Hello, community!
I am building a dashboard in Grafana to monitor the latency and the number of requests made to a specific API. The metrics are being collected via Google Cloud Managed Service for Prometheus and accessed in Grafana using Google Cloud Monitoring as the data source.
However, I am facing an issue with how the data is being displayed. The metric I am using to calculate the total number of requests is returning the cumulative number of requests since the start of data collection, regardless of the time period selected in the dashboard.
For example, when I apply a filter to display data from the last 5 minutes, the panel still shows the total number of requests accumulated from the start of data collection, instead of displaying only the total for the selected 5-minute interval.
Below is an illustrative image:
What I need is to calculate the number of requests only within the selected time period in Grafana. Is there a way to adjust the PromQL query so it returns the correct data based on the selected time range? I’ve tried several approaches, but the query always returns the cumulative value of all requests.
Currently, I am using the following PromQL query to calculate the metric total. Does anyone know how I can modify it to return only the requests from the selected time range?
sum(coleta_online_request_count{product_id=~'$product_id', external_bases_name=~'$base_name'})
Here is the configuration for exporting my metrics. Every time a request comes in, I add the value 1
to the metric using the incBy
function:
# HELP coleta_online_request_count gauge coleta online request
# TYPE coleta_online_request_count gauge
coleta_online_request_count{product_id="509",base_name="Mock 1",request_status="success"} 1
coleta_online_request_count{product_id="510",base_name="Mock 2",request_status="success"} 1
coleta_online_request_count{product_id="521",base_name="Mock 1",request_status="error"} 1
coleta_online_request_count{product_id="521",base_name="Mock 1",request_status="success"} 1
Any suggestions or ideas would be greatly appreciated. I have been trying for hours without finding a satisfactory result.
Thank you in advance for your help and support!
Best regards,
Reinan