Architecture
Server, exporters, Alertmanager, Pushgateway, Grafana, and the scrape loop
Prometheus is one statically linked Go binary. Inside it are four jobs that run continuously: discover targets, scrape them, store the samples, and evaluate rules. Everything else in the stack is a separate process with a narrow job.
Grafana sits beside Prometheus, not in the data path. It sends PromQL queries to Prometheus's HTTP API and draws the results.
The components
| Component | Job | Talks to |
|---|---|---|
| Prometheus server | Discovers targets, scrapes them, stores samples in its local TSDB, evaluates recording and alerting rules, serves PromQL | Targets (pull), Alertmanager (push alerts) |
| Exporters | Translate something that doesn't speak Prometheus (Linux /proc, Postgres pg_stat_*, an HTTP probe) into a /metrics page | The thing they export |
| Client libraries | Let your own code expose /metrics directly (Go, Java, Python, Node, ...) | Nothing; they just serve the page |
| Alertmanager | Receives firing alerts, deduplicates, groups, applies silences and inhibitions, sends notifications | Receivers (Slack, email, PagerDuty, webhooks) |
| Pushgateway | Holds the last metrics pushed by short-lived jobs so Prometheus can scrape them | Batch jobs push, Prometheus pulls |
| Grafana | Dashboards, exploration, and optionally its own alerting | Prometheus API, Alertmanager API |
Alerting is split into two processes on purpose. Prometheus decides whether something is wrong. Alertmanager decides who to tell and how often. Run two Prometheus servers for redundancy and both send the same alert; Alertmanager deduplicates them, so the on-call person gets one page, not two.
The scrape loop
For every target, Prometheus runs an independent loop:
- Wait for
scrape_interval(default 1m, set to 15s here). Prometheus staggers targets across the interval so they aren't all scraped at the same moment. - GET the target's
metrics_path(default/metrics), with ascrape_timeout(10s here). - Parse the response: each line is one sample.
- Apply
metric_relabel_configs, which can drop or rename series. - Attach the target's labels (
job,instance, and any you added). - Append every sample to the TSDB with the scrape's timestamp.
- Record synthetic metrics about the scrape itself:
up,scrape_duration_seconds,scrape_samples_scraped, and others.
If the GET fails or times out, step 7 still happens, with up set to 0.
Any series the target exposed last time are marked stale, so queries
stop returning them within one interval instead of showing a frozen line.
Rule evaluation
Separately, every evaluation_interval (15s here), Prometheus runs every
rule in rule_files:
- Recording rules run a PromQL expression and store the result as a new series. For example, precomputing the p99 latency so dashboards don't recompute it from raw buckets.
- Alerting rules run an expression. Every series it returns is an
alert. The alert goes pending, then firing once it has been
true for the
forduration. Firing alerts are sent to Alertmanager.
Both are covered in Rules, Alerting & SLOs.
Where state lives
/prometheus/ # the prometheus_data volume
├── wal/ # write-ahead log of recent samples (crash safety)
├── chunks_head/ # memory-mapped chunks of the in-memory head block
├── 01J9.../ # a persisted 2-hour (or compacted, larger) block
│ ├── chunks/ # compressed samples
│ ├── index # label -> series lookup
│ ├── meta.json # time range, stats
│ └── tombstones # deletions not yet compacted away
└── queries.active # in-flight queries, for crash diagnosticsThe most recent ~2 hours live in memory (the head block), backed by the WAL so a crash loses nothing. Older data lives in immutable on-disk blocks that are compacted into larger blocks over time. The full story is in Head, WAL & Blocks.
Prometheus has no clustering. Each server is independent, with its own local disk, and never talks to other Prometheus servers by default. That's a deliberate design choice: monitoring must keep working when the network is partitioned, and a single binary with local storage has very few ways to fail. Scaling and redundancy are added on top of that, by running more copies. See HA & Federation.
Prometheus's own API
Everything in the UI is built on an HTTP API you can call directly, which is useful for scripts and debugging:
# instant query
curl -s 'localhost:9090/api/v1/query?query=up' | jq
# range query: 5 minutes of data at 15s resolution
curl -s 'localhost:9090/api/v1/query_range' \
--data-urlencode 'query=rate(prometheus_http_requests_total[1m])' \
--data-urlencode "start=$(date -v-5M +%s)" \
--data-urlencode "end=$(date +%s)" \
--data-urlencode 'step=15s' | jq '.data.result | length'
# what is being scraped, and is it healthy?
curl -s localhost:9090/api/v1/targets | jq '.data.activeTargets[] | {job: .labels.job, health}'
# which series cost the most?
curl -s localhost:9090/api/v1/status/tsdb | jq '.data.seriesCountByMetricName[:5]'Grafana uses the same query and query_range endpoints. When a panel
looks wrong, copy its query into the Prometheus UI (or curl) to see
whether the problem is the data or the panel.
Next: Your First Scrape.