Prerequisites
- A Linux server to monitor
- Prometheus installed (on the same machine or elsewhere)
01Install node_exporter
Downloaded from the Prometheus site and unpacked, it runs as is and listens on port 9100. Debian and Ubuntu also ship it as a package (prometheus-node-exporter), already set up as a service.
Port 9100 should only be reachable by the Prometheus server: the metrics say a lot about the machine.
[Unit]
Description=Prometheus node_exporter
After=network-online.target
[Service]
User=node_exporter
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target02Declare it in Prometheus
global:
scrape_interval: 15s
rule_files:
- rules/*.yml
scrape_configs:
- job_name: node
static_configs:
- targets: ['192.168.20.12:9100']03Query
In the Prometheus interface, the up metric tells you for each target whether the last scrape succeeded (1) or not (0).
Two useful queries: CPU usage as a percentage, and remaining disk space.
# CPU used, in %, averaged over 5 minutes
100 * (1 - avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])))
# Free space on the root filesystem, in %
100 * node_filesystem_avail_bytes{mountpoint="/"} / node_filesystem_size_bytes{mountpoint="/"}04The first alert
for: 2m avoids alerting on a single missed scrape. promtool checks the file before reloading Prometheus; Alertmanager then takes care of sending the notification.
groups:
- name: availability
rules:
- alert: TargetDown
expr: up == 0
for: 2m
labels:
severity: critical
annotations:
summary: "{{ $labels.instance }} is not responding"05Next steps
Grafana for dashboards, Alertmanager to route alerts, and snmp_exporter for network equipment that can’t run an agent.
promtool check rules rules/availability.yml
curl -X POST http://localhost:9090/-/reload # if --web.enable-lifecycleKey takeaways
- node_exporter: port 9100, reachable by Prometheus only.
- One target per job in prometheus.yml.
- up == 0 for 2 minutes: the first alert to write.
- promtool check before every reload.
Example addresses.