هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Node Exporter reads /proc and /sys and shows the values as text on http://SERVER:9100/metrics. Prometheus scrapes that page every 15–30 seconds. Collectors decide which groups of metrics are shown.
| Item | Value |
|---|---|
| Ubuntu package | prometheus-node-exporter (service prometheus-node-exporter) |
| Release file | node_exporter from github.com/prometheus/node_exporter/releases (works on RHEL and Ubuntu) |
| Port | 9100/tcp |
| Flags | in the service file (or /etc/default/prometheus-node-exporter on Ubuntu) |
| Textfile folder | for example /var/lib/node_exporter/textfile/ |
| Runs as | a system user without login |
Install on RHEL, Rocky, Alma and Fedora
Use the official release file (choose the version from the releases page):
useradd --system --no-create-home --shell /sbin/nologin node_exporter
NVER=1.9.1
curl -fsSLO https://github.com/prometheus/node_exporter/releases/download/v$NVER/node_exporter-$NVER.linux-amd64.tar.gz
curl -fsSLO https://github.com/prometheus/node_exporter/releases/download/v$NVER/sha256sums.txt
sha256sum -c --ignore-missing sha256sums.txt
node_exporter-1.9.1.linux-amd64.tar.gz: OK
tar -xzf node_exporter-$NVER.linux-amd64.tar.gz
install -m 0755 node_exporter-$NVER.linux-amd64/node_exporter /usr/local/bin/
mkdir -p /var/lib/node_exporter/textfile /etc/node_exporter[Unit]
Description=Prometheus Node Exporter
After=network-online.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter \
--collector.systemd \
--collector.processes \
--collector.textfile.directory=/var/lib/node_exporter/textfile \
--collector.filesystem.mount-points-exclude='^/(dev|proc|run|sys|var/lib/docker/.+|var/lib/containers/.+)($|/)' \
--web.config.file=/etc/node_exporter/web.yml
Restart=on-failure
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=read-only
[Install]
WantedBy=multi-user.target(Remove the --web.config.file line until you made that file — see "Make it safe".)
Install on Ubuntu and Debian
The package is the quick way; it is a bit older than the release file:
apt-get update
apt-get install -y prometheus-node-exporter
systemctl status prometheus-node-exporter --no-pagerAdd flags in /etc/default/prometheus-node-exporter (ARGS="--collector.systemd …") and restart. Or use the release file and service above — the same on all distributions.
First configuration: collectors and firewall
Check the page, then open the port only for the Prometheus server:
curl -s http://localhost:9100/metrics | grep -E '^node_(load1|memory_MemAvailable_bytes|filesystem_avail_bytes\{.*mountpoint="/")'
firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="10.0.0.5/32" port port="9100" protocol="tcp" accept'
firewall-cmd --reload
ufw allow from 10.0.0.5 to any port 9100 proto tcp| Flag | Why |
|---|---|
--collector.systemd | State of every systemd unit (alert when nginx.service fails). |
--collector.processes | Process and thread counts. |
--collector.textfile.directory | Your own metrics from scripts (below). |
--collector.filesystem.mount-points-exclude | No noise from container and virtual file systems. |
--no-collector.<name> | Turn off a collector you do not need (for example --no-collector.wifi). |
Your own metrics: the textfile collector
A script writes a .prom file; Node Exporter shows it. Example: report the backup result at the end of the nightly backup script:
cat > /usr/local/bin/backup-metric.sh <<'EOF'
#!/bin/sh
F=/var/lib/node_exporter/textfile/backup.prom
echo "# HELP backup_last_success_timestamp_seconds Last successful backup." > $F.tmp
echo "# TYPE backup_last_success_timestamp_seconds gauge" >> $F.tmp
echo "backup_last_success_timestamp_seconds $(date +%s)" >> $F.tmp
mv $F.tmp $F
EOF
chmod 755 /usr/local/bin/backup-metric.sh
/usr/local/bin/backup-metric.sh
curl -s localhost:9100/metrics | grep backup_last
backup_last_success_timestamp_seconds 1.7949e+09Write to a .tmp file and mv it, so Node Exporter never reads half a file. Alert when the backup is older than 26 hours: time() - backup_last_success_timestamp_seconds > 26*3600.
Daily use: the queries and the first alerts
100 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100
(1 - node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100
100 * node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes
predict_linear(node_filesystem_avail_bytes{mountpoint="/"}[6h], 24*3600) < 0
rate(node_disk_io_time_seconds_total[5m])
node_load15 / count by (instance) (node_cpu_seconds_total{mode="idle"})
node_systemd_unit_state{state="failed"} == 1
rate(node_network_receive_errs_total[5m]) > 0Real uses at work:
- The base of every server dashboard (Grafana dashboard 1860 "Node Exporter Full").
- Alerts: disk will be full in 24 hours, a systemd unit failed, memory pressure, server down (
up == 0). - Your own checks: backup age, certificate days, pending updates — with the textfile collector.
Make it safe
The metrics page shows a lot about the server (users of processes, mounts, versions). Protect it with TLS and a password:
tls_server_config:
cert_file: /etc/node_exporter/node.crt
key_file: /etc/node_exporter/node.key
basic_auth_users:
prometheus: $2y$12$Zq…In Prometheus, add scheme: https, basic_auth and tls_config.ca_file to the job.
Security checklist:
- Port 9100 only from the Prometheus server (firewall).
- TLS and basic auth with
--web.config.fileon untrusted networks. - Run as its own user; the systemd hardening options above.
- Textfile folder writable only by root and your scripts.
- Update with new releases.
Update and remove
systemctl stop node_exporter
install -m 0755 node_exporter-1.9.2.linux-amd64/node_exporter /usr/local/bin/
systemctl start node_exporter
apt-get install --only-upgrade -y prometheus-node-exporter
systemctl disable --now node_exporter && rm /usr/local/bin/node_exporter /etc/systemd/system/node_exporter.serviceFix common problems
| Problem | Cause | Fix |
|---|---|---|
Target DOWN: context deadline exceeded | Firewall drops 9100. | Open 9100 for the Prometheus IP. |
Target DOWN: connection refused | Service not running or another port. | systemctl status node_exporter; ss -ltnp | grep 9100. |
server returned HTTP status 401 Unauthorized | Basic auth set, Prometheus has no password. | Add basic_auth to the scrape job. |
textfile: failed to read …: invalid metric in the log | Bad format in a .prom file. | Check the file; promtool check metrics < file.prom. |
No node_systemd_* metrics | The systemd collector is off or has no D-Bus access. | Add --collector.systemd; do not block D-Bus in hardening. |
| Too many filesystem series | Container overlay mounts. | Use --collector.filesystem.mount-points-exclude (above). |
Service fails to start: bind: address already in use | Two exporters (package + release file). | Keep one; remove the other. |
Next steps
- Quick how-to: Monitor a Linux server with Prometheus.
- Command page: node_exporter, Command page: promtool.
- The server that scrapes it: Install and set up Prometheus. The dashboards: Grafana. The alerts: Alertmanager.
- Practise the stack: Lab: Prometheus, node exporter, Alertmanager and Grafana.
- At work: Linux host metrics.
1How do you show your own value (for example the last backup time) in Prometheus without writing an exporter?
Write it to a .prom file in the textfile collector folder.
2Which query finds systemd services that failed?
node_systemd_unit_state{state="failed"} == 1.