RITESH DUBEY
RITESH DUBEY

Reputation: 75

Is there a way in promql to get all the available label names using thanos api?

I have a promql which is giving me the metric result as a whole from the server, but I am interested in filtering and getting results of a specific value, but I am not sure what can be the label name for that value, if I can see all the available names I will be able to at least hit it using trial and error, but without the label names, I am not able to do anything.

Upvotes: 6

Views: 14502

Answers (3)

zer0e
zer0e

Reputation: 11

/api/v1/labels is fine for Prometheus users, but there are some inconsistent behaviors with Thanos, so just be careful when using this API

Upvotes: 1

valyala
valyala

Reputation: 17830

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.

Upvotes: 13

Neema Mashayekhi
Neema Mashayekhi

Reputation: 930

@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",
   ]
}

Upvotes: 1

Related Questions