My answer tries to elaborate on Carl's answer. I assume that the GUI layout may have changed a little since 2016, so it took me while to find the "name" option.
Assuming you have a metric as follows:
# HELP db2_prometheus_adapter_info Information on the state of the DB2-Prometheus-Adapter
# TYPE db2_prometheus_adapter_info gauge
db2_prometheus_adapter_info{app_state="UP"} 1.0
and you would like to show the value of the label app_state.
Follow these steps:
- Create a "SingleStat" visualization.
- Go to the "Queries" tab:
- Enter the name (here
db2_prometheus_adapter_info) of the metric. - Enter the label name as the legend using the
{{[LABEL]}}notation (here{{app_state}}). - Activate the "instant" option.
- Enter the name (here

- Go to the "Visualization" tab:
- Choose the value "Name" under "Value - Stat".

Note on the "Instant" setting: This setting switches from a range query to a simplified query only returning the most recent value of the metric (also see What does the "instant" checkbox in Grafana graphs based on prometheus do?). If not activated, the panel will show an error as soon as there is more than one distinct value for the label in the history of the metric. For a "normal" metric you would remedy this by choosing "current" in the "Value - Stat" option. But doing so here prevents your label value to be shown.
Answer from Marcus Rickert on Stack OverflowMy answer tries to elaborate on Carl's answer. I assume that the GUI layout may have changed a little since 2016, so it took me while to find the "name" option.
Assuming you have a metric as follows:
# HELP db2_prometheus_adapter_info Information on the state of the DB2-Prometheus-Adapter
# TYPE db2_prometheus_adapter_info gauge
db2_prometheus_adapter_info{app_state="UP"} 1.0
and you would like to show the value of the label app_state.
Follow these steps:
- Create a "SingleStat" visualization.
- Go to the "Queries" tab:
- Enter the name (here
db2_prometheus_adapter_info) of the metric. - Enter the label name as the legend using the
{{[LABEL]}}notation (here{{app_state}}). - Activate the "instant" option.
- Enter the name (here

- Go to the "Visualization" tab:
- Choose the value "Name" under "Value - Stat".

Note on the "Instant" setting: This setting switches from a range query to a simplified query only returning the most recent value of the metric (also see What does the "instant" checkbox in Grafana graphs based on prometheus do?). If not activated, the panel will show an error as soon as there is more than one distinct value for the label in the history of the metric. For a "normal" metric you would remedy this by choosing "current" in the "Value - Stat" option. But doing so here prevents your label value to be shown.
We recently added support for displaying the series name as a value in the single stat panel (https://github.com/grafana/grafana/issues/4740). So you have to run our nightly build until we release version 4.0.
Just make sure the query returns one series and you can use the "name" value in the dropdown under Options -> big value. Then you can format the string using the legend formatter. Ex {{job}} would return "node" as a series name.
I hope this answers your question.
Use Label Value as Returned Value
Extract labels values from prometheus metrics
grafana - Prometheus: how to get label_value() in query - Stack Overflow
grafana - How do I extract a value from a set of labels in prometheus? - Stack Overflow
Hi, I've been searching online to try and resolve my problem but I can't seem to find a solution that works.
I am trying to get our printers status using SNMP but when looking at the returned values in the exporter its putting the value I need as a label ("Sleeping..." is what I'm trying to get).
prtConsoleDisplayBufferText{hrDeviceIndex="1", prtConsoleDisplayBufferIndex="1", prtConsoleDisplayBufferText="Sleeping..."} 1In the above example I want to have prtConsoleDisplayBufferText returned instead of just the value 1
Can anyone point me in the right direction? I feel like I've been going around in circles for the last few hours.
You can try in the following way:
metric_2 * on(instance) group_left(host) metric_1{instance="abc"}
on(instance) => this is how to JOIN on label instance.
group_left(host) metric_1{instance="abc"} => means, keep the label host from metric_1 in the result.
Okay, finally, I've got it. So As Pulak Kanti suggested, I used group_left. However it returned error: many-to-many mathcing is not allowed. So what I've done:
Labels between metric_1 and metric_2 do not match, however it is pretty simple to fix it, we need to add label_replace() func
label_replace(metric_2,"host","$1","domain", "(.+)"). This expression adds to metric_2 label host with values copied from label domain. From our point of view we've just renamed label domain to label host. And this is great news, because now metric_1 and metric_2 have one common label - host. So the query from this step would look something like this:label_replace(metric_2,"host","$1","domain", "(.+)") + on (host) group_left(domain) metric_1{instance="abc"}Now our query at least doesn't retrun any error, however, it returns unexpected result-this is because it multiplies values from metric_2 with values from metric_1. Because we need only values from metric_2, we can just null metric_1, so it ends up being:
label_replace(metric_2,"host","$1","domain", "(.+)") + on (host) group_left(domain) 0*metric_1{instance="abc"}
I do understand that this query isn't effective, however it worked for me. I would be very grateful if someone would help and make this query more efficient.
BTW: here it is not important what is inside group_left() brackets, because it influences only what label we displays, for me it is not important, so
label_replace(metric_2,"host","$1","domain", "(.+)") + on (host) group_left() 0*metric_1{instance="abc"} also works.
While PromQL doesn't provide functionality for returning all the available label names, Prometheus querying API provides such functionality via /api/v1/labels handler.
This handler supports optional start and end query args, which may be used for limiting time range for the returned label names. It also supports match[] query args, which may be used for additional filtering on time series. For example, request to /api/v1/labels?match[]=foo{bar="baz"} would return only label names for time series matching foo{bar="baz"} time series selector. See these docs for more details.
@valyala's answer is helpful for label/metric names. But if you want to get all the values of a label, you can call /api/v1/label/{YOUR_LABEL_NAME}/values. See the docs. For example:
$ curl http://localhost:9090/api/v1/label/instance/values
{
"status" : "success",
"data" : [
"node1",
"node2",
"node3",
]
}