Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add label field support for sub-queries #43

Closed
skyairmj opened this issue Apr 12, 2018 · 2 comments
Closed

Add label field support for sub-queries #43

skyairmj opened this issue Apr 12, 2018 · 2 comments

Comments

@skyairmj
Copy link

Hi,

Prometheus-Sql is very helpful, especially the sub-metrics approach. However, sub-metrics doesn't support label fields yet. It makes prometheus-sql not be able to handle multi-row multi-metric scenarios.

Giving a query string as:

select group, subgroup, count, avg from test_table

and the result set as bellow:

group subgroup count avg
a a1 10 5
b b1 7 6

We'd like to register metrics as bellow:

metric value
xxx_count(group = 'a', subgroup='a1') 10
xxx_avg(group = 'a', subgroup='a1') 5
xxx_count(group = 'b', subgroup='b1') 7
xxx_avg(group = 'b', subgroup='b1') 6

To achieve this, shall we treat all fields not specified under sub-metrics as label fields for all sub metrics? e.g.

- xxx:
    sql: >
        select group, subgroup, count, avg from test_table
    sub-metrics: # group, subgroup become label fields for both xxx_count and xxx_avg metrics as above
      count: count
      avg: avg
    interval: 30s

What's your opinion?

@Teriand
Copy link

Teriand commented Dec 12, 2018

But this work fine now.
ex.

- pg_statio_user_tables:
    data-source: pgmain
    sql: >
            SELECT 'MSK-MAIN' as stand, 'pgmain' as pg_instance, schemaname, relname,
            heap_blks_read, heap_blks_hit,coalesce(idx_blks_read,-1) as idx_blks_read, coalesce(idx_blks_hit,-1) as idx_blks_hit,
            coalesce(toast_blks_read,-1) as toast_blks_read, coalesce(toast_blks_hit,-1) as toast_blks_hit, coalesce(tidx_blks_read,-1) as tidx_blks_read, coalesce(tidx_blks_hit,-1) as tidx_blks_hit
            FROM pg_statio_user_tables
    interval: 5m
    sub-metrics:
      heap_blks_read: heap_blks_read
      heap_blks_hit: heap_blks_hit 
      idx_blks_read: idx_blks_read
      idx_blks_hit: idx_blks_hit
      toast_blks_read: toast_blks_read
      toast_blks_hit: toast_blks_hit
      tidx_blks_read: tidx_blks_read
      tidx_blks_hit: tidx_blks_hit

in metrics:

# HELP query_result_pg_statio_user_tables_heap_blks_hit Result of an SQL query
# TYPE query_result_pg_statio_user_tables_heap_blks_hit gauge
query_result_pg_statio_user_tables_heap_blks_hit{pg_instance="pgmain",relname="activator_message",schemaname="queue",stand="msk-main"} 4.0721516415e+10
query_result_pg_statio_user_tables_heap_blks_hit{pg_instance="pgmain",relname="alarms",schemaname="state",stand="msk-main"} 198160
query_result_pg_statio_user_tables_heap_blks_hit{pg_instance="pgmain",relname="alarms_sources",schemaname="state",stand="msk-main"} 203279

Only 1 features need prom-sql its custom HELP for replace "Result of an SQL query"

@haxorof
Copy link
Contributor

haxorof commented Dec 26, 2021

Regarding help text, it is handled in #48

@haxorof haxorof closed this as completed Dec 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants