How to build graphs of aggregate data for Prometheus

Hi Team,

I am using Telegraf + Prometheus + Grafana to build Nginx log’s graphs on Grafana. I am using below prometheus recording rule with default time to pull the data ( not sure what is the default time, I guess 15 sec).

bitnami@XYZ@ more rules.yml

  • name: nodejs
    • record: node_api:request_time:avg_
      expr: avg by (host, request) (nginx_access_log_request_time{request =~ “/api.*”})
    • record: node_api:api_wise:count_
      expr: count by (host, request) (nginx_access_log_response{request =~ “/api.*”})
    • record: node_api:response:count_
      expr: count_values(“response”, nginx_access_log_response) by (host)

15 seconds interval is getting reflected by using metrics-name " node_api:response:count_"

Then I want to see the graphs based on 5m, 15m , 30m aggregation.

I have tried all options in grafna templale of Promql query, however not able to achieve it. Could you please help here?

Hi, I was able to solve this via below query.


I have another issue where I need combination of two queries for API-wise-count. I want to do sum API-wise-count by time and for all the hosts.

I see for all the host, I can get graph like below.
sum(node_api:api_wise:count_) by (request)

and for time, I can get like below.

However, how to combine both these queries?
Can someone help me please?

Br, Nitin