Linux Labs

Observability: metrics, alerts, logs / Stage 1 of 9

Metrics, exporters and scraping

Not running Starting usually ~20 s
Leave the lesson

Step 4 of 7 · on a machine · 7 min

Prometheus scrapes targets

The exporter only knows “now”. History is kept by Prometheus — it fetches the metrics itself.

The node_exporter service is an exporter: it turns the machine's figures into this text format. Every scrape_interval Prometheus requests /metrics from each target — an exporter or an application from its config — and stores the values with a timestamp. Such a request is called a scrape. Targets are grouped into jobs — the scrape_configs list in /etc/prometheus/prometheus.yml (in the Wiki):

yaml
scrape_configs:
  - job_name: node                       # job name
    static_configs:
      - targets: ['localhost:9100']      # target address:port

Prometheus adds two labels to every series it scrapes: job, the job name, and instance, the target address. And for every target it writes its own up series: 1 — the last scrape worked, 0 — the target did not answer.

The Prometheus web interface lives on port 9090, but there is no browser to this machine. The state of the targets comes from the /api/v1/targets API — handy to read through jq (in the Wiki) — and promtool query instant runs a query against the collected data.

Exercise · look

Look at Prometheus's targets

Prometheus on the machine scrapes metrics according to /etc/prometheus/prometheus.yml. Look at the config, at the state of the targets and at the up values. The labapp training app is not running yet.

First, predict

The config has a job for labapp, but the app itself is not running. What will Prometheus show about its target?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in

The reason in lastError is what Prometheus got back: connection refused means nothing listens on that port. The service is not running or listens on another port — ss -ltn shows which. The address of node_exporter itself is set by the --web.listen-address option in the ARGS line of /etc/default/prometheus-node-exporter; without the option it is port 9100 (in the Wiki).

Ubuntu 24.04
Loading…