Prometheus and node_exporter basics for a Linux server
Prometheus pulls metrics over HTTP from exporters such as node_exporter on port 9100, stores them as time series and lets you query them with PromQL.
- Updated Nov 27, 2026
- Markdown
Run node_exporter, scrape it from Prometheus, validate the config and write your first PromQL queries.
- An Ubuntu or Debian server with sudo
- Basic familiarity with YAML and systemd
How Prometheus and Grafana work together
- Prometheus pulls the /metrics page from node_exporter on a fixed interval.
- node_exporter answers with current CPU, memory, disk and network numbers as text.
- Grafana sends PromQL queries to Prometheus for each panel on a dashboard.
- You see the stored time series as graphs, and Prometheus keeps the history.
Static diagram
- Prometheusscrapenode_exporter
- node_exportermetricsPrometheus
- GrafanaPromQLPrometheus
- GrafanadashboardYou
Prometheus is a metrics database that pulls numbers from small HTTP endpoints called exporters. On a Linux server, node_exporter listens on port 9100 and publishes CPU, memory, disk and network figures. You tell Prometheus where to scrape in prometheus.yml, validate it with promtool check config, confirm the target is up, and then query it with PromQL.
How it works#
Prometheus uses a pull model. Every scrape interval it sends an HTTP request to each target’s /metrics page, parses the text and stores the values with a timestamp. Because Prometheus initiates the request, a dead target is obvious: the scrape fails and the built-in up metric for it becomes 0.
Metrics have names and labels, for example node_filesystem_avail_bytes{mountpoint="/"}. Counters such as node_cpu_seconds_total only increase, so you apply rate() to get a per-second value. Gauges such as available bytes go up and down, so you read them directly. The picture in the diagram above shows the flow: exporter, Prometheus, then Grafana for graphs, which is the next lessons’ topic. For which numbers matter first, see what to monitor first.
Step 1: Run node_exporter#
On the server to monitor, install the packaged exporter:
sudo apt update
sudo apt install prometheus-node-exporter
systemctl status prometheus-node-exporter
curl -s http://127.0.0.1:9100/metrics | headThe Debian and Ubuntu package runs it as a systemd service. The last command prints plain text lines starting with # HELP and # TYPE. Alternatively you can download a release binary from the Prometheus project and write your own unit; the package is simpler. See run a service with systemd if you go that route.
By default it listens on all interfaces. If Prometheus runs on the same host, restrict it to localhost by setting the listen address in /etc/default/prometheus-node-exporter:
ARGS="--web.listen-address=127.0.0.1:9100"Then sudo systemctl restart prometheus-node-exporter. If Prometheus is on another machine, bind to a private address and allow only that machine in the firewall.
Step 2: Install Prometheus and configure a scrape#
sudo apt install prometheusEdit /etc/prometheus/prometheus.yml to a minimal config:
global:
scrape_interval: 15s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ["127.0.0.1:9090"]
- job_name: node
static_configs:
- targets: ["127.0.0.1:9100"]Each job_name groups targets, and static_configs lists addresses. For more servers, add their private addresses to the node targets list. The packaged install may already include a similar file, so edit rather than replace blindly, and keep a copy of the original.
Step 3: Validate and reload#
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheuspromtool prints SUCCESS if the file parses. Always validate before restarting, because a syntax error can leave Prometheus down. A configured reload without a restart is possible when the web lifecycle option is on, but a restart is fine on a small box.
Step 4: Check the targets page#
Open http://127.0.0.1:9090/targets, through an SSH tunnel if the server is remote:
ssh -L 9090:127.0.0.1:9090 deploy@203.0.113.10Each target shows UP or DOWN with the last error. A target in DOWN with connection refused means nothing listens at that address. Port 9090 and 9100 expose detailed data without authentication, so never publish them to the internet. See publish container ports safely for the equivalent rule with containers.
Step 5: First PromQL queries#
In the expression browser at /graph, try:
up
rate(node_cpu_seconds_total{mode="idle"}[5m])
node_filesystem_avail_bytes{mountpoint="/"}
node_memory_MemAvailable_bytesup lists every target with 1 or 0. The rate(...) query gives idle CPU seconds per second for each core, so a value near 1 means that core is idle. Disk space on / is in bytes, and memory available is the number that matters for memory pressure, since free memory alone ignores reclaimable cache. Divide to get percentages, which the next lesson uses in Grafana dashboards for CPU, memory and disk.
Check it worked#
curl -s http://127.0.0.1:9100/metrics | grep node_load1prints a value.promtool check configends withSUCCESS.- The targets page lists both jobs as
UP. - The query
upreturns 1 for each job. - From another machine,
curl --max-time 5 http://203.0.113.10:9100/metricsfails, which is what you want.
Edge cases and gotchas#
- Public exposure. Prometheus and exporters have no login by default. Bind to localhost or a private address and use the firewall. See set up a firewall with ufw.
- Counters need rate. Graphing a raw counter shows a line that only rises. Wrap it in
rate()orincrease(). - Retention fills the disk. Prometheus keeps data on local disk for a limited period. Watch its data directory and set retention with its startup flags.
- Scrape interval versus rate window. The window in
rate(x[5m])should cover several scrapes. A window shorter than two scrape intervals returns nothing. - Containers hide the host. node_exporter inside a container sees the container’s view unless you configure host mounts. Run it on the host for host metrics.
- Clock skew. Wrong server time makes graphs look gappy. Keep time sync enabled.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Target shows connection refused | Exporter not running or wrong port | systemctl status prometheus-node-exporter and check the address |
Target shows context deadline exceeded | Network blocked or exporter slow | Test with curl --max-time 5 from the Prometheus host |
promtool: command not found | Tool not on PATH | Use the full path or install the prometheus package |
yaml: unmarshal errors | Indentation or a wrong key | Fix the line reported by promtool check config |
Query returns No data | Metric name wrong or no scrape yet | Autocomplete the name and wait one interval |
| Prometheus will not start | Invalid config or permissions | journalctl -u prometheus -n 50 |
| Graph has gaps | Target down or scrape too slow | Check up over time |
bind: address already in use on 9100 | Another exporter running | See fix port already in use |
Quick reference#
sudo apt install prometheus prometheus-node-exporter
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
curl -s http://127.0.0.1:9100/metrics | headup
rate(node_cpu_seconds_total{mode="idle"}[5m])
node_filesystem_avail_bytes{mountpoint="/"}Related lessons#
- What to monitor first: which metrics deserve a graph.
- Grafana dashboards for CPU, memory and disk: turn these queries into panels.
- Disk, memory and CPU alerts that matter: alert on these metrics.
- Container metrics with cAdvisor and docker stats: add containers as a second target.
- Check disk, memory and CPU usage: the command-line equivalents.
Next#
Make the numbers visible in Grafana dashboards for CPU, memory and disk.
Check what you learned
Frequently asked questions
What does it mean that Prometheus uses a pull model?
Prometheus fetches metrics from each target on a schedule, by requesting an HTTP page such as /metrics. Targets do not push. A target that stops answering shows up as down.
What port does node_exporter use?
Port 9100 by default. Prometheus itself uses 9090. Neither should be reachable from the public internet.
How do I check my Prometheus config for errors?
Run promtool check config /etc/prometheus/prometheus.yml. It parses the file and reports problems before you reload Prometheus.
What does up mean in PromQL?
up is a metric Prometheus records for every target. It is 1 when the last scrape worked and 0 when it failed, so up == 0 finds broken targets.
Sources
Keep going: guides and tutorials
- Our Health Check Failed and the Deploy Went Live Anyway A postmortem from our own dogfood run: a failed readiness probe still received traffic. What broke, why two correct parts added up to a bug, and the fix.
- Zero Downtime Deploy for Docker Apps, With Rollback How a Docker deploy waits for readiness before cutover, holds the previous release for rollback, rolls back on its own, and how to rehearse it.