Learn Labs
Instrumentation & Exporters

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.

SQLPrometheuspostgres_exporterqueries on each scrapePostgrespg_stat_* viewsblackbox_exporter/probe?target=…demo-app/healthzgrafana/api/healthPrometheus scrapes the exporters; each does the real work (SQL, an HTTP probe) when scraped

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"})

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.

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:ro

After 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 expires

The relabeling that makes this work is in config/prometheus.yml under blackbox-http, and explained in Service Discovery & Relabeling.

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 success

The 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".

Finding exporters

The Prometheus docs list hundreds of exporters, from MySQL and Redis to SNMP network gear and AWS CloudWatch. Before choosing one, check:

  1. Is it maintained? Prefer the prometheus and prometheus-community GitHub orgs.
  2. How expensive is a scrape? Some exporters run heavy queries. Check scrape_duration_seconds after enabling it.
  3. How many series does it produce? Check scrape_samples_post_metric_relabeling for the job. Some exporters emit tens of thousands; drop what you don't need.
  4. Does the software already expose metrics natively? That's usually better than an exporter.

On this page