PromQL Cheat Sheet

In PromQL

PromQL is a powerful query language used in Prometheus, an open-source monitoring system. It is designed to help users retrieve and analyze time-series data collected by Prometheus. PromQL is a flexible and expressive language that allows users to perform complex queries on their data, making it easier to identify and troubleshoot issues in their systems.

PromQL is based on a functional programming model, which means that it uses functions to manipulate data. These functions can be combined to create more complex queries, allowing users to filter, aggregate, and transform their data in a variety of ways. PromQL also supports regular expressions, which makes it easy to search for specific patterns in your data.

This cheat sheet provides a quick reference for PromQL queries.

Basics

QueryDescription
upReturns 1 for each active target and 0 for each inactive target.
scrape_duration_secondsReturns the duration of the last scrape for each target.
scrape_samples_post_metric_relabelingReturns the number of samples after metric relabeling for each target.
http_requests_totalReturns the total number of HTTP requests.

Filtering

QueryDescription
metric_name{label=value}Filters by label value.
metric_name != ""value""Filters by label value not equal to “”value””.
metric_name{label=~""regex""}Filters by label value matching a regular expression.
metric_name{label!~""regex""}Filters by label value not matching a regular expression.

Aggregation

QueryDescription
sum(metric_name)Returns the sum of all values for the metric.
avg(metric_name)Returns the average of all values for the metric.
min(metric_name)Returns the minimum value for the metric.
max(metric_name)Returns the maximum value for the metric.
count(metric_name)Returns the number of samples for the metric.

Time Ranges

QueryDescription
metric_name[5m]Returns the last 5 minutes of data for the metric.
metric_name[1h:]Returns all data for the metric from the last hour.
metric_name[1d-]Returns all data for the metric up to one day ago.

Functions

QueryDescription
rate(metric_name[5m])Returns the per-second rate of change for the metric over the last 5 minutes.
irate(metric_name[5m])Returns the per-second rate of change for the metric over the last 5 minutes, ignoring gaps in the data.
delta(metric_name[5m])Returns the difference between the first and last value for the metric over the last 5 minutes.
increase(metric_name[5m])Returns the total increase in the metric over the last 5 minutes.

Alerting

QueryDescription
ALERT alert_name IF expr FOR durationDefines an alert that triggers when the expression is true for the specified duration.
ALERTSReturns a list of all defined alerts.
ALERTS{alertstate=""firing""}Returns a list of all currently firing alerts.

References

PromQL Documentation