Prometheus: What Is Prometheus?
Prometheus is a free tool that collects numbers from services and stores them with timestamps. It asks services for their numbers instead of waiting to be told.
The pull idea
Prometheus visits the service. The service does not phone home.
Prometheus --asks--> ShopSentry /metrics
ShopSentry --answers--> numbers with timesWhat a metrics page looks like
A metrics page is plain text. Each line is a name, some labels, and a number.
http_requests_total{route="/",status="200"} 41Four metric kinds, named only
Prometheus knows four kinds of numbers: counter, gauge, histogram and summary.
counter: only goes up
gauge: moves up and down
histogram: measures sizes in buckets
summary: measures sizes in percentilesExample
curl -s "http://127.0.0.1:19101/api/v1/query?query=up"Key points
- Prometheus: a collector and store for numbers measured over time.
- Prometheus pulls numbers: it visits each service on a schedule and asks for its metrics.
- Each service answers with a page of numbers, called a metrics page.
- Prometheus stores every number with the time it was collected.
- A query language called PromQL asks the store questions, like how fast errors are rising.
- Prometheus also watches rules and can raise alerts when a number crosses a limit.
In this example, a PromQL query asks Prometheus for the value of up, which is 1 when a target answers and 0 when it does not. All three targets answer 1: the shop, the host monitor, and Prometheus itself. The answer is a list of three series, one per target.
Note
Prometheus stores numbers, not log lines, because it is built for metrics.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
How does Prometheus collect metrics from a service?