## Common Query Patterns in PromQL

For day to day use, there’s only a handful of PromQL patterns you need to know for aggregation.

For gauges you'll usually `sum()`

, `avg()`

, `min()`

or `max()`

them:

sum without (instance)(my_gauge)

For counters, you'll take a `rate()`

and then `sum()`

:

sum without (instance)(rate(my_counter_total[5m]))

A summary contains `_sum`

and `_count`

counters, from which we can calculate the average event size. This is often the average latency:

sum without (instance)(rate(my_summary_latency_seconds_sum[5m])) / sum without (instance)(rate(my_summary_latency_seconds_count[5m]))

This query pattern works in other situations too, such as a failure ratio:

sum without (instance)(rate(my_events_failed_total[5m])) / sum without (instance)(rate(my_events_total[5m]))

A histogram contains buckets, from which we can calculate say the 90th percentile latency:

histogram_quantile(

0.9,

sum without (instance)(rate(my_histogram_latency_seconds_bucket[5m])))

We take the rate of the bucket counters, aggregate up and then calculate the quantile.

A histogram also contains a `_sum`

and `_count`

, so the summary query from above will work here too.