Creating a key/value table from multiple queries

On Grafana 13.0.2, I have two queries that are returning:

unitModelName{model_name=“A Big Server”} = 1

unitFirmware{firmware_version=“1.2.3.4”} = 1

I’d like to render this into a table:

| Key        | Value        |
| Model Name | A Big Server |
| Firmware   | 1.2.3.4      |

I’ve seen a few iterations of this, but it’s always capturing the value of a particular metric. I’ve tried various combinations of Label to Field + Merge Series, but can’t bend Grafana to my will.

Any suggestions?

Can you please the result of the queries, what do those look like

Query & result for the model name:

label_replace(entPhysicalDescr{instance="$switch"}, "key", "Hardware platform", "", "")

entPhysicalDescr{cluster="is-servers",device_model="EX-4100-48MP",device_type="juniper_switch",entPhysicalDescr="Juniper EX4100-48MP Switch",entPhysicalIndex="1",instance="10.4.136.105",job="juniper_ex_snmp",key="Hardware platform"} = 1

And for the firmware version:

label_replace(entPhysicalSoftwareRev{instance="$switch"}, "key", "Software version", "", "")

entPhysicalSoftwareRev{cluster="is-servers",device_model="EX-4100-48MP",device_type="juniper_switch",entPhysicalIndex="1",entPhysicalSoftwareRev="23.4R2-S7.7",instance="10.4.136.105",job="juniper_ex_snmp",key="Software version"} = 1

Are you open to using Grafana Text plugin?

You could leverage javascript. Another way would have been to use SQL Expression but for now it is limited with the functions you can use such as parsing strings and extracting key value pairs

Mmm, trying that now. That might be a much cleaner solution.

you will have to play with the array coming from your 2 datasources or combine them into one using sql union select metric from a union select metric from b

Since both have shared data points and will be two distinct rows, in your js you will have to dedup somehow.

look for registerHelper in this forum. others have successfully bent this to their will :wink:

context.handlebars.registerHelper(“unique”, (context, key) => {
return […new Set(context.map((item) => item[key]))];
});