Exporters & the Pushgateway

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

An exporter bridges a system that does not natively speak Prometheus’s format into one that does: it runs as its own process, exposes a /metrics HTTP endpoint, and translates whatever it knows about a third-party system into Prometheus’s text exposition format on every scrape. This page covers the two most widely deployed exporters — node_exporter for host metrics and blackbox_exporter for active probing — the general shape of a custom exporter, and the Pushgateway, which exists for a narrow case that pull-based scraping cannot cover on its own. The full catalog of first-party and community exporters is Exporters & integrations; getting node_exporter running for the first time is covered in Getting Started. Database-specific community exporters follow the same shape — for example redis_exporter, covered from the Redis side in Administration, Monitoring & Troubleshooting.

node_exporter: host-level metrics

node_exporter exposes kernel and hardware metrics for the machine it runs on — CPU, memory, filesystems, disks, network interfaces — by reading /proc and /sys on Linux (with narrower support for other Unix-likes). Each metric family comes from an independent collector, and most collectors are on by default:

Collector What it reports

cpu

Per-CPU, per-mode time in node_cpu_seconds_total (user, system, iowait, idle, …​).

meminfo

Parsed /proc/meminfo fields such as node_memory_MemAvailable_bytes and node_memory_MemTotal_bytes.

filesystem

Per-mountpoint size and free space (node_filesystem_size_bytes, node_filesystem_avail_bytes).

diskstats

Per-block-device I/O counters (node_disk_read_bytes_total, node_disk_io_time_seconds_total).

netdev

Per-interface traffic counters (node_network_receive_bytes_total, node_network_transmit_bytes_total).

loadavg

The classic 1/5/15-minute load averages.

uname

A single info metric with kernel/architecture labels.

pressure

Linux pressure-stall information (node_pressure_cpu_waiting_seconds_total and friends): how long tasks waited for CPU, memory or I/O.

hwmon

Hardware sensors such as temperatures and fan speeds, where the kernel exposes them.

stat

Context switches, forks, boot time and interrupts from /proc/stat.

os

An info metric describing the distribution (node_os_info).

Running it and what comes out

The quickest way to try it, and the one used for the examples here, is the official container. Note that on Docker Desktop it observes the Linux virtual machine the containers run in, not the macOS or Windows host; on a Linux server you would run the binary (or a container with --pid=host and the root filesystem mounted read-only at /host with --path.rootfs=/host) so that it sees the real machine.

docker run -d --name node-exporter -p 9100:9100 prom/node-exporter
curl -s localhost:9100/metrics | grep -c '^node_'

The lab instance (node_exporter 1.12.1) exposed 1350 node_ series and reported success for 49 collectors, visible as one node_scrape_collector_success series per collector. Each scrape also exposes node_scrape_collector_duration_seconds, so a slow collector is easy to find. A handful of real queries against it:

Query Meaning Lab result

100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[1m])))

CPU busy percentage across all cores

56.2

1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes

Fraction of memory in use

0.649 (of 8.3 GB)

node_load1

One-minute load average

5.04

sum by (device) (rate(node_network_receive_bytes_total[1m]))

Receive throughput per interface

106 bytes per second on eth0

node_uname_info

Info series; labels carry kernel and machine

release="7.0.14-linuxkit", machine="aarch64"

node_cpu_seconds_total has one series per core and per mode (user, system, idle, iowait, irq, nice, softirq, steal); the lab VM had ten cores, so count(node_cpu_seconds_total) by (mode) returned 10 for each of the eight modes. That is why a CPU query always averages or sums over cpu and filters one mode — the modes of a core add up to wall-clock time.

