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.

  • 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 Overflow
Top answer
1 of 9
38

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.

  • 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.

2 of 9
17

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.

🌐
Prometheus
discuss.prometheus.io › promql
Get label's value as query value - PromQL - Prometheus Monitoring System
November 21, 2022 - Hello, I’m looking for a way to get a label’s value as query result rather than just a 1 or a 0 I’ve been knocking my head all around the web for hours but I’ve yet to find a definitive working answer. I’ve found the t…
Discussions

Use Label Value as Returned Value
Prometheus metric values are only numbers. What you're asking for isn't possible. It's also not really necessary, as tools like Grafana can display string label values. For example, see this blog post . More on reddit.com
🌐 r/PrometheusMonitoring
6
0
June 20, 2024
Extract labels values from prometheus metrics
Hi guys, I’ve already spent a lot of time , but still have no solution. Our Prometheus instance stores some interesting metrics, where the relevant information saved as labels and not as metric value: cadvisor_version_info{beta_kubernetes_io_arch="amd64",beta_kubernetes_io_os="linux",doc... More on community.grafana.com
🌐 community.grafana.com
13
2
July 31, 2017
grafana - Prometheus: how to get label_value() in query - Stack Overflow
So I have 2 metrics, I need to get label values from first metric and then query over 2nd metric, where {param="label_values_from_1st_metric"}. For ex: More on stackoverflow.com
🌐 stackoverflow.com
grafana - How do I extract a value from a set of labels in prometheus? - Stack Overflow
I'm trying to create a grafana variable from a prometheus data source. I'll keep this short and to the point: I have a set of values in the form: kube_namespace_labels{container="kube-state-me... More on stackoverflow.com
🌐 stackoverflow.com
🌐
OneUptime
oneuptime.com › home › blog › how to write prometheus queries that return label values
How to Write Prometheus Queries That Return Label Values
December 17, 2025 - In current Grafana versions, use the Prometheus variable query type "Label values" for new dashboard variables, and use label_values() only when working with classic queries. # Get all values for a label across all metrics label_values(label_name) ...
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › oK_bx8rHmZs
hi how do i get all labels list in prometheus?
Bit old, but I did find a way to do it. http://promethesusserver:port/api/v1/label/__name__/values will return all Labels that are shown in the Graph listing. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original ...
🌐
Grafana
grafana.com › blog › how-to-extract-label-values-from-prometheus-metrics-in-grafana
How to extract label values from Prometheus metrics in Grafana | Grafana Labs
February 24, 2023 - Next, in the upper right corner of the screenshot above, where you see Time series, we want to choose instead the Table visualization. This is important, because most Prometheus label information won’t be numbers that you can graph; they’ll be categorical variables or pieces of text best put into a table. This gets us raw data, but it makes for an ugly table, as you can see below.
🌐
SigNoz
signoz.io › guides › how to write prometheus queries to return label values
How to Write Prometheus Queries to Return Label Values | SigNoz
July 25, 2024 - Labels in Prometheus are crucial for organizing and querying metrics. They provide additional context to the data, allowing for fine-grained filtering and aggregation. For example, a metric http_requests_total might have labels like method, status, and endpoint. Querying label values is important for several reasons:
🌐
Reddit
reddit.com › r/prometheusmonitoring › use label value as returned value
r/PrometheusMonitoring on Reddit: Use Label Value as Returned Value
June 20, 2024 -

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..."} 1

In 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.

🌐
GitHub
github.com › prometheus › prometheus › discussions › 10620
Query function to get value of a label · prometheus/prometheus · Discussion #10620
Proposal Query function to get value of a label. This would be convenient to have alert thresholds stored in labels. What would lead to simplified alert rules. Example: Metrics: metric1{label1="foo...
Author: prometheus
Find elsewhere
🌐
Promlabs
promlabs.com › blog › 2020 › 12 › 17 › promql-queries-for-exploring-your-metrics
PromLabs | Blog - PromQL Queries for Exploring Your Metrics
December 17, 2020 - Note: In this latter case, you may again use the label values API endpoint (but this time for the mode label) instead of a PromQL query. As a Prometheus server administrator, the total number of time series that a server needs to keep track of is one of the main memory and scaling bottlenecks to watch out for. To get ...
🌐
Better Stack
betterstack.com › community › questions › how-do-i-write-prometheus-query-that-returns-value-of-label
How Do I Write a Prometheus Query That Returns the Value of a Label? | Better Stack Community
August 5, 2025 - If you want to return all the unique values of a specific label (e.g., method) from the http_requests_total metric, you can use the label_values function in conjunction with the Prometheus UI or Grafana.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › cBwjaNXZKUg
How can i get the label values in prometheus
A label is exactly was its name implies. It's a string. You can parse them with regex, manipulate them in simple ways, etc, but not "calculate" against them. Certainly you can (and should) order or filter by them though, but the value of the metric itself is what you should generally be after.
🌐
Nobl9
docs.nobl9.com › prometheus api for slo time series › slo time series › get label values
Get label values | Nobl9 Documentation
Returns a list of label values for a specific label name. Can be filtered by series matchers. ... Bad request — invalid or unparseable parameters (for example, a malformed PromQL expression or timestamp), or a query that exceeds the query limits (too many series, time range too long, or too ...
🌐
Grafana
community.grafana.com › prometheus
Extract labels values from prometheus metrics - Prometheus - Grafana Labs Community Forums
July 31, 2017 - Hi guys, I’ve already spent a lot of time , but still have no solution. Our Prometheus instance stores some interesting metrics, where the relevant information saved as labels and not as metric value: cadvisor_version_info{beta_kubernetes_io_arch="amd64",beta_kubernetes_io_os="linux",doc...
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
http_requests_total{environment=~"staging|testing|development",method!="GET"} Label matchers that match empty label values also select all time series that do not have the specific label set at all.
Top answer
1 of 3
6

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.

2 of 3
3

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:

  1. 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"}

  2. 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.

🌐
client_python
prometheus.github.io › client_python › instrumenting › labels
Labels | client_python
April 9, 2026 - It is recommended to initialize the label values by calling the .labels() method alone: from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) c.labels('get', '/') c.labels('post', '/submit') Remove a specific labelset from the metric.
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-metrics-labels-time-series
Prometheus Cheat Sheet - Basics (Metrics, Labels, Time Series, Scraping)
Side note 2: Values are always floating-point numbers; timestamps are integers storing the number of milliseconds since the Unix epoch. Every such time series is stored separately on the Prometheus node in the form of an append-only file. Since a series is defined by the label value(s), one ...