Search code examples
devopsprometheuspromql

Multiple labels in Prometheus query


I am trying to get an array of label and values inside one JSON from Prometheus.

I have a metric

http_server_requests_seconds_count{method="POST", service="application", status="200", uri="/v1/rest/clients/ids"}

Using query:

count(sum(rate(http_server_requests_seconds_count[5m])) by (method,uri)) by (uri)

I get:

"result" : [
         {
            "metric" : {
               "uri" : "/v1/rest/clients/ids"
            },
            "value" : [
               1.662458065998E9,
               "1"
            ]
         },

However, I would like to get more labels in the metric field, such as service, status, uri. For example:

"metric" : {
   "uri" : "/v1/rest/clients/ids",
   "service" : "application",
   "status" : "200",
},

Either value aggregation over each unique label


Solution

  • I have adjusted my query as follows

    round(sum(delta(http_server_requests_seconds_count[5m])) by (service, status, uri) >0 )