Prometheus - Query (PromQL, Expression)

1 - About

Query / Expression

3 - Example

3.1 - Time Series

  • return the time series of the metric name promhttp_metric_handler_requests_total with different labels by requests statuses.

promhttp_metric_handler_requests_total 

3.2 - Filtering

  • requests that resulted in HTTP code 200

promhttp_metric_handler_requests_total{code="200"} 

3.3 - Count

  • Number of times serie data by metrics

count(promhttp_metric_handler_requests_total) 

3.4 - Request Rate


-- the per-second HTTP request rate returning status code 200
rate(promhttp_metric_handler_requests_total{code="200"}[1m]) 
-- Given an HTTP request counter, this query calculates the per-second average request rate over the last 5 minutes.
rate(http_request_total[5m]) 

3.5 - Histogram

  • 95th Percentile of Request Latencies: Calculates the 95th percentile of HTTP request rate over 5 minute windows.

histogram_quantile(0.95, sum(rate(prometheus_http_request_duration_seconds_bucket[5m])) by (le))

3.6 - Alert

  • Alerts Firing: Sums up the alerts that have been firing over the last 24 hours.

sort_desc(sum(sum_over_time(ALERTS{alertstate="firing"}[24h])) by (alertname))

4 - Management

4.1 - GUI

navigate to http://localhost:9090/graph and choose:

  • the “Console” (to see the data)
  • or the graph tab (to graph)

4.2 - Step

Defines the graph resolution using a duration format (15s, 1m, 3h, …). Small steps create high-resolution graphs but can be slow over larger time ranges. Using a longer step lowers the resolution and smooths the graph by producing fewer datapoints. If no step is given the resolution is calculated automatically.

5 - Documentation / Reference


Data Science
Data Analysis
Statistics
Data Science
Linear Algebra Mathematics
Trigonometry

Powered by ComboStrap