Skip to content
Français
Sync not enabled: your progress stays in this browser My learning
Select theme
Français

Prometheus exporters

24 min read
Improve this page

Prometheus does only one thing to collect data: it sends an HTTP request and reads a text in the format it expects. An exporter is the program that produces this text from a source that knows nothing about it: an operating system, a database, a network device. This guide helps you pick the right tool and understand how the pieces fit together.

What you will learn

  • Tell the three exporter families apart, and know which one requires relabeling.
  • Choose between an exporter and direct instrumentation of your code.
  • Install Node Exporter as a systemd service, under a dedicated account.
  • Set up the multi-target pattern with Blackbox, relabeling included.
  • Avoid cardinality traps and never expose /metrics without protection.

Where do exporters fit?

The exporter never sends anything on its own: Prometheus comes to read its /metrics endpoint at regular intervals, an operation called a scrape. This pull model, as opposed to the push of a classic agent, explains most of the rest of the page: the exporter must be reachable over the network from the Prometheus server, not the other way around.

Collection flow: the source (MySQL, OS, Redis) hands its data to the exporter, which exposes it on /metrics; Prometheus reads it with an HTTP GET request.collectHTTP GETSourceMySQL, OS, Redis…Exporter/metricsPrometheusscrape
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %
[SOURCE] → (exporter / instrumentation) → /metrics ──scrape──▶ Prometheus
  • Source: OS, DB, network service, application…
  • Exporter: queries the source and publishes the result on /metrics
  • Prometheus: collects, stores, queries, alerts

Exporter or instrumentation: how to decide?

A single criterion decides: who owns the code. Instrumenting means making the application produce its own metrics, which gives access to business indicators that no external tool can infer: an average basket value, a number of pending orders. An exporter observes from the outside what a component is willing to expose, so it is limited to what that component already publishes.

SituationSolutionWhy
I have the app's codeInstrumentation (client libs, OTel)Precise business metrics, less approximation
Third-party product, no codeDedicated exporterMySQL, PostgreSQL, Redis, Nginx…
Operating systemAgent (Node/Windows Exporter)CPU, RAM, disk, network
Check external availabilityBlackbox ExporterHTTP, DNS, TCP, ICMP probes

The 3 exporter families

This is the distinction to understand before configuring anything, because it changes the way you write the scrape_config. The sorting criterion is simple: how many targets can one instance of the exporter observe, and where does it run relative to them. The first two families are configured with an ordinary list of targets; the third one requires relabeling, detailed below.

Family A, Single-target (agents)

One exporter = one machine or service. The exporter runs on or next to the target.

ExampleUse
Node ExporterLinux system metrics
Windows ExporterWindows system metrics

Prometheus configuration (simple):

scrape_configs:
- job_name: node
static_configs:
- targets: ['server1:9100', 'server2:9100']

Each target is the exporter itself.

Family B, Service (DB, caches, brokers)

The exporter connects to a service (MySQL, PostgreSQL, Redis…) over TCP with credentials, then exposes /metrics.

ExampleUse
mysqld_exporterMySQL/MariaDB
postgres_exporterPostgreSQL
redis_exporterRedis
mongodb_exporterMongoDB

Points to watch:

  • Minimum privileges (read-only whenever possible)
  • Collection latency → adjust scrape_timeout
  • Label cardinality

Family C, Multi-target (proxy/prober)

A single exporter can monitor N targets through a target=... parameter. This is the multi-target exporter pattern.

ExampleUse
Blackbox ExporterHTTP, DNS, TCP, ICMP probes
SNMP ExporterSNMP network devices

Why is it different?

  • The exporter does not know the targets in advance
  • Prometheus passes the target as a parameter through relabeling
  • A single exporter can probe hundreds of URLs

Choosing the right tool (decision table)

This table starts from the intent, not from the tool: first state what you want to know, then the family column tells you which kind of configuration to plan. The last row is an exception, since cAdvisor is not an exporter in the strict sense, as the note below explains.

IntentToolFamilyWhat it measures
Linux machine healthNode ExporterACPU, RAM, disk, network
Windows healthwindows_exporterAPerformance counters
HTTP/DNS/TCP/ICMP availabilityBlackbox ExporterCExternal probes, SSL expiry
MySQL/MariaDB healthmysqld_exporterBConnections, queries, replication
PostgreSQL healthpostgres_exporterBConnections, locks, bloat
Redis healthredis_exporterBMemory, keys, ops/sec
Container metricscAdvisor / kubeletSourceCPU, RAM, I/O per container

