Prometheus
Prometheus is a free and open source software project centered on server monitoring and alerting.
Contents
Project
The Prometheus project consists of:
- the Prometheus time series database
the Prometheus web scraper which aggregates metrics from targets into the database
- the built-in web interface for querying the database
- the HTTP API for querying the database, as used by Grafana
a set of exporters which expose metrics from various sources
the Prometheus query language, PromQL
PromQL
PromQL is a query language built for the Prometheus project. It specializes in time series queries.
Consider the use case of monitoring 5xx errors in an NGINX instance. The below would query all such events:
http_requests_total{status="500"}
The below would then query the per-second rate of those events over 5 minutes, demonstrating how time series are a first class citizen of this language:
rate(http_requests_total{status="500"}[5m])
Queries can be functionally combined as shown below, to compute the error rate:
sum(rate(http_requests_total{status="500"}[5m])) / sum(rate(http_requests_total{}[5m]))
Furthermore, operators such as division (/) are capable of matching left-hand and right-hand vectors, to compute the per-path error rate:
sum by(path) (rate(http_requests_total{status="500"}[5m])) / sum by(path) (rate(http_requests_total{}[5m]))