Introduction #
An overview of PromQL and why it matters in Prometheus.
What is PromQL? #
Available in: ✓ OSS ✓ Enterprise ✓ Cloud
PromQL (Prometheus Query Language) is the query language used in Prometheus to query metric data. It lets you extract information, create alerts and visualize graphs in tools such as Grafana.
Why use PromQL? #
PromQL is essential to analyze the metrics collected by Prometheus. With its powerful, flexible syntax, you can:
- Monitor the performance of your systems.
- Configure alerts based on specific thresholds.
- Create detailed visualizations for dashboards.
PromQL basics #
Understanding the fundamental concepts of PromQL.
Data types #
A PromQL expression always evaluates to one of the following four types:
- Instant vector: a set of time series containing a single value (sample) for each of them at a given time.
- Range vector: a set of time series containing a range of values over a given period (e.g.
[5m]). - Scalar: a simple numeric value.
- String: a simple text value.
Metric types #
PromQL works with metrics of different types:
- Counter: a cumulative value that never decreases (e.g. number of HTTP requests). Heavily used with the
rate()function. - Gauge: a value that can go up or down arbitrarily (e.g. memory usage).
- Histogram: samples observations and counts them in configurable buckets.
- Summary: similar to the Histogram, but also computes sliding quantiles.
Simple expressions #
Simple expressions retrieve raw metrics:
http_requests_totalThis returns all current values (instant vector) of the http_requests_total metric.
Common commands #
The most used commands with explanations and examples.
Filtering with labels #
Metrics can be filtered using labels:
http_requests_total{method="GET", status="200"}This returns only the metrics where method is GET and status is 200.
Aggregation #
Aggregation functions summarize data:
sum(http_requests_total): sum of all requests.avg(http_requests_total): average of requests.max(http_requests_total): maximum value.min(http_requests_total): minimum value.
Functions #
PromQL offers functions to manipulate time series:
rate(metric[5m]): per-second rate of change over a 5-minute window.increase(metric[1h]): total increase over one hour.irate(metric[1m]): instantaneous rate based on the most recent points.
Arithmetic operations #
PromQL lets you perform calculations:
(http_requests_total{method="GET"} / http_requests_total) * 100This computes the percentage of GET requests relative to the total.
Joining metrics #
You can combine several metrics:
sum(cpu_usage) by (instance) / sum(cpu_limit) by (instance)This gives the CPU usage ratio per instance.
Advanced operations #
Going further with PromQL: logical operators, complex matching and offsets.
Set operators #
These operators filter and combine vectors:
and(intersection): returns the elements of the left vector that have a match on the right.or(union): returns all elements of the left vector and adds those from the right that have no match on the left.unless(difference): returns the elements of the left vector that have no match on the right.
Vector matching #
When you perform operations between two vectors, PromQL tries to match series by their labels. You can change this behavior:
ignoring(label)oron(label): restrict matching to a subset of labels, or ignore some of them.group_leftorgroup_right: used for many-to-one or one-to-many joins.
Offset modifier #
The offset modifier shifts the evaluation of a vector into the past. It is especially useful to compare current data with historical data:
http_requests_total offset 1wThis returns the value of the metric as it was exactly one week ago.
Visualizing results #
Display and analyze results in Prometheus and Grafana.
Prometheus #
In the Prometheus web UI, enter a PromQL query in the search bar to view the results in real time.
Grafana #
Grafana offers a more advanced interface to create graphs and dashboards based on PromQL queries.
Examples #
A few example queries:
CPU usage #
- Average load across all cores:
This query computes the average CPU usage rate (excluding idle mode) over the last 5 minutes.avg(rate(node_cpu_seconds_total{mode!="idle"}[5m])) - CPU usage per instance:
sum(rate(node_cpu_seconds_total{mode!="idle"}[5m])) by (instance)
Memory usage #
- Percentage of memory used:
100 * (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes)) - Memory used in gigabytes:
(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) / (1024 * 1024 * 1024)
Disk usage #
- Percentage of disk space used:
100 * (node_filesystem_size_bytes{fstype!~"tmpfs|overlay"} - node_filesystem_free_bytes{fstype!~"tmpfs|overlay"}) / node_filesystem_size_bytes{fstype!~"tmpfs|overlay"} - Free space on a specific disk:
node_filesystem_free_bytes{mountpoint="/"}
Network monitoring #
- Data transmit rate on a network interface:
rate(node_network_transmit_bytes_total[1m]) - Data receive rate:
rate(node_network_receive_bytes_total[1m])
Instance uptime #
- List of instances that are up:
up == 1 - cAdvisor instance:
up{instance="cadvisor:8080"}
Application errors #
- HTTP 5xx error rate:
rate(http_requests_total{status=~"5.."}[5m]) - Percentage of 5xx errors relative to total traffic:
100 * rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m])
Feeding an alert #
- Saturated CPU (> 90%):
avg(rate(node_cpu_seconds_total{mode!="idle"}[5m])) by (instance) > 0.9 - Less than 10% of disk space available:
(node_filesystem_free_bytes / node_filesystem_size_bytes) < 0.1
Best practices #
Tips for writing efficient PromQL queries.
Keep your queries simple #
Avoid overloading your queries with complex calculations. Use simple functions and combine them as needed.
Use aggregations #
Aggregations such as sum and avg simplify data and make it more readable.
Filter the data #
Use labels to reduce the volume of data returned, which improves query performance.
Conclusion #
Summary and next steps to master PromQL.
PromQL is a powerful language to analyze and monitor your metrics in Prometheus. By mastering its features, you can create precise alerts and detailed visualizations, and optimize your systems. Keep exploring the advanced functions and experiment with your metrics to get the most out of them.
2026 update: what has changed #
Recent changes worth knowing (checked in November 2026).
What Prometheus 3 changed for PromQL #
- UTF-8 names: metrics and labels can contain dots (OpenTelemetry names); write them in quotes inside the braces.
- Left-open windows: a
[5m]window now excludes the sample sitting exactly at its start.rate()results can differ slightly from Prometheus 2, especially with very short windows. - holt_winters was renamed
double_exponential_smoothingand moved behind an experimental flag. - New UI: the query editor includes expression explain and metric exploration.
- LTS releases: Prometheus publishes releases maintained for a year, to favour in production.
# UTF-8 metric names (OpenTelemetry): quotes inside the braces
sum by (service) (rate({"http.server.request.duration_count", "deployment.environment"="prod"}[5m]))
# Left-open windows (Prometheus 3): a sample exactly at the window start is no longer counted
rate(http_requests_total[5m])