Full list of official exporters

Node Exporter (Family A)

This is the exporter to deploy first: it collects the system metrics of a Linux machine: CPU, memory, disks, network interfaces. It is installed on every server you want to monitor and listens on port 9100 by default. No configuration is needed to start: the settings only serve to enable or disable collectors.

Installation

The binary is the recommended mode on a physical or virtual machine, because the exporter must see the host system to measure anything. The Docker variant exists but requires several options to share resources with the host, detailed in its tab.

  1. Download the archive and the checksum file

    Terminal window
    cd /tmp
    VERSION="1.12.1"
    BASE="https://github.com/prometheus/node_exporter/releases/download/v${VERSION}"
    wget "${BASE}/node_exporter-${VERSION}.linux-amd64.tar.gz"
    wget "${BASE}/sha256sums.txt"

    On a minimal Debian 13 installation, wget is not installed while curl is: running apt install wget first avoids a command not found on the very first command of the procedure.

  2. Check the digest before extracting

    Terminal window
    sha256sum --ignore-missing -c sha256sums.txt

    The output must show the archive line followed by OK. If it shows FAILED, the archive is corrupted or tampered with: delete it without extracting it. The order matters, and that is the whole point of this step: a digest computed after extraction protects nothing.

  3. Install

    Terminal window
    tar xvfz node_exporter-${VERSION}.linux-amd64.tar.gz
    sudo cp node_exporter-${VERSION}.linux-amd64/node_exporter /usr/local/bin/
    sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter

    The --system option is not decorative: without it, useradd picks from the range of human accounts. Measured on Debian 13, the same account gets UID 1002 without --system and UID 988 with it, and a UID above 1000 makes a service account show up in login screens and user inventories. The node_exporter group is created automatically because /etc/login.defs contains USERGROUPS_ENAB yes: this is what lets the unit ask for Group=node_exporter without any other command.

  4. Create the service

    /etc/systemd/system/node_exporter.service
    [Unit]
    Description=Node Exporter
    Wants=network-online.target
    After=network-online.target
    [Service]
    User=node_exporter
    Group=node_exporter
    Type=exec
    ExecStart=/usr/local/bin/node_exporter
    Restart=always
    # Hardening
    NoNewPrivileges=true
    ProtectSystem=strict
    ProtectHome=true
    [Install]
    WantedBy=multi-user.target

    Type=exec deserves an explanation, because Type=simple is the value you meet most often in exporter units. Both start a foreground process, but they do not tell systemctl start the same thing. Tested on systemd 257, Debian 13, with a deliberately missing ExecStart:

    SettingWhat systemctl start returnsActual service state
    Type=simple0, so a successactive, although nothing is running
    Type=exec1, so a failurefailed

    With Type=simple, systemd considers the service started as soon as it has forked, without waiting to know whether the binary runs. A typo in the path, or a forgotten copy step, therefore produces a service reported as active and a silent terminal. Type=exec waits for execve() and reports the failure.

  5. Start

    Terminal window
    sudo systemctl daemon-reload
    sudo systemctl enable node_exporter
    sudo systemctl start node_exporter
  6. Check that the exporter really answers

    An active service proves that the process is running, not that it publishes its metrics. The two commands complement each other:

    Terminal window
    systemctl is-active node_exporter
    curl -s http://localhost:9100/metrics | head -5

    The first must print active. The second must open with the two lines of metadata that Prometheus expects at the top of each metric, # HELP then # TYPE, followed by the values themselves. An empty answer or a refused connection on port 9100 means an exporter that started but does not listen, typically because of a misspelled option in ExecStart: journalctl -u node_exporter -n 20 will tell you.

Prometheus configuration

On the Prometheus side, nothing special: each server is declared as an ordinary target, with its exporter port. The job name becomes a label attached to every collected metric, and it will later be used to filter in each query, so choose an explicit one.

prometheus.yml
scrape_configs:
- job_name: 'node'
static_configs:
- targets:
- 'server1:9100'
- 'server2:9100'

