Exporters: Node, Blackbox & Friends
An exporter is a small process that reads the state of something that doesn't speak Prometheus (the Linux kernel, PostgreSQL, Redis, a router) and serves it on /metrics. Prometheus scrapes the exporter, not the thing itself.
The ones every setup has
| Exporter | Port | What it exposes |
|---|---|---|
| node_exporter | 9100 | Linux host metrics: CPU (node_cpu_seconds_total), memory (node_memory_MemAvailable_bytes), disks (node_filesystem_avail_bytes, node_disk_io_time_seconds_total), network, load, pressure (PSI) |
| kube-state-metrics | 8080 | the desired and current state of Kubernetes objects: kube_deployment_status_replicas_available, kube_pod_container_status_restarts_total, kube_pod_status_phase |
| cAdvisor (inside the kubelet) | 10250 | per-container CPU, memory, network: container_cpu_usage_seconds_total, container_memory_working_set_bytes |
| blackbox_exporter | 9115 | probes from the outside: HTTP, TCP, ICMP, DNS, TLS certificate expiry |
| postgres_exporter, redis_exporter, mysqld_exporter | 9187, 9121, 9104 | database internals: connections, replication lag, cache hit ratio |
kube-prometheus-stack installs node_exporter (as a DaemonSet), kube-state-metrics and the kubelet/cAdvisor scrape configs for you. The difference between the last two matters: kube-state-metrics tells you "the Deployment wants 3 replicas and has 2", cAdvisor tells you "this container uses 412 MiB".
On a plain Linux server, node_exporter is a systemd service (Linux Server Administration shows how to write one):
# sample session
$ curl -s localhost:9100/metrics | grep -E '^node_(load1|memory_MemAvailable_bytes|filesystem_avail_bytes\{.*mountpoint="/")'
node_filesystem_avail_bytes{device="/dev/nvme0n1p2",fstype="ext4",mountpoint="/"} 3.1874400256e+10
node_load1 0.42
node_memory_MemAvailable_bytes 5.928497152e+09The textfile collector
node_exporter's --collector.textfile.directory reads every *.prom file in a directory and serves its contents. It's the simplest way to publish metrics from cron jobs and scripts: backups, certificate checks, package update counts. Write to a temporary file and mv it into place, so node_exporter never reads half a file:
mkdir textfile
cat > backup.sh <<'SH'
#!/usr/bin/env bash
# after a backup: publish its outcome for node_exporter's textfile collector
set -euo pipefail
dir=textfile
started=1767232800 # in a real script: $(date +%s) before the backup
ended=1767233046 # and after it
bytes=734003200
tmp=$(mktemp "$dir/.backup.prom.XXXXXX")
cat > "$tmp" <<PROM
# HELP backup_last_success_timestamp_seconds When the last successful backup finished.
# TYPE backup_last_success_timestamp_seconds gauge
backup_last_success_timestamp_seconds{job="pg-nightly"} $ended
# HELP backup_duration_seconds How long the last backup took.
# TYPE backup_duration_seconds gauge
backup_duration_seconds{job="pg-nightly"} $((ended - started))
# HELP backup_size_bytes Size of the last backup.
# TYPE backup_size_bytes gauge
backup_size_bytes{job="pg-nightly"} $bytes
PROM
mv "$tmp" "$dir/backup.prom"
SH
bash backup.sh
cat textfile/backup.prom | grep -v '^#'
promtool check metrics < textfile/backup.prom && echo "lint: ok"backup_last_success_timestamp_seconds{job="pg-nightly"} 1767233046
backup_duration_seconds{job="pg-nightly"} 246
backup_size_bytes{job="pg-nightly"} 734003200
lint: ok
The alert for it doesn't look at success counters; it checks freshness: time() - backup_last_success_timestamp_seconds > 26 * 3600 fires when no backup has succeeded for 26 hours, whatever the reason (job failed, cron broken, server gone). That pattern works for every batch job.
Blackbox probing
The blackbox exporter probes targets you pass to it as a URL parameter: Prometheus scrapes blackbox:9115/probe?module=http_2xx&target=https://linkly.example.com/healthz. The exporter's config defines modules:
# blackbox.yml
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_status_codes: [200]
fail_if_not_ssl: true
tcp_connect:
prober: tcpThe scrape config uses a well-known relabeling trick: the target list holds the URLs to probe, and relabeling moves each into the target parameter and points __address__ at the exporter. Checked offline:
cat > prometheus.yml <<'YML'
scrape_configs:
- job_name: blackbox-http
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://linkly.example.com/healthz
- https://status.example.com/
relabel_configs:
- source_labels: [__address__]
target_label: __param_target # becomes ?target=...
- source_labels: [__param_target]
target_label: instance # keep the probed URL as the instance label
- target_label: __address__
replacement: blackbox-exporter:9115
YML
promtool check service-discovery prometheus.yml blackbox-http |
jq -r '.[].labels | "\(.__scheme__)://\(.__address__)\(.__metrics_path__)?module=\(.__param_module)&target=\(.__param_target) instance=\(.instance)"'http://blackbox-exporter:9115/probe?module=http_2xx&target=https://linkly.example.com/healthz instance=https://linkly.example.com/healthz
http://blackbox-exporter:9115/probe?module=http_2xx&target=https://status.example.com/ instance=https://status.example.com/
Probe results come back as probe_success (1/0), probe_http_status_code, probe_duration_seconds and probe_ssl_earliest_cert_expiry (a Unix timestamp). Two alerts every public endpoint should have:
- alert: EndpointDown
expr: probe_success{job="blackbox-http"} == 0
for: 3m
- alert: CertificateExpiresSoon
expr: probe_ssl_earliest_cert_expiry - time() < 14 * 24 * 3600
for: 1hBlackbox probes measure what users see (DNS, TLS, the load balancer, the app) from where the exporter runs; they complement, not replace, the app's own metrics. Run one in a different network or region from the service, or the probe and the outage share a fate.
Finding exporters
The Prometheus docs list hundreds of exporters (databases, message queues, hardware, cloud services). Before installing one, check that it's maintained, that it doesn't open a write path into the system it watches, and how many series it produces (count by (__name__)({job="new-exporter"})).
Test yourself
Which exporter tells you that a Deployment wants 3 replicas but only 2 are available?
- node_exporter
- cAdvisor
- kube-state-metrics
- blackbox_exporter
What is the most robust alert for a nightly batch job?
- Alert when its failure counter increases
- Alert when the last-success timestamp is older than the expected interval plus a margin
- Alert when it is running
- No alert; check the logs
In the blackbox scrape config, what does __param_target do?
- Sets the Alertmanager target
- Becomes the
targetURL query parameter of the scrape request - Renames the job
- Enables TLS