Back to tools

PromQL Query Builder

Create Prometheus queries visually without memorizing the exact syntax.

What is PromQL?

PromQL (Prometheus Query Language) is Prometheus' query language used to select and aggregate time series metric data in real-time.

  • rate() / irate(): Calculates per-second rate of change
  • sum() / avg() / min() / max(): Aggregation functions
  • by / without: Group by specific labels
  • offset: Query historical data

Frequently Asked Questions

What is PromQL and how to use it for querying Prometheus metrics?

PromQL (Prometheus Query Language) is the query language for extracting and aggregating time-series data from Prometheus. Basic example: `rate(http_requests_total[5m])` calculates requests per second over the last 5 minutes. Label selectors filter metrics: `http_requests_total{status="200", method="GET"}`. Aggregation functions like `sum()` or `avg()` combine multiple series. PromQL powers Grafana dashboards, Alertmanager alert rules, and supports retrospective analysis.

How to calculate container CPU usage with PromQL?

To calculate container CPU usage: `rate(container_cpu_usage_seconds_total[5m])` returns CPU seconds per second. For percentage: `rate(container_cpu_usage_seconds_total[5m]) / on() machine_cpu_cores * 100`. For a specific container: `rate(container_cpu_usage_seconds_total{name="myapp"}[5m])`. With kubelet metrics: `sum(rate(container_cpu_usage_seconds_total{container!="POD"}[5m])) by (pod)`. The `irate()` function is better for spiky metrics.

What is the difference between rate and irate in PromQL and when to use each?

`rate()` calculates the average per-second increase over the entire time range: `rate(metric[5m])` divides the total increment by 300 seconds, smoothing spikes and producing a more stable line. `irate()` calculates the rate based on the last two samples only: `irate(metric[5m])`, making it more sensitive to sudden changes. Use `rate()` for overview panels and alerting rules. Use `irate()` for detailed graphs where every variation matters.

How to create PromQL queries that group by labels using by()?

The `by()` clause in PromQL groups aggregation results by specific labels. Example: `sum(rate(http_requests_total[5m])) by (status, method)` sums requests per second grouped by HTTP status code and method. `topk(5, max(node_memory_MemAvailable_bytes) by (instance))` shows the top 5 instances with most available memory. Use `without()` to exclude specific labels instead of including them.