Sub topic 2
How Prometheus, exporters, Alertmanager, and Grafana fit together
This chapter assumes you can edit YAML files, manage services with systemctl, and use curl against an HTTP endpoint. It gives you the overall picture of the stack. Later chapters install and configure each part.
The four roles
A Prometheus monitoring stack has four main parts. Each does one job and talks to the others over plain HTTP.
- Exporters run on or near the thing being measured. An exporter reads data from a system, such as the Linux kernel, and publishes it as text at an HTTP path, usually
/metrics. An exporter does not store history and does not decide what is a problem. - The Prometheus server is the central part. It fetches (scrapes) the exporters on a schedule, stores the samples in its own time series database, answers queries written in PromQL, and evaluates rules.
- Alertmanager is a separate process. It receives alerts from Prometheus and decides who is told, when, and how often.
- Grafana is a visualization tool. It sends PromQL queries to Prometheus and draws the results as panels on dashboards.
Prometheus ships as a single binary, and the same binary holds the scraper, the database, the query engine, the rule evaluator, and a basic web UI. Alertmanager and Grafana are separate projects with their own binaries, configuration files, and release schedules.
The data flow
Note the direction of the arrows. Prometheus opens the connection to each exporter. Grafana opens the connection to Prometheus. Prometheus opens the connection to Alertmanager. No exporter ever needs to know where Prometheus is.
The pull model
In a pull model, the monitoring server asks each target for its current values. In a push model, each target sends its data to the monitoring server. Prometheus pulls.
One scrape cycle works like this:
- At each
scrape_interval, Prometheus sends an HTTP GET request to the target's/metricspath. - The target replies with its current values as plain text.
- Prometheus attaches a timestamp, adds target labels such as
jobandinstance, and appends the samples to storage. - Prometheus records a synthetic metric named
upfor the target:1if the scrape succeeded,0if it failed.
The up metric is the central health signal of the pull model. A failed scrape produces up == 0, so a dead host reports itself as missing instead of staying silent. A push system has a harder problem here, because it cannot tell a host that is quiet from a host that has died.
Trade-offs of pulling
| Aspect | Pull (Prometheus) | Push |
|---|---|---|
| Detecting a dead target | Built in: `up` becomes 0 | Needs a separate "no data received" check |
| Checking a target by hand | Run `curl` against `/metrics` | Need a copy of what was sent |
| Network direction | Prometheus must reach every target | Targets must reach the server |
| Short-lived jobs | Poor fit: the job may end before a scrape | Good fit |
| Configuration | Target list lives in one place | Each target needs the server address |
The main failure mode of pulling is reachability. If a firewall, NAT, or network zone blocks Prometheus from reaching a target, the target looks down even though it is healthy. For batch jobs that finish between scrapes, Prometheus offers the Pushgateway, a small service that holds pushed values until Prometheus scrapes them. Use it for batch jobs only. Do not use it to monitor long-running servers, because it hides the up signal for the original host.
Who does what
| Component | Default port | Reads from | Stores data | Decides alerts |
|---|---|---|---|---|
| node_exporter | 9100 | Linux kernel (`/proc`, `/sys`) | No | No |
| Prometheus | 9090 | Targets' `/metrics` | Yes, on local disk | Evaluates alerting rules |
| Alertmanager | 9093 | Alerts from Prometheus | Only silences and notification state | Routes and groups, but does not create alerts |
| Grafana | 3000 | Prometheus (a data source) | Dashboards and settings, not metrics | No (in this setup) |
This split matters when you debug. An empty dashboard panel can come from a failed scrape, a wrong query, or a bad data source setting in Grafana. Knowing which component owns which step lets you test one hop at a time.
A minimal configuration
Prometheus learns about the rest of the stack from one file, prometheus.yml. This example scrapes Prometheus itself and two servers, loads rule files, and names the Alertmanager.
global:
scrape_interval: 15s
evaluation_interval: 15s
rule_files:
- rules/*.yml
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['localhost:9090']
- job_name: node
static_configs:
- targets: ['server1.example.com:9100', 'server2.example.com:9100']Each section maps to a link in the diagram:
scrape_configsdefines the arrows from Prometheus to the exporters.rule_filespoints to recording and alerting rules, which Prometheus evaluates everyevaluation_interval.alertingdefines the arrow from Prometheus to Alertmanager.
Grafana is not mentioned in this file. Grafana is a client of Prometheus and is configured on its own side, through a data source.
Checking each hop
Every component exposes an HTTP endpoint, so you can test the chain one link at a time from the monitoring host.
# 1. Does the exporter publish metrics?
curl -s http://server1.example.com:9100/metrics | head -n 5
# 2. Is Prometheus running and ready to serve queries?
curl -s http://localhost:9090/-/ready
# 3. Is Alertmanager running?
curl -s http://localhost:9093/-/healthy
# 4. Is Grafana running?
curl -s http://localhost:3000/api/healthIf step 1 fails, the problem is on the target or in the network. If step 1 works but the Prometheus UI shows the target as down, the problem is in prometheus.yml or in a firewall between the two hosts. If Prometheus has the data but Grafana is empty, check the data source URL and the query.
Where the stack can fail
- Prometheus down: nothing is scraped, no rules are evaluated, and no alerts fire. Prometheus cannot report its own death, so a small production setup needs an outside check, such as a second Prometheus or a hosted uptime probe.
- Alertmanager down: metrics and dashboards keep working, but notifications are lost. Prometheus retries sending, yet alerts that resolve during the outage may never be delivered.
- Grafana down: dashboards are unavailable, but collection and alerting are unaffected. Because alert rules live in Prometheus, alerting does not depend on Grafana.
- An exporter down: only that target is affected. Its
upvalue drops to 0 and its other metrics stop.
Exercise
A server is healthy and you can reach its node_exporter with curl from your laptop, but the Prometheus UI shows the target as down and up is 0. Which direction of connection should you test next, and why?
Show answer
Test the connection from the Prometheus host to the target, for example by running curl http://server1.example.com:9100/metrics on the Prometheus host. Prometheus pulls, so it is the one that must reach the exporter. A firewall or network rule can allow your laptop but block the Prometheus host. Also check that the host name and port in scrape_configs match the exporter.
Exercise
Prometheus and Grafana both run on the monitoring host. If you stop the Grafana service for an upgrade, are alerts still evaluated and sent? Explain.
Show answer
Yes. Alerting rules are evaluated by Prometheus and delivered through Alertmanager. Grafana only queries Prometheus to draw dashboards, so stopping it affects visualization only.