Exporters
node, postgres, blackbox, ClickHouse, and the Pushgateway
You can't add a client library to Linux or Postgres. An exporter is a small process that sits next to the thing you want to monitor, reads its native stats when scraped, and translates them into the Prometheus format.
Most exporters do the work at scrape time: no scrape, no queries
against the database. This keeps them stateless, but it means a slow
exporter makes a slow scrape, and a scrape that exceeds scrape_timeout
sets up to 0 even though the exporter is running.
node_exporter: the machine
Reads /proc and /sys and exposes a few hundred metrics about the
host. In compose_prod.yaml it runs with the host's root filesystem
mounted at /host and pid: host, so it sees the real machine, not just
its own container.
# CPU busy fraction (0-1), averaged over cores
1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m]))
# memory actually available to new processes
node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes
# disk space free per mount
node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes
# disk I/O saturation: fraction of time the device was busy
rate(node_disk_io_time_seconds_total[5m])
# network throughput
rate(node_network_receive_bytes_total{device!~"lo|veth.*"}[5m])
# load average relative to core count (saturation)
node_load1 / count without (cpu, mode) (node_cpu_seconds_total{mode="idle"})On macOS, Docker runs inside a Linux VM (OrbStack or Docker Desktop), so node_exporter reports that VM, not your Mac. CPU count and memory will match the VM's allocation. On a Linux server it would be the real host. For per-container resource usage you'd add cAdvisor, which is how Kubernetes exposes container metrics.
postgres_exporter: the database
Connects with a DSN and runs queries against pg_stat_database,
pg_stat_activity, pg_stat_bgwriter, pg_locks, replication views,
and so on. It's the scheduled version of the catalog queries from the
Postgres module's Monitoring
lesson.
postgres-exporter:
image: prometheuscommunity/postgres-exporter:v0.20.1
environment:
DATA_SOURCE_NAME: ${POSTGRES_EXPORTER_DSN} # from .env
extra_hosts:
- "host.docker.internal:host-gateway"pg_up # could the exporter connect?
sum by (state) (pg_stat_activity_count) # connections by state
rate(pg_stat_database_xact_commit{datname="learning"}[5m]) # commits/s
pg_database_size_bytes{datname="learning"}
rate(pg_stat_database_deadlocks{datname="learning"}[5m])Start the Postgres module (cd ../postgres && docker compose up -d), and
pg_up turns 1. The Postgres Overview dashboard in Grafana fills in.
Give the exporter its own role with pg_monitor, not a superuser:
CREATE ROLE exporter LOGIN PASSWORD '...'; GRANT pg_monitor TO exporter;.
It only needs to read statistics. In this lab it uses admin for
simplicity.
ClickHouse: a built-in endpoint
Some software exposes Prometheus metrics natively, so no exporter is
needed. ClickHouse can, but it's off by default. The file
prometheus/config/clickhouse/prometheus.xml turns it on:
<clickhouse>
<prometheus>
<endpoint>/metrics</endpoint>
<port>9363</port>
<metrics>true</metrics>
<events>true</events>
<asynchronous_metrics>true</asynchronous_metrics>
</prometheus>
</clickhouse>Mount it into ClickHouse's config.d/ and publish the port:
ports:
- "9363:9363"
volumes:
- ../prometheus/config/clickhouse/prometheus.xml:/etc/clickhouse-server/config.d/prometheus.xml:roAfter docker compose up -d in clickhouse/, the clickhouse target
in Prometheus turns green. Try ClickHouseProfileEvents_Query (queries
run) and ClickHouseMetrics_MemoryTracking.
Other software with native endpoints: Kafka (via JMX exporter), Kubernetes components, etcd, CoreDNS, Traefik, Grafana, Alertmanager, and Prometheus itself.
blackbox_exporter: from the outside
Every other exporter asks a system about itself. The blackbox exporter tests a system the way a user would: makes an HTTP request, opens a TCP connection, resolves DNS, pings. It's the "multi-target" pattern: one exporter probes many targets, chosen by a URL parameter.
# try it directly (the exporter's port isn't published, so ask from inside the network)
docker exec prometheus wget -qO- \
'http://blackbox-exporter:9115/probe?module=http_2xx&target=http://demo-app:8080/healthz'
probe_success # 1 if the probe passed
probe_duration_seconds # total time
probe_http_status_code
probe_ssl_earliest_cert_expiry - time() # seconds until TLS cert expiresThe relabeling that makes this work is in config/prometheus.yml under
blackbox-http, and explained in
Service Discovery & Relabeling.
Black-box probes catch failures nothing else can: a DNS record deleted, a load balancer misrouting, an expired certificate, a firewall change. The service's own metrics look perfect because no traffic reaches it. Always have at least one probe per user-facing endpoint.
Pushgateway: for jobs that don't live long
A nightly backup runs for 40 seconds. With a 15-second scrape interval, Prometheus might never see it. The Pushgateway is a metrics cache: the job pushes its final metrics there before exiting, and Prometheus scrapes the gateway.
docker compose -f compose_prod.yaml run --rm demo-app python batch_job.py
# then in Prometheus
nightly_backup_rows
time() - nightly_backup_last_success_timestamp_seconds # seconds since last successThe scrape job uses honor_labels: true, so the job="nightly_backup"
label the batch job pushed is kept, instead of being overwritten with
job="pushgateway".
The Pushgateway is not a general push endpoint. It never forgets:
a pushed metric stays until it's overwritten or deleted, so a job that
stops running keeps reporting its last success forever. up for it
means "the gateway is up", not "the job ran". And it's a single point of
failure. Use it only for service-level batch jobs, push a
last_success_timestamp gauge, and alert on its age.
Finding exporters
The Prometheus docs list hundreds of exporters, from MySQL and Redis to SNMP network gear and AWS CloudWatch. Before choosing one, check:
- Is it maintained? Prefer the
prometheusandprometheus-communityGitHub orgs. - How expensive is a scrape? Some exporters run heavy queries.
Check
scrape_duration_secondsafter enabling it. - How many series does it produce? Check
scrape_samples_post_metric_relabelingfor the job. Some exporters emit tens of thousands; drop what you don't need. - Does the software already expose metrics natively? That's usually better than an exporter.