Related to prometheus query

148 views
Skip to first unread message

dikshant rai

unread,
Mar 20, 2023, 10:07:53 AM3/20/23
to Prometheus Users
Hi,
I am trying to create custom dashboard from prometheus logs but not getting as expected I am trying to count them. below is the script I am using but I am getting zero.

count(http_server_requests_seconds_count{application="marketplace-service", uri="/marketplace/live/bid/{auctionId}"})

Below is the 1 line log and I wanted to achieve that if uri, method and application matches, it should count as 1.

"http_server_requests_seconds_count{application="marketplace-service",exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} ""

Brian Candler

unread,
Mar 20, 2023, 10:35:17 AM3/20/23
to Prometheus Users
Firstly, I suggest you use the PromQL query browser within the Prometheus web interface to test your expressions.

Secondly, I suggest you build them up in stages.  Try the inner query first; when that's working as you expect then add to the query.

Therefore, I suggest you try this query first:

    http_server_requests_seconds_count{application="marketplace-service", uri="/marketplace/live/bid/{auctionId}"}

I expect it will return zero results unless the query uri is literally the string "/marketplace/live/bid/{auctionId}" - because that's what you asked to match.  If so, that's why the count of timeseries is zero.

What I *guess* you probably want is a query like this:

    http_server_requests_seconds_count{application="marketplace-service", uri=~"/marketplace/live/bid/.+"}

That's a regular expression pattern match, where . means "any character" and + means "1 or more times".  That should return one or more results (as long as there are some with uri that match).  OK so far?

Then, I wonder what you mean by a "count".  If you put count(...) around this expression, then it will work, but you will get a single value which is the *number of timeseries*, ignoring their values.  That is, the number of distinct uri's that are seen.

But each of these timeseries is itself a counter.  So maybe what you want is to put sum(...) around this expression, to get the total of the counts?

    sum(http_server_requests_seconds_count{application="marketplace-service", uri="/marketplace/live/bid/.+"})

Only you can decide if that's what you want, because only you know what you're trying to show from these metrics.

I hope that helps - good luck!

dikshant rai

unread,
Mar 20, 2023, 12:56:46 PM3/20/23
to Prometheus Users
Hi Brian,
Thanks for such clarification. This is a sample one. We want to monitor much time http_server_requests_seconds_count is being hit with keeping application="marketplace-service", uri="/marketplace/live/bid/{auctionId} as filter and every time a post request is being made it can be count as 1,2,3 and so on. We will only change the uri in filter rest things are same.

Reply all
Reply to author
Forward
0 new messages