How to Install, Configure, and Monitor Node Exporter with Prometheus
This guide walks through installing the Go‑based Node Exporter, configuring it as a systemd service or Docker container, exposing standard Prometheus metrics, and using PromQL to calculate CPU usage across multiple nodes.
Node Exporter is a Go‑written exporter that exposes *NIX host metrics such as CPU, memory, and disk without any third‑party dependencies; you only need to download, extract, and run the binary.
Installation and Configuration
Download the tarball from the Prometheus download page, extract it, and run the
node_exporterbinary:
<code>wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
# Optional fast download for China
# wget https://download.fastgit.org/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz
tar -xvf node_exporter-1.2.2.linux-amd64.tar.gz
cd node_exporter-1.2.2.linux-amd64
./node_exporter</code>The log shows that Node Exporter listens on port 9100 and serves metrics at the
/metricsendpoint, which can be accessed with:
<code>curl http://localhost:9100/metrics</code>The output follows the standard Prometheus exposition format, ready to be scraped by Prometheus.
Run
./node_exporter -hto see all configurable flags. The most important flag is
--collector.<name>, which enables specific metric collectors. Use
--no-collector.<name>to disable defaults, or
--collector.disable-defaultsfollowed by explicit
--collector.<name>entries.
For production, you can run Node Exporter in a Docker container (remember to grant access to the host’s namespaces) or manage it with systemd. Below is a typical systemd unit file:
<code>[Unit]
Description=node exporter service
Documentation=https://prometheus.io
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target</code>After placing the binary in
/usr/local/bin, reload the daemon and start the service:
<code>cp node_exporter /usr/local/bin/node_exporter
systemctl daemon-reload
systemctl start node_exporter
systemctl status node_exporter</code>Add a static scrape job for the two nodes in Prometheus configuration:
<code>global:
scrape_interval: 5s
scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: "demo"
scrape_interval: 15s
scrape_timeout: 10s
static_configs:
- targets: ["localhost:10000", "localhost:10001", "localhost:10002"]
- job_name: "node_exporter"
static_configs:
- targets: ["node1:9100", "node2:9100"]</code>CPU Monitoring
The metric
node_cpu_seconds_totalrecords the cumulative CPU time spent in each mode (idle, user, system, etc.) as a counter. Sample output shows values for each CPU core and mode.
To derive CPU usage percentage, calculate the proportion of time not spent in the
idlemode. Using PromQL, first get the increase of idle time over a 1‑minute window, then compute the ratio against the total CPU time:
<code>(1 - sum(increase(node_cpu_seconds_total{mode="idle"}[1m])) by (instance) / sum(increase(node_cpu_seconds_total[1m])) by (instance)) * 100</code>This expression yields the CPU utilization per instance, comparable to the percentages shown by the
topcommand.
Further node‑level metrics such as memory and I/O will be covered in upcoming articles.
Ops Development Stories
Maintained by a like‑minded team, covering both operations and development. Topics span Linux ops, DevOps toolchain, Kubernetes containerization, monitoring, log collection, network security, and Python or Go development. Team members: Qiao Ke, wanger, Dong Ge, Su Xin, Hua Zai, Zheng Ge, Teacher Xia.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.