Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculating average using a Histogram metric

I am generating a Histogram using a prometheus client. The metric name is retrieve_stripe_subscription_latency_ms. Since Histogram generates additional metrics with suffixes _sum and _count, can I calculate the average using the below query in Grafana?

sum(retrieve_stripe_subscription_latency_ms_sum)/sum(retrieve_stripe_subscription_latency_ms_count)

like image 322
Arjun Avatar asked Jul 22 '26 02:07

Arjun


1 Answers

I think official Prometheus documentation address this. Having your metric name:

To calculate the average [...put here a metric meaning...] during the last 5 minutes from a histogram or summary called retrieve_stripe_subscription_latency_ms, use the following expression:

rate(retrieve_stripe_subscription_latency_ms_sum[5m])
/
rate(retrieve_stripe_subscription_latency_ms_count[5m])
like image 151
Kuchara Avatar answered Jul 24 '26 14:07

Kuchara



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!