# 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.

URL: https://levelrail.com/learn/monitoring/prometheus-and-node-exporter-basics/
Updated: 2026-11-27

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](https://levelrail.com/learn/monitoring/what-to-monitor-first/)).

## Step 1: Run node_exporter

On the server to monitor, install the packaged exporter:

```bash
sudo apt update
sudo apt install prometheus-node-exporter
systemctl status prometheus-node-exporter
curl -s http://127.0.0.1:9100/metrics | head
```

The Debian and Ubuntu package runs it as a [systemd](https://levelrail.com/learn/glossary/#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](https://levelrail.com/learn/server-basics/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`:

```text
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

```bash
sudo apt install prometheus
```

Edit `/etc/prometheus/prometheus.yml` to a minimal config:

```yaml
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

```bash
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl restart prometheus
```

`promtool` 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:

```bash
ssh -L 9090:127.0.0.1:9090 deploy@203.0.113.10
```

Each 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](https://levelrail.com/learn/docker/publish-container-ports-safely/)) for the equivalent rule with containers.

## Step 5: First PromQL queries

In the expression browser at `/graph`, try:

```text
up
rate(node_cpu_seconds_total{mode="idle"}[5m])
node_filesystem_avail_bytes{mountpoint="/"}
node_memory_MemAvailable_bytes
```

`up` 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](https://levelrail.com/learn/monitoring/grafana-dashboards-for-cpu-memory-disk/)).

## Check it worked

- `curl -s http://127.0.0.1:9100/metrics | grep node_load1` prints a value.
- `promtool check config` ends with `SUCCESS`.
- The targets page lists both jobs as `UP`.
- The query `up` returns 1 for each job.
- From another machine, `curl --max-time 5 http://203.0.113.10:9100/metrics` fails, 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](https://levelrail.com/learn/server-basics/set-up-a-firewall-with-ufw/)).
- **Counters need rate.** Graphing a raw counter shows a line that only rises. Wrap it in `rate()` or `increase()`.
- **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](https://levelrail.com/learn/troubleshooting/fix-port-already-in-use/)) |

## Quick reference

```bash
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 | head
```

```text
up
rate(node_cpu_seconds_total{mode="idle"}[5m])
node_filesystem_avail_bytes{mountpoint="/"}
```

## Related lessons

- [What to monitor first](https://levelrail.com/learn/monitoring/what-to-monitor-first/)): which metrics deserve a graph.
- [Grafana dashboards for CPU, memory and disk](https://levelrail.com/learn/monitoring/grafana-dashboards-for-cpu-memory-disk/)): turn these queries into panels.
- [Disk, memory and CPU alerts that matter](https://levelrail.com/learn/monitoring/disk-memory-and-cpu-alerts-that-matter/)): alert on these metrics.
- [Container metrics with cAdvisor and docker stats](https://levelrail.com/learn/monitoring/container-metrics-with-cadvisor-and-docker-stats/)): add containers as a second target.
- [Check disk, memory and CPU usage](https://levelrail.com/learn/server-basics/check-disk-memory-and-cpu-usage/)): the command-line equivalents.

## Next

Make the numbers visible in [Grafana dashboards for CPU, memory and disk](https://levelrail.com/learn/monitoring/grafana-dashboards-for-cpu-memory-disk/)).

## 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

- [Prometheus documentation](https://prometheus.io/docs/introduction/overview/)
- [Prometheus configuration](https://prometheus.io/docs/prometheus/latest/configuration/configuration/)
- [Node exporter guide](https://prometheus.io/docs/guides/node-exporter/)