Key metrics

Node Exporter publishes several hundred series; these are enough to cover everyday monitoring. Note the _total suffix, which marks a cumulative counter: its raw value is of no interest, only its change over time matters, hence the use of rate() right after.

MetricDescription
node_cpu_seconds_totalCPU time per mode (idle, user, system)
node_memory_MemAvailable_bytesAvailable memory
node_filesystem_avail_bytesAvailable disk space
node_network_receive_bytes_totalBytes received per interface
node_load1, node_load5, node_load15Load average

Useful PromQL queries

These three queries rest on the same principle: Node Exporter provides no usage percentage, you have to compute it. For the processor, you start from the time spent in idle mode and subtract it from 100; for memory and disk, you divide the available space by the total space.

# CPU used (%)
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory used (%)
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
# Disk used (%)
(1 - node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100

Blackbox Exporter (Family C, Multi-target)

Monitors availability from the outside: HTTP, DNS, TCP, ICMP. This is synthetic monitoring (probes), not internal telemetry.

Why the multi-target pattern?

Blackbox does not run on the targets it monitors. A single instance can probe hundreds of URLs, because the target is not part of its configuration: Prometheus passes it at every scrape, in the target parameter of the HTTP request.

Prometheus queries:
GET /probe?target=https://boutique.internal&module=http_2xx
Blackbox answers:
probe_success 1
probe_duration_seconds 0.234

Installation

One instance is enough for all the targets. The point to decide is not how many to deploy, but where: place it where you want to measure availability from. A probe running from the same datacenter as the service says nothing about what your users experience.

Terminal window
docker run -d \
--name blackbox_exporter \
-p 9115:9115 \
-v $(pwd)/blackbox.yml:/config/blackbox.yml:ro \
prom/blackbox-exporter:v0.28.0@sha256:e753ff9f3fc458d02cca5eddab5a77e1c175eee484a8925ac7d524f04366c2fc \
--config.file=/config/blackbox.yml

Blackbox configuration

The configuration file contains no target: it declares modules, that is ways of probing. Each module has a name that Prometheus will request at scrape time. The http_2xx module illustrates the important point: it is the valid_status_codes that decide whether the probe is a success, so a 404 correctly returned will be counted as a failure.

blackbox.yml
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: [200, 201, 204]
follow_redirects: true
tcp_connect:
prober: tcp
timeout: 5s
icmp:
prober: icmp
timeout: 5s
dns_resolve:
prober: dns
dns:
query_name: "boutique.internal"
query_type: "A"

Prometheus configuration (relabeling explained)

Relabeling turns a list of URLs into parameters for Blackbox:

prometheus.yml
scrape_configs:
- job_name: 'blackbox-http'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://boutique.internal
- https://api.boutique.internal/health
- https://docs.boutique.internal
relabel_configs:
# 1. The URL becomes the ?target= parameter
- source_labels: [__address__]
target_label: __param_target
# 2. The URL is also copied into the "instance" label
- source_labels: [__param_target]
target_label: instance
# 3. The real scrape address becomes Blackbox Exporter
- target_label: __address__
replacement: blackbox-exporter:9115

What happens:

  1. Prometheus sees https://boutique.internal in targets
  2. Relabeling turns it into GET blackbox-exporter:9115/probe?target=https://boutique.internal
  3. The instance label keeps the original URL to identify the metrics

Metrics

All probes produce the same small set of metrics, whatever the module used, which makes alerts uniform: a rule written for an HTTP probe also works for a TCP probe. The last row is an exception in two ways: it is the one people forget to watch, since it lets you be warned of a certificate expiring before the outage, and it is the only one that does not always appear.

MetricDescription
probe_success1 if the probe succeeded, 0 otherwise
probe_duration_secondsTotal probe duration
probe_http_status_codeHTTP code returned
probe_ssl_earliest_cert_expiryTLS certificate expiry date, only on an HTTPS probe

The last row deserves its caveat. Verified on Blackbox 0.28.0: a probe against an http:// URL produces no probe_ssl_earliest_cert_expiry series, whereas probe_success, probe_duration_seconds and probe_http_status_code produce one each. A certificate expiry alert set on a plain-text endpoint will therefore never fire, and this silence looks very much like "all is well".

Common alerts

These two rules cover most of what Blackbox brings. The for: 2m of the first one avoids waking someone up for a transient network incident: the expression must keep returning at least one series for two minutes in a row. The wording matters, because a PromQL comparison operator filters the vector instead of returning a boolean; the Prometheus configuration (in French) details this mechanism. The second one compares the certificate expiry date with the current time and fires thirty days before the deadline, which leaves time for a renewal.

rules/blackbox.yml
groups:
- name: blackbox
rules:
- alert: EndpointDown
expr: probe_success == 0
for: 2m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} is down"
- alert: SSLCertExpiringSoon
expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 30
for: 1h
labels:
severity: warning
annotations:
summary: "SSL cert for {{ $labels.instance }} expires in < 30 days"

