PromQL (Prometheus Query Language) is a powerful query language used by Prometheus, a popular open-source monitoring and alerting toolkit. This guide will introduce you to the basics of PromQL and help you get started with writing queries.
What is PromQL?
PromQL is a query language designed to work with time series data, allowing you to select and aggregate data in real time. It's used for both graphing and alerting in Prometheus.
Basic Concepts
1. Metrics: Named measurements collected at regular intervals
2. Labels: Key-value pairs that add dimensions to metrics
3. Samples: Individual data points consisting of a float64 value and a millisecond-precision timestamp
The most basic PromQL query is just the name of a metric:
This returns the current value of the `http_requests_total` metric for all monitored endpoints.
Label Matchers
You can filter metrics using label matchers:
This query selects only the HTTP requests with a status code of 200 and GET method.
Range Vectors
To query data over time, use range vectors:
http_requests_total[5m]
This returns all values of `http_requests_total` over the last 5 minutes.
Basic Functions
PromQL provides various functions to work with data:
rate(): Calculate per-second rate of increase
rate(http_requests_total[5m])
sum(): Add up values
sum(http_requests_total)
avg(): Calculate average
avg(node_cpu_utilization)
This guide has introduced you to the basics of PromQL. As you become more comfortable with these concepts, you'll be able to write more complex queries to gain deeper insights into your systems.
π
Also read: The Awesome Prometheus ToolkitβYour Ideal Companion to Kickstart Monitoring
Next Steps
- Experiment with different functions and operators
- Learn about aggregation and grouping
- Explore more advanced PromQL features like subqueries and offset modifiers.
π
Share your SRE experiences, and thoughts on reliability, observability, or monitoring. Let's connect on theSRE Discord community!