Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prometheus query for table in grafana

When i make a table panel and go to "Options" tab, columns parameter set to Auto: Columns and their order are determined by the data query.

Is there a doc on how write prometheus queries for grafana tables?

My prometheus data is a metric with 2 labels my_col and my_row:

my_metric{instance="lh",job="job",my_col="1",my_row="A"} 6
my_metric{instance="lh",job="job",my_col="2",my_row="A"} 8
my_metric{instance="lh",job="job",my_col="1",my_row="B"} 10
my_metric{instance="lh",job="job",my_col="2",my_row="B"} 17

I want to make a table that looks like:

|   | 1 | 2 |
| A | 6 | 8 |
| B | 10| 17|
like image 564
lacerated Avatar asked Sep 04 '18 10:09

lacerated


1 Answers

It is possible with Grafana 7.0.3. I think it was possible with earlier versions as well, but the approach has changed since 7.0.0 with the introduction of transformations.

Add two queries:

my_metric{instance="lh",job="job",my_col="1"}
my_metric{instance="lh",job="job",my_col="2"}

Make them instant queries and format them as tables. Create the transformation Outer join and join by my_col. You should get the two values as Value #A and Value #B. You can use the transformation Organize fields to rename them and drop all the other fields.

like image 135
fischerman Avatar answered Oct 03 '22 23:10

fischerman