Bi dimensional matrix table display from Prometheus query

  • What Grafana version and what operating system are you using?

Grafana 8.3.6 on Linux

  • What are you trying to achieve?

I have ICMP latency numbers in Prometheus, with site label being the source of ping and target_site being the destination, for example:

query: max by (site, target_site) (probe_duration_seconds{job="smoke/icmp"})

results:
{site="drmrs", target_site="drmrs"} 0.002829992
{site="drmrs", target_site="codfw"} 0.13355915
{site="codfw", target_site="knams"} 0.116177193
{site="drmrs", target_site="eqdfw"} 0.115776562
{site="eqsin", target_site="eqiad"} 0.240002609
{site="codfw", target_site="esams"} 0.118240049
{site="ulsfo", target_site="eqiad"} 0.071118352
{site="eqiad", target_site="eqiad"} 0.002334645
{site="eqsin", target_site="eqord"} 0.249370348
{site="eqiad", target_site="esams"} 0.082603106
{site="codfw", target_site="eqsin"} 0.212831425
{site="eqsin", target_site="ulsfo"} 0.19079361
{site="ulsfo", target_site="ulsfo"} 0.00213096
{site="eqsin", target_site="esams"} 0.339148254
{site="eqiad", target_site="eqsin"} 0.240296569
{site="esams", target_site="eqsin"} 0.32271197
...

The cardinality of site is smaller (~5) than target_site (~8). I would like to have a table display in Grafana with site as rows and target_site as columns, and values in cells.

       | eqiad | esams | knams | eqsin 
---
drmrs  | x     | x     | x     | x
eqiad  | x     | x     | x     | x
codfw  | x     | x     | x     | x
ulsfo  | x     | x     | x     | x
eqsin  | x     | x     | x     | x
  • How are you trying to achieve it?

So far I have:

A table panel with “time series” mode and “instant” results.
A label-to-fields transformation with columns and “value field name” of target_site
An outer join on “site”
An “organize fields” to hide Time

  • What happened?

The result sort-of works but there are more columns than I expected, i.e. one per different target_site combination and the resulting matrix/table is sparse (an example below, not based on the sample data above)

       | eqiad 1 | eqiad 2 | esams 1 | knams 1 | eqsin 1 ...
---
drmrs  |         | x       |         | x       | x
eqiad  | x       |         |         |  
codfw  | x       |         | x       | x
ulsfo  |         | x       |         |  
eqsin  | x       | x       | x       | x
  • What did you expect to happen?

I can collapse/join the columns too to obtain a fully populated matrix as opposed to a sparse one

Happy to provide more information, thanks!

Sounds like the transformations have already carried you quite far.

I would inspect your panel data and data frame structure to polish this:

Thank you @mattabrams ! I will be playing a little more with transformations and report back