Table-like visualization with label values as row values and column names
Asked Answered
P

2

3

I have some metrics from a Prometheus data-source like this (the real data contains many more label combinations):

status{pod = "A", platform = "X",} 1
status{pod = "C", platform = "X",} 3
status{pod = "A", platform = "Y",} 5
status{pod = "A", platform = "P",} 8
status{pod = "C", platform = "Y",} 7
status{pod = "B", platform = "Y",} 4
status{pod = "B", platform = "P",} 1

For which I need to display the info with a Grafana visualization like this:

X Y P
A 1 5 8
C 3 7
B 4 1

The labels pod and platform cannot be hard-coded into the visualization configuration but it needs to be taken from the values from the metrics.

So basically, I need to:

  • take the pod label values as row values for the first column,
  • take the platform label values as the column names for the next columns and,
  • take the metric values as the intersection between pod and platform as depicted above.

I tried using the Table Panel using the Labels to fields transformation but couldn’t get it working.

So, how could I achieve the described scenario? I’m open to any suggestion that could give me a similar result.

I’d be really thankful for any insights you could provide me with.

Posted originally on Grafana Community. Posted here to reach wider audience

Pelkey answered 2/2, 2021 at 13:5 Comment(0)
P
2

I just had to select the Time Series format on the Grafana query editor and then the Value field name drop-down is properly populated in the Transform tab.

Now I’m able to choose pod for that drop-down and the platform values are rendered as column names as expected with their respective values for each pod.

Pelkey answered 2/2, 2021 at 15:45 Comment(0)
C
0

After parsing your labels, you will notice a labels column on the default table. These can be extracted as JSON to be displayed as new columns on the table.

To accomplish this:

  1. In the Query tab, parse your labels (i.e. with a parser such as Logfmt). You will notice a Labels column on the default table.
  2. In the Transform data tab, add a Extract fields transform.
    • Set Source to labels.
    • Set Format to JSON.
    • To hide the default columns while still showing the Time columns, tick Replace all fields and Keep time.

Capital answered 10/4, 2024 at 11:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.