Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display all metrics that don't have a specific label

Tags:

prometheus

I want to select all metrics that don't have label "container". Is there any possibility to do that with prometheus query?

like image 952
cristi Avatar asked Jul 11 '18 20:07

cristi


People also ask

How do you add labels to the metric system?

If you want to add a label unconditionally to every metric returned from a specific scrape job, then just add the label in the service discovery (e.g. "file_sd_configs" or "static_configs"). Different labels can be applied for different groups of targets, e.g.

How do I use wildcards in PromQL?

PromQL does not support the * wildcard that Lucene queries use. Instead, use "~" before the value you want to search, and ". +" at the end of it.

What is PromQL?

PromQL, short for Prometheus Querying Language, is the main way to query metrics within Prometheus. You can display an expression's return either as a graph or export it using the HTTP API. PromQL uses three data types: scalars, range vectors, and instant vectors. It also uses strings, but only as literals.

What is up metric in Prometheus?

up{job="<job-name>", instance="<instance-id>"} : 1 if the instance is healthy, i.e. reachable, or 0 if the scrape failed. i.e. it is a per scraper / exporter metric which means whether the exporter was available / reachable or not.


2 Answers

Try this:

{__name__=~".+",container=""}

There needs to be at least one non-empty matcher (hence the + in the __name__ regular expression, * wouldn't cut it). And the way you query for a missing label is by checking for equality with the empty string.

like image 60
Alin Sînpălean Avatar answered Sep 21 '22 09:09

Alin Sînpălean


In recent versions of Prometheus it's enought to query for something like this:

node_load1{not_existent_label=""}
like image 20
Konstantin Avatar answered Sep 23 '22 09:09

Konstantin