Sub topic 5
Exposing Linux Host Metrics with node_exporter
Assume you are comfortable with the Linux command line, systemd, TCP ports, and basic server resources. You should also know how to edit a file with sudo.
What node_exporter does
node_exporter is a Prometheus exporter for Linux host metrics. An exporter is a service that reads system information and exposes it over HTTP in a format Prometheus can scrape.
It reports metrics such as:
| Metric area | Example information |
|---|---|
| CPU | Time spent idle or running |
| Memory | Total, available, and used memory |
| Filesystems | Size and free space by mount point |
| Network | Bytes and packets sent or received |
By default, node_exporter listens on TCP port 9100. Requesting /metrics returns plain text containing metric names, values, labels, and help text.
Install and expose the exporter
Obtain the node_exporter binary that matches your server's operating system and CPU architecture. Place it in /usr/local/bin, then create a dedicated system user. A dedicated user limits the damage if the exporter is compromised.
sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter
sudo install -m 0755 node_exporter /usr/local/bin/node_exporter
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporterCreate /etc/systemd/system/node_exporter.service:
[Unit]
Description=Prometheus Node Exporter
After=network-online.target
Wants=network-online.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.targetLoad the unit, start the service, and enable it for future boots:
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
sudo systemctl status node_exporterRestart=on-failure asks systemd to restart the process when it exits unexpectedly. The exporter runs as node_exporter, rather than as root.
Verify the metrics endpoint
Test the endpoint locally:
curl http://127.0.0.1:9100/metricsYou should see lines such as:
# HELP node_memory_MemAvailable_bytes Memory information field MemAvailable_bytes.
# TYPE node_memory_MemAvailable_bytes gauge
node_memory_MemAvailable_bytes 1.23456768e+09A gauge represents a value that can rise or fall. The later Prometheus configuration will scrape this endpoint and add an instance label that identifies the server.
Network access and security
Prometheus must be able to reach port 9100 on each monitored server. Allow that port only from the Prometheus server's address in your firewall. Do not expose the metrics endpoint publicly. The endpoint can reveal hostnames, mount points, device names, and resource details.
If the service fails, inspect its logs:
sudo journalctl -u node_exporter --since "10 minutes ago"Exercise
What command confirms that node_exporter is listening locally, and what URL should Prometheus scrape?
Show answer
Run curl http://127.0.0.1:9100/metrics; Prometheus should scrape http://server-address:9100/metrics.