Prometheus Aggregation Operators

Prometheus provides several aggregation operators that allow you to perform calculations and aggregations on the collected metrics. Here are some commonly used aggregation operators in Prometheus:

1. sum: Calculates the sum of the selected metric over a given time range.

2. avg: Computes the average value of the selected metric over a specified time period.

3. min: Returns the minimum value of the selected metric within a given time range.

4. max: Returns the maximum value of the selected metric within a given time range.

5. count: Counts the number of times the selected metric has been recorded within a given time frame.

6. quantile: Computes the quantile value of the selected metric over a specified time period. For example, "quantile(0.95)"" will give you the 95th percentile value.

7. rate: Calculates the per-second average rate of increase of the selected metric over a given time window.

8. irate: Similar to "rate", but provides an instant rate of increase at each point in time.

9. delta: Computes the difference between the first and last value of the selected metric within a given time range.

10. stddev: Calculates the standard deviation of the selected metric over a specified time period.

These operators can be used in Prometheus's query language, PromQL, to perform aggregations and calculations on your metrics data. By combining these operators with various functions and modifiers, you can derive meaningful insights and create custom monitoring and alerting rules based on your specific requirements.

Examples

Here are examples of each aggregation operator using PromQL syntax:

1. sum:

sum(metric_name)

2. avg:

avg(metric_name)

3. min:

min(metric_name)

4. max:

max(metric_name)

5. count:

count(metric_name)

6. quantile:

quantile(0.95, metric_name)

7. rate:

rate(metric_name[5m])

8. irate:

irate(metric_name[1m])

9. delta:

delta(metric_name[1h])

10. stddev:

stddev(metric_name)

Note that in these examples, "metric_name" should be replaced with the actual name of the metric you want to aggregate. The time ranges within square brackets [ ] specify the duration over which the aggregation is performed (e.g., 5m for 5 minutes, 1h for 1 hour).

Keep in mind that PromQL is a flexible query language, and you can combine these aggregation operators with other PromQL functions and modifiers to create more complex queries and calculations based on your specific needs.