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
Query
Description
up
Returns 1 for each active target and 0 for each inactive target.
scrape_duration_seconds
Returns the duration of the last scrape for each target.
scrape_samples_post_metric_relabeling
Returns the number of samples after metric relabeling for each target.
http_requests_total
Returns the total number of HTTP requests.
Filtering
Query
Description
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
Query
Description
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
Query
Description
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
Query
Description
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
Query
Description
ALERT alert_name IF expr FOR duration
Defines an alert that triggers when the expression is true for the specified duration.