Database exporters (Family B)

These exporters all work the same way: they open a connection to the engine with a dedicated account, query its internal statistics views and publish the result. Two points of vigilance follow. The account used must have the minimum privileges needed to read the statistics, never administration rights. And the connection string contains a password: it has no place in a Git repository, so pass it through an environment variable or a protected file.

MySQL Exporter

The PROCESS, REPLICATION CLIENT and SELECT privileges are enough to feed all the exposed metrics. Replace the example password before running anything.

  1. Create the MySQL user (minimum privileges)

    If the exporter runs on the same machine as MySQL, create the user for localhost:

    CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'password';
    GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
    FLUSH PRIVILEGES;

    If the exporter runs in a Docker container (variant of step 2), MySQL sees it coming from an address of the Docker network: create the user for % instead. The % accepts all addresses, so only open port 3306 to the Docker network.

    CREATE USER 'exporter'@'%' IDENTIFIED BY 'password';
    GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%';
    FLUSH PRIVILEGES;
  2. Run the exporter

    Since version 0.15.0, mysqld_exporter no longer reads the DATA_SOURCE_NAME variable. The address and the user are passed as options, the password through the MYSQLD_EXPORTER_PASSWORD variable.

    Terminal window
    export MYSQLD_EXPORTER_PASSWORD='password'
    ./mysqld_exporter \
    --mysqld.address=localhost:3306 \
    --mysqld.username=exporter

    Or with Docker. The exporter and MySQL must share a Docker network (here monitoring, adapt it), and the options go after the image:

    Terminal window
    docker run -d \
    --name mysqld_exporter \
    --network monitoring \
    -p 9104:9104 \
    -e MYSQLD_EXPORTER_PASSWORD='password' \
    prom/mysqld-exporter:v0.20.0@sha256:abed8dac117b4ae5b70757f988e44795935b9a72c3b58d720c67ba688f8cb79e \
    --mysqld.address=mysql:3306 \
    --mysqld.username=exporter

    For this variant, use the 'exporter'@'%' user from step 1. With 'exporter'@'localhost', MySQL answers Access denied.

    To check the connection, run curl -s localhost:9104/metrics | grep '^mysql_up': the value must be 1. A 0 means the exporter cannot connect to MySQL. To keep the credentials in a file, the --config.my-cnf option reads a file in .my.cnf format ([client] section) instead of the variable.

  3. Prometheus configuration

    - job_name: 'mysql'
    static_configs:
    - targets: ['localhost:9104']

Key metrics:

MetricDescription
mysql_upMySQL reachable (1/0)
mysql_global_status_threads_connectedActive connections
mysql_global_status_slow_queriesSlow queries
mysql_global_status_questionsExecuted queries

PostgreSQL Exporter

The configuration fits in a single environment variable in URI format. The sslmode=disable of the example assumes that the exporter runs on the same machine as the database; as soon as the connection crosses the network, switch to sslmode=require or stronger, otherwise the credentials travel in clear text.

Terminal window
export DATA_SOURCE_NAME='postgresql://exporter:password@localhost:5432/postgres?sslmode=disable'
./postgres_exporter

Key metrics:

MetricDescription
pg_upPostgreSQL reachable
pg_stat_activity_countConnections per state
pg_stat_database_deadlocksDeadlocks
pg_stat_database_tup_fetchedRows fetched

Redis Exporter

The instance address is passed as a command-line option. If your Redis requires a password, supply it through the environment variable provided for that purpose rather than in the command: any account on the system can read the process list, and would find it there in clear text.

