Video in progress
How does Prometheus collect metrics?
Prometheus works on a pull model: every 15–30 seconds it sends an HTTP request to the application's endpoint such as /actuator/prometheus, reads the text-format metrics and stores them as time series.
📖 Answer
This process is called a "scrape". In the configuration you write which addresses to read from:
scrape_configs:
- job_name: order-service
metrics_path: /actuator/prometheus
scrape_interval: 15s
static_configs:
- targets: ['order-service:8080']
In Kubernetes you don't write targets by hand: pods are found automatically through service discovery.
The text the endpoint returns looks like this:
http_server_requests_seconds_count{method="GET",status="200",uri="/orders"} 1532.0
The convenience of the pull model: if Prometheus can't reach a target, the up metric becomes 0, so you know right away the service is dead. The downside: batch jobs that run for only a few seconds may finish before the scrape, and they need the Pushgateway or another solution.
You query the stored data with the PromQL language, usually through Grafana.
Sign up to mark studied questions and save your progress.