Stage 6 · Operate
Metrics with Prometheus
node_exporter
Collecting CPU, memory, disk, filesystem, and network metrics from Linux hosts.
What node_exporter Collects
node_exporter is the standard Prometheus exporter for hardware and OS-level metrics on Linux. It reads from /proc and /sys to expose CPU, memory, disk, filesystem, network, and system load metrics. It is the foundation of infrastructure monitoring.
node_cpu_seconds_total
node_memory_MemAvailable_bytes
node_filesystem_avail_bytes
node_disk_read_bytes_total
node_network_receive_bytes_total
node_load1Installation
The recommended installation method uses the Prometheus community's binary releases. Download the archive, extract it, and run the binary with appropriate flags.
wget https://github.com/prometheus/node_exporter/releases/download/v1.7.0/node_exporter-1.7.0.linux-amd64.tar.gz
tar xvf node_exporter-1.7.0.linux-amd64.tar.gz
cd node_exporter-1.7.0.linux-amd64
./node_exporter --web.listen-address=":9100"Run node_exporter as a non-root user with a dedicated system account. Only grant access to the metrics port. Never run exporters as root in production.
Key Metrics
Understanding the key metrics enables you to build useful dashboards and alerts. Each metric category maps to a specific resource dimension.
# CPU utilization percentage
100 - (avg by(instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory utilization percentage
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
# Disk space utilization percentage
(1 - node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100
# Network receive rate in bytes per second
rate(node_network_receive_bytes_total{device="eth0"}[5m])Textfile Collector
The textfile collector lets you expose custom metrics by writing files to a directory. This is useful for scripts, cron jobs, or programs that cannot run an HTTP server but need to report metrics to Prometheus.
#!/bin/bash
# Write a metric to the textfile collector directory
DIR="/var/lib/node_exporter/textfile_collector"
echo "backup_last_success_timestamp $(date +%s)" > "$DIR/backup.prom"
echo "backup_last_success_timestamp_seconds $(date +%s)" > "$DIR/backup.prom"
# Validate with promtool
promtool check metrics < "$DIR/backup.prom"Hardening and Tuning
Disable collectors you do not need to reduce overhead. Each collector reads from /proc or /sys and adds to scrape time. Disable unused collectors to speed up scrapes and reduce resource usage.
./node_exporter \
--no-collector.infiniband \
--no-collector.nfs \
--no-collector.nfsd \
--no-collector.mdadm \
--no-collector.tapestats \
--web.listen-address=":9100"node_exporter reveals detailed system information. Exposing it to untrusted networks is a security risk. Use firewall rules, VPN, or Prometheus service discovery within a private network.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.