Course contentsShow
← System Design
Lesson 1194 of 1,91930. Observability: MetricsFree lesson

Time-Series Queries and PromQL

Learning basic time-series query patterns for filtering, grouping, and computing rates over time windows.

Time-Series Queries and PromQL

You'll learn the fundamental query patterns for filtering, grouping, and computing rates over time windows in time-series databases.

When you have millions of metrics flowing through your system, raw numbers are meaningless without the ability to ask specific questions. PromQL (Prometheus Query Language) provides the vocabulary to slice, aggregate, and analyze time-series data effectively.

Core Query Patterns

Filtering lets you select specific time series using labels. Think of it like finding books in a library by author or genre:

http_requests_total{status="500", service="api"}

This retrieves only the request counters for HTTP 500 errors from your API service.

Grouping aggregates multiple series together. Imagine summing sales across all store locations to see company-wide revenue:

sum(http_requests_total) by (service)

This groups requests by service name, giving you per-service totals.

Rate calculations convert raw counter values into meaningful rates over time windows. Since counters only increase, you need rate functions to see "requests per second":

rate(http_requests_total[5m])

This calculates the per-second rate over the last 5 minutes, smoothing out spikes and giving you a true throughput picture.

Combining Patterns

You can chain these patterns together. To find which services have the highest error rates:

sum(rate(http_requests_total{status="500"}[5m])) by (service)

This filters for errors, calculates rates, then groups by service—answering "which service is failing most frequently right now?"

The bracket notation [5m] creates a range vector, looking back across a time window rather than just the instant value.

Key Takeaway: PromQL queries follow a filter-then-aggregate-then-calculate pattern, letting you transform raw time-series metrics into actionable insights about system behavior over time.