Terminal window
docker run -d \
--name redis_exporter \
-p 9121:9121 \
oliver006/redis_exporter:v1.91.1@sha256:c67a432dba6b4ae30f471e3c77cf14a289133bbeeb89abb0bb03e6092efb2836 \
--redis.addr=redis://localhost:6379

Writing your own exporter

For metrics from a third-party system that no exporter covers, write one.

Python example (relay to an external API)

The official client library does all the work of the format and the HTTP serving: start_http_server opens the /metrics endpoint, and all that is left is to update the values. Watch the final loop: the refresh interval must stay lower than or equal to the Prometheus scrape_interval, otherwise Prometheus will collect the same value twice and the graph will show a plateau that does not exist.

my_exporter.py
from prometheus_client import start_http_server, Gauge
import requests
import time
# Define the metrics
ORDERS_PENDING = Gauge('orders_pending_total', 'Pending orders count')
ORDERS_VALUE = Gauge('orders_pending_value_euros', 'Value of pending orders')
def collect_metrics():
"""Collect from an external API."""
response = requests.get('https://api.internal/orders/stats')
data = response.json()
ORDERS_PENDING.set(data['pending_count'])
ORDERS_VALUE.set(data['pending_value'])
if __name__ == '__main__':
start_http_server(8000)
print("Exporter running on :8000/metrics")
while True:
collect_metrics()
time.sleep(15)

Metric types

The type is chosen at declaration and cannot be changed afterwards without breaking existing queries. The fundamental distinction opposes the Counter, which only grows and resets to zero when the process restarts, and the Gauge, which represents an instantaneous value that can go up or down.

TypeUseExample
CounterIncreasing value onlyRequests, errors
GaugeGoes up and downMemory, connections
HistogramDistribution with bucketsLatency
SummaryClient-side quantilesLatency (less recommended)

Naming conventions

A metric name is public and long-lived: renaming it breaks every dashboard and every alert that uses it. Two rules are enough: prefix with the component name and end with the unit of measure, in base units (seconds and bytes, never milliseconds or megabytes).

namespace_name_unit_suffix
  • myapp_http_requests_total: compliant
  • myapp_request_duration_seconds: compliant
  • requestCount: avoid (no namespace, no unit)

Common pitfalls

Two of these pitfalls deserve particular attention. A /metrics endpoint left open tells an attacker about your estate, versions and volumes included, without any authentication. And cardinality, that is the number of distinct label combinations, is a common cause of a saturated Prometheus: putting a user ID or a full URL in a label creates one time series per value encountered.

PitfallImpactSolution
/metrics exposed without authInformation leakFirewall, TLS, basic auth
Too many labelsCardinality explosionLow-cardinality labels only
Scrape interval too shortExporter overload15s-60s depending on criticality
Scrape timeout too shortTargets "DOWN"Adjust scrape_timeout

Troubleshooting

The first reflex is to query the /metrics endpoint by hand, from the machine that hosts Prometheus and not from your workstation: a target marked DOWN is most often so because of network filtering, and the workstation is not on the same path. If the answer arrives but the expected metrics are missing, the problem has moved to the permissions of the account used by the exporter.

SymptomLikely causeSolution
Exporter not reachableFirewall/networkcurl http://exporter:port/metrics
Empty metricsMissing permissionsCheck DB/system rights
Scrape timeoutSlow exporterIncrease scrape_timeout
Target "DOWN"DNS/networkCheck resolution + ping

Debug commands:

Terminal window
# Check the endpoint
curl -s http://localhost:9100/metrics | head -20
# Check in Prometheus
# Status → Targets
# For Blackbox, test the probe manually
curl "http://localhost:9115/probe?target=https://boutique.internal&module=http_2xx"

Key takeaways

  • 3 families: single-target (Node), service (MySQL), multi-target (Blackbox)
  • Instrumentation > Exporter if you have the code
  • Blackbox = synthetic monitoring (external availability)
  • Relabeling: essential for the multi-target pattern
  • Security: never expose /metrics without network protection
  • Type=exec in the systemd unit: a missing binary makes systemctl start fail, whereas Type=simple reports an active service
  • Metric quality: component prefix, base unit as suffix, no high-cardinality label (ID, full URL)