flowchart LR P["Prometheus
scrapes every 5s"] -- "GET /metrics" --> N["node_exporter"] N --> C1["cpu collector
/proc/stat"] N --> C2["meminfo collector
/proc/meminfo"] N --> C3["filesystem, diskstats,
netdev, loadavg ..."] N --> C4["textfile collector
reads *.prom files"] C4 --- F[("cron job output
orders_batch.prom")]

Collectors are toggled with --collector.<name> / --no-collector.<name> flags at startup; a few collectors are off by default and must be enabled explicitly, while others (textfile, covered below) are on but do nothing until configured:

# Disable a noisy or irrelevant collector, and turn on the textfile collector
# pointed at a directory of *.prom files dropped there by cron jobs or scripts.
./node_exporter \
  --no-collector.arp \
  --collector.textfile.directory=/var/lib/node_exporter/textfile_collector
# https://github.com/prometheus/node_exporter

The textfile collector is the escape hatch for anything node_exporter does not natively read: a cron job writes plain exposition-format lines to a .prom file in the watched directory, and node_exporter folds them into its own /metrics output on the next scrape. A real run with the directory mounted and one file in it:

cat textfile/orders_batch.prom
# HELP orders_backup_last_success_timestamp_seconds Unixtime of the last successful backup.
# TYPE orders_backup_last_success_timestamp_seconds gauge
orders_backup_last_success_timestamp_seconds 1.794318e+09
# HELP orders_backup_size_bytes Size of the last backup.
# TYPE orders_backup_size_bytes gauge
orders_backup_size_bytes 5.2428800e+07

docker run -d -p 9100:9100 -v "$PWD/textfile:/textfile" prom/node-exporter \
  --collector.textfile.directory=/textfile
curl -s localhost:9100/metrics | grep -E '^orders_backup|^node_textfile_scrape_error'
node_textfile_scrape_error 0
orders_backup_last_success_timestamp_seconds 1.794318e+09
orders_backup_size_bytes 5.24288e+07

node_textfile_scrape_error flips to 1 when a file does not parse, so alert on it. Always write the file atomically (write a temporary file in another directory, then mv it into place) so a scrape never reads a half-written file, and remember that, unlike the Pushgateway, the series disappear as soon as the file does. Without --collector.textfile.directory the collector is enabled but has nothing to read. No separate HTTP endpoint is needed for that data. The full collector list, their default on/off state, and each metric’s name and labels are documented in the project’s own reference, not duplicated here: node_exporter.

blackbox_exporter: probing from the outside

Where node_exporter reports what a host observes about itself, blackbox_exporter reports what an external probe observes about a target — it is the exporter to reach for when the question is "is this endpoint reachable and responding correctly," not "what is this host’s own CPU doing." It supports HTTP(S), TCP, ICMP, and DNS probes, each defined as a named module in its own config file:

# blackbox.yml
modules:
  http_2xx:
    prober: http
    timeout: 5s
    http:
      valid_status_codes: [200]
      method: GET

  tcp_connect:
    prober: tcp
    timeout: 5s

  icmp_ping:
    prober: icmp
    timeout: 5s
# https://github.com/prometheus/blackbox_exporter

Prometheus does not scrape blackbox_exporter directly for the target’s own metrics; it scrapes the /probe endpoint of blackbox_exporter, passing the real target and the module to use as query parameters. The exporter performs the probe on the fly and returns metrics such as probe_success (1/0) and probe_duration_seconds for that request:

scrape_configs:
  - job_name: "blackbox-http"
    metrics_path: /probe
    params:
      module: [http_2xx]
    static_configs:
      - targets:
          - https://example.com
          - https://example.org
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: localhost:9115   # the blackbox_exporter itself
# https://github.com/prometheus/blackbox_exporter

The relabel_configs block above is the standard pattern for every blackbox_exporter job: the real target from static_configs is rewritten into a __param_target query parameter, copied into the instance label so it (not the exporter’s own address) identifies the series, and __address__ is then overwritten to point the scrape itself at blackbox_exporter. Relabeling in general is covered in Service Discovery & Relabeling. A probe of the example service through the exporter, run by hand, shows exactly what Prometheus will see:

curl -s localhost:9115/probe --get --data-urlencode 'target=http://host.docker.internal:28102/health' \
  --data-urlencode module=http_2xx | grep -E '^probe_(success|http_status_code|duration_seconds|ip_protocol) '
probe_duration_seconds 0.021755333
probe_http_status_code 200
probe_ip_protocol 4
probe_success 1

Adding &debug=true to the URL returns the probe’s own log instead of metrics, which is the first thing to check when probe_success is 0. It paid off in the lab: the first attempt failed because the exporter resolved host.docker.internal to an IPv6 address that the container could not reach (connect: network is unreachable). Setting preferred_ip_protocol: ip4 in the module, as in the configuration above, fixed it, and probe_ip_protocol then reported 4.

sequenceDiagram participant P as Prometheus participant B as blackbox_exporter participant T as Target URL P->>B: GET /probe?module=http_2xx&target=http://orders/health B->>T: HTTP GET /health T-->>B: 200 OK B-->>P: probe_success 1, probe_duration_seconds 0.02, probe_http_status_code 200

Scraped with the relabeling job shown above (targets /health and /orders of the example service), the exporter produced two series per probe metric, labeled with the target URL as instance:

probe_success
probe_duration_seconds
avg_over_time(probe_success[1m])
probe_success{instance="http://host.docker.internal:28102/health", job="blackbox-http"}   1
probe_success{instance="http://host.docker.internal:28102/orders", job="blackbox-http"}   1
probe_duration_seconds{instance=".../health", ...}   0.0013
probe_duration_seconds{instance=".../orders", ...}   0.608

/orders takes 0.6 s from the outside because that handler sleeps; an external probe sees the latency a user would, which an application’s own histogram (measured inside the process) can miss when the problem is a proxy or the network. avg_over_time(probe_success[5m]) is a simple availability figure, and a typical alert is probe_success == 0 with for: 2m. Targets are listed in the Prometheus configuration, not the exporter’s, so a new URL to probe is a scrape-config (or service-discovery) change.

ICMP probing needs raw-socket privileges (CAP_NET_RAW or root) on the host running the exporter.

Writing a custom exporter

When neither an existing exporter nor direct instrumentation (covered in Instrumenting Applications) fits — typically because the system you need metrics from is a third party you cannot add a client library to — the fix is a small standalone process that follows the same shape every official exporter uses:

  • Expose a single /metrics HTTP endpoint using a Prometheus client library.

  • On each scrape, either query the target system live (a database, a REST API, an appliance) and translate its current state into metrics on the spot, or serve values a background goroutine/thread already gathered on its own schedule and cached in memory.

  • Return plain, unauthenticated text in the Prometheus exposition format — no scrape-triggered side effects beyond reading state.

A working example: an exporter for a database table

The example below turns the number of orders in each status of a small SQLite database into a Gauge, with the Python client’s custom collector interface. A collector implements collect(); the registry calls it on every scrape, and it yields metric families built at that moment instead of mutating long-lived metric objects. This is the right shape when the values live somewhere else and the exporter only reports them.

import sqlite3
import sys
import time
from wsgiref.simple_server import make_server

from prometheus_client import make_wsgi_app
from prometheus_client.core import REGISTRY, GaugeMetricFamily

DB = sys.argv[1]


class OrdersCollector:
    """Queries the orders database on every scrape and yields fresh metrics."""

    def collect(self):
        started = time.time()
        queue = GaugeMetricFamily(
            "orders_queue_length", "Orders waiting by status.", labels=["status"]
        )
        success = 1
        try:
            with sqlite3.connect(DB, timeout=2) as conn:
                for status, count in conn.execute(
                    "SELECT status, COUNT(*) FROM orders GROUP BY status"
                ):
                    queue.add_metric([status], count)
        except sqlite3.Error:
            success = 0
        yield queue
        yield GaugeMetricFamily("orders_exporter_up", "1 if the last query worked.", value=success)
        yield GaugeMetricFamily(
            "orders_exporter_scrape_duration_seconds", "Time spent querying.", value=time.time() - started
        )


REGISTRY.register(OrdersCollector())
make_server("0.0.0.0", int(sys.argv[2]), make_wsgi_app()).serve_forever()
venv/bin/python sqlite_exporter.py orders.db 9200 &
curl -s localhost:9200/metrics | grep '^orders_'
orders_queue_length{status="new"} 7.0
orders_queue_length{status="paid"} 3.0
orders_queue_length{status="shipped"} 12.0
orders_exporter_up 1.0
orders_exporter_scrape_duration_seconds 0.00043892860412597656

The database held seven new, three paid and twelve shipped orders, and the output reflects that exactly. Three conventions from the guidelines are visible: the up-style metric (orders_exporter_up) separates "the database is empty" from "the database could not be queried" (a failed query must not make the whole scrape fail, or Prometheus would lose the exporter’s own health signal); the scrape duration metric exposes how long the live query took; and the status is a label on one metric rather than three metric names, so sum(orders_queue_length) works. Gauges are right here because the counts go down as orders ship.

The live-query-per-scrape pattern is simplest and keeps metrics as fresh as the last scrape, but it means a slow upstream call directly slows (or times out) the scrape; a background collector decouples the two at the cost of metrics that lag their own collection interval. Both are legitimate, and the choice is a per-exporter judgment call, not a Prometheus rule. The canonical guidance on this decision, naming conventions, and metric-type selection is Writing exporters.

The Pushgateway: what it is for

Every mechanism above is pull-based: Prometheus initiates the scrape, on its own schedule, and can tell a target apart from a target that has simply gone quiet. The Pushgateway is the one place this model is deliberately inverted: it is a small HTTP service that accepts pushed metrics and holds them in memory so a normal Prometheus scrape of the Pushgateway itself can still pull them out. It exists for exactly one case: short-lived batch or cron jobs that exit before any scrape could ever reach them.

# A batch job pushes its own result under the "my_batch_job" job label
# and a grouping label identifying this particular instance.
echo "my_batch_job_last_success_timestamp_seconds $(date +%s)" | \
  curl --data-binary @- \
    http://pushgateway:9091/metrics/job/my_batch_job/instance/db-backup-01
# https://prometheus.io/docs/instrumenting/pushing[Pushing metrics]

Prometheus then scrapes the Pushgateway like any other target:

scrape_configs:
  - job_name: "pushgateway"
    honor_labels: true          # keep the job/instance labels the job pushed, not the scrape's own
    static_configs:
      - targets: ["pushgateway:9091"]
# https://prometheus.io/docs/instrumenting/pushing[Pushing metrics]

honor_labels: true is not optional in practice here. The lab ran the same Pushgateway under two scrape jobs, one with and one without it, so the effect is visible side by side. With honor_labels: true the pushed job and instance survive. Without it, Prometheus keeps its own target labels and renames the colliding pushed ones with an exported_ prefix:

batch_job_duration_seconds{instance="db-backup-01", job="nightly_backup"}                       42.5
batch_job_duration_seconds{exported_instance="db-backup-01", exported_job="nightly_backup",
                           instance="host.docker.internal:29101", job="pushgateway-nohonor"}    42.5

Everything from every batch job would then carry the Pushgateway’s own job and instance, and an alert that selects job="nightly_backup" would never match.

Pushing from code, and the group semantics

A batch job usually pushes through the client library at the end of its run. The helper below pushes a duration, a success timestamp and a counter to the group identified by job="nightly_backup" and instance="db-backup-01":

import sys
import time

from prometheus_client import CollectorRegistry, Counter, Gauge, push_to_gateway

registry = CollectorRegistry()
duration = Gauge("batch_job_duration_seconds", "Duration of the last batch run.", registry=registry)
last_success = Gauge(
    "batch_job_last_success_timestamp_seconds", "Unixtime of the last successful run.", registry=registry
)
processed = Counter("batch_job_records_processed", "Records processed in this run.", registry=registry)

started = time.time()
for _ in range(1200):          # the "work"
    processed.inc()
duration.set(time.time() - started)
last_success.set_to_current_time()  # only reached when the work did not raise

push_to_gateway(sys.argv[1], job="nightly_backup", grouping_key={"instance": "db-backup-01"}, registry=registry)
batch_job_duration_seconds{instance="db-backup-01",job="nightly_backup"} 0.0004229545593261719
batch_job_last_success_timestamp_seconds{instance="db-backup-01",job="nightly_backup"} 1.794318182454259e+09
batch_job_records_processed_total{instance="db-backup-01",job="nightly_backup"} 1200
push_failure_time_seconds{instance="db-backup-01",job="nightly_backup"} 0
push_time_seconds{instance="db-backup-01",job="nightly_backup"} 1.7943181824595866e+09

The last two series are added by the Pushgateway itself and are the key to alerting on batch jobs. A group is the set of metrics sharing the same grouping labels (here job and instance), and the HTTP verb decides what a push does to the group:

Verb Effect on the group

PUT (the client library’s push_to_gateway)

Replaces every metric in the group with the pushed ones. A PUT carrying only batch_job_duration_seconds removed the other metrics, which the lab confirmed.

POST (pushadd_to_gateway)

Replaces only metrics with the same names, leaving the rest of the group untouched.

DELETE (delete_from_gateway)

Removes the whole group; the lab server answered 202 and the series was absent from the next scrape.

sequenceDiagram participant J as Batch job participant G as Pushgateway participant P as Prometheus J->>G: PUT /metrics/job/nightly_backup/instance/db-backup-01 J-->>J: exits loop every scrape interval P->>G: GET /metrics G-->>P: last pushed values, same until replaced or deleted end

The Pushgateway never forgets on its own, so the freshness of a push has to be measured explicitly:

time() - batch_job_last_success_timestamp_seconds{job="nightly_backup"}

returned 14.9 seconds shortly after the push and grows without bound afterwards, whereas the series itself keeps being scraped and never goes stale. An alert such as time() - batch_job_last_success_timestamp_seconds > 26 * 3600 detects a nightly job that stopped succeeding, and push_time_seconds tells when the last push of any kind happened. Also note that up{job="nightly_backup"} returned nothing: Prometheus only knows the target pushgateway, so the health of the job itself is invisible except through these timestamps.

When not to use it

The Pushgateway is explicitly not a general-purpose ingestion endpoint, and reaching for it out of habit breaks the properties pull-based scraping gives for free:

  • Never for regular, long-running service metrics. A normal service should expose its own /metrics and be scraped directly — pushing to the Pushgateway instead adds a hop, a single point of failure shared by every job pushing to it, and throws away per-target up semantics: Prometheus sees the Pushgateway as up, not the job that pushed.

  • It breaks staleness. A scraped target’s series go stale (and eventually disappear) automatically when the target stops responding. A metric pushed once to the Pushgateway is held and re-served on every subsequent scrape until something explicitly deletes it (DELETE /metrics/job/<job>/instance/<instance>) — so a batch job that stops running silently leaves its last value looking perpetually current instead of going stale.

  • It is not a queue or a buffer for high-volume or high-cardinality data — it holds the latest value per label set in memory, with no history and no aggregation.

The project’s own guidance on this boundary — and the handful of cases (short-lived batch jobs, service-level batch metrics that no scrape could otherwise observe) it is actually meant for — is Pushing metrics. For everything else, prefer a directly-scraped /metrics endpoint, whether from Instrumenting Applications or one of the exporters on this page.

Continue with Service Discovery & Relabeling for how scrape targets — including blackbox_exporter jobs like the one above — are discovered and relabeled at scale, or Containers & Kubernetes Monitoring for running these exporters alongside workloads in a cluster.