Skip to content

Deploying node_exporter for host metrics that actually help during an incident

A reproducible node_exporter install on Ubuntu with the right collectors enabled, textfile collector wired in, and the labels that make a CPU spike attributable to a host you can find.

node_exporter is the small Go binary that turns a Linux host into a Prometheus scrape target. Most teams install it once, accept the default collector set, and never come back to it — then six months later an incident lands and the metric they need (a smartmon counter, a NTP offset, a filesystem-level inode pressure) is not being collected. This article walks through a deliberate install: a pinned binary, a hardened systemd unit, the collectors you actually want enabled, and the textfile-collector pattern for bolting on metrics the binary does not natively produce.

How to verify

After install, the exporter should be reachable on 127.0.0.1:9100/metrics and serve a few thousand series, including the collectors you turned on.

systemctl status node_exporter --no-pager
ss -lntp | grep 9100
curl -fsS http://127.0.0.1:9100/metrics | grep '^node_exporter_build_info'
curl -fsS http://127.0.0.1:9100/metrics | grep -E '^# HELP node_(cpu|memory|filesystem|netdev|systemd|textfile)' | head -20
curl -fsS http://127.0.0.1:9100/metrics | wc -l

A baseline Ubuntu host with the default collector set returns around 1,500–3,000 sample lines. If you see fewer than 500, a collector failed to load — check journalctl -u node_exporter -n 100 for couldn't load collector lines.

What’s happening

node_exporter is a single binary with about 40 built-in collectors, each pulling from a /proc or /sys interface, a syscall, or a Linux subsystem. Some collectors are on by default (cpu, meminfo, filesystem, netdev); some you have to enable explicitly (systemd, processes, interrupts, mountstats); some are heavy and you usually want off (tcpstat, wifi). The flags are --collector.NAME to enable and --no-collector.NAME to disable.

Two things matter for production. First, your scrape target needs a stable instance label — typically the hostname or a private IP — so a CPU spike on a dashboard can be traced back to a host you can SSH into. Second, the textfile collector reads *.prom files from a directory and exposes them as metrics; this is how you ship metrics that node_exporter does not natively produce (last-backup timestamp, certificate expiry, custom health probe results) without writing a full exporter.

The procedure

  1. Create a system user and download the pinned binary.

    sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter
    NE_VERSION="1.8.2"
    cd /tmp
    curl -fLO "https://github.com/prometheus/node_exporter/releases/download/v${NE_VERSION}/node_exporter-${NE_VERSION}.linux-amd64.tar.gz"
    tar xzf node_exporter-${NE_VERSION}.linux-amd64.tar.gz
    sudo install -m 0755 node_exporter-${NE_VERSION}.linux-amd64/node_exporter /usr/local/bin/node_exporter
    sudo mkdir -p /var/lib/node_exporter/textfile
    sudo chown -R node_exporter:node_exporter /var/lib/node_exporter
  2. Write the systemd unit with the collector flags you actually want.

    # /etc/systemd/system/node_exporter.service
    [Unit]
    Description=Prometheus node_exporter
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    Type=simple
    User=node_exporter
    Group=node_exporter
    ExecStart=/usr/local/bin/node_exporter \
      --web.listen-address=127.0.0.1:9100 \
      --collector.systemd \
      --collector.systemd.unit-include=^(nginx|postgresql|prometheus|sshd|cron|chrony).*\.service$ \
      --collector.processes \
      --collector.interrupts \
      --collector.mountstats \
      --collector.textfile.directory=/var/lib/node_exporter/textfile \
      --no-collector.wifi \
      --no-collector.hwmon
    Restart=on-failure
    RestartSec=5s
    LimitNOFILE=65536
    NoNewPrivileges=true
    ProtectSystem=full
    ProtectHome=true
    ReadOnlyPaths=/proc /sys
    ReadWritePaths=/var/lib/node_exporter
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    The unit-include regex keeps the systemd collector cardinality bounded — without it you get one set of series per systemd unit on the box, which can be hundreds.

  3. Bind to localhost, scrape over the internal network. The exporter has no auth. Either bind to a private interface (--web.listen-address=10.0.0.5:9100) and rely on a firewall (UFW or security groups), or bind to 127.0.0.1 and have Prometheus reach it through a same-VPC sidecar. We default to the latter for hosts that are not on a flat private network.

  4. Add the scrape job to Prometheus. Use file-based service discovery if you have more than a handful of hosts.

    # /etc/prometheus/prometheus.yml
    scrape_configs:
      - job_name: 'node'
        file_sd_configs:
          - files: ['/etc/prometheus/targets/nodes/*.json']
            refresh_interval: 30s
        relabel_configs:
          - source_labels: [__address__]
            regex: '([^:]+):.*'
            target_label: instance
    // /etc/prometheus/targets/nodes/prod-web.json
    [
      {
        "targets": ["web01.internal:9100", "web02.internal:9100"],
        "labels": { "env": "prod", "tier": "web", "region": "ca-central-1" }
      }
    ]
  5. Wire the textfile collector. Drop a .prom file into /var/lib/node_exporter/textfile/ and the exporter will read it on every scrape. Example for a backup script:

    # End of nightly backup script:
    cat > /var/lib/node_exporter/textfile/backup.prom.$$ <<EOF
    # HELP backup_last_success_timestamp_seconds Unix epoch of last successful backup
    # TYPE backup_last_success_timestamp_seconds gauge
    backup_last_success_timestamp_seconds{job="db-nightly"} $(date +%s)
    backup_last_size_bytes{job="db-nightly"} ${BACKUP_BYTES}
    EOF
    mv /var/lib/node_exporter/textfile/backup.prom.$$ /var/lib/node_exporter/textfile/backup.prom

    The atomic rename matters — node_exporter reads files mid-write otherwise and emits parse errors.

  6. Enable and verify. sudo systemctl daemon-reload && sudo systemctl enable --now node_exporter. Then check the Prometheus targets page; the node job should show every host as UP, with a scrape duration well under one second.

Common pitfalls

  • Leaving the systemd collector unfiltered on a host with hundreds of .scope units; cardinality explodes and your TSDB grows out from under you.
  • Writing textfile metrics directly without an atomic rename, producing intermittent parse error warnings in node_exporter logs.
  • Forgetting node_filesystem_avail_bytes excludes tmpfs by default in some dashboards — your filesystem alerting may miss a full /var/log on a host that mounts it as a tmpfs.
  • Binding to 0.0.0.0 on a host with a public IP; the /metrics endpoint leaks process lists, mount points, and uptime to anyone who can reach it.
  • Running an old node_exporter version with new Prometheus dashboards; metric names changed between 0.x and 1.x and some Grafana dashboards expect the old names.

For the dashboards that consume these metrics, see grafana-dashboards-scratch. For alerts that fire off them, see prometheus-alerting-rules.


Stack Harbor installs node_exporter as part of the baseline image we maintain for clients in our managed operations tier — collector set audited, textfile collector wired into the backup and cert-renewal scripts, scrape cardinality kept inside a budget.