Log inSign up

Collect server metrics with Prometheus and node_exporter

Download the current Prometheus and node_exporter release binaries, copy them to /usr/local/bin, create system users and run both as systemd services listening on 127.0.0.1. Prometheus then scrapes 127.0.0.1:9100 every 30 seconds and answers PromQL queries on port 9090. Remote servers reached over public IPs get node_exporter with TLS, basic auth and a firewall rule that admits only the Prometheus address.

Topic: Monitoring and logs · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

How do Prometheus and node_exporter fit together?

Prometheus is a time series database that pulls metrics over HTTP, and node_exporter is the small agent that turns Linux kernel statistics into those metrics. Every scrape interval, Prometheus fetches /metrics from each target, stores the samples on disk and makes them searchable with the PromQL query language. node_exporter reports CPU time per mode, load, memory, filesystems, disk I/O, network counters, systemd unit states and more.

Prometheus has only a basic graph view, so most people add Grafana for dashboards. The pair complements the Usage graphs tab in the console: the console shows the outside view of each instance, while Prometheus keeps detailed inside metrics for as long as you choose.

Why use the release binaries instead of distro packages?

Ubuntu and Debian ship Prometheus packages, but they track older 2.x releases, and Rocky Linux and AlmaLinux have no package in the base repositories. The upstream binaries are statically built Go programs that run on every distribution, so one method covers all four systems and gives you the current 3.x line. If you prefer packages on Ubuntu or Debian, apt policy prometheus prometheus-node-exporter shows which versions your release offers.

Prepare a sudo user and the download tools:

# Ubuntu and Debian
sudo apt update && sudo apt install -y curl tar

# Rocky Linux and AlmaLinux
sudo dnf install -y curl tar

How do I install node_exporter?

Look up the latest version from the project releases, download the archive for amd64, and install the single binary:

NE_VER=$(curl -s https://api.github.com/repos/prometheus/node_exporter/releases/latest | grep -oP '"tag_name": "v\K[^"]+')
echo "$NE_VER"
cd /tmp
curl -LO "https://github.com/prometheus/node_exporter/releases/download/v${NE_VER}/node_exporter-${NE_VER}.linux-amd64.tar.gz"
tar xzf "node_exporter-${NE_VER}.linux-amd64.tar.gz"
sudo install -m 0755 "node_exporter-${NE_VER}.linux-amd64/node_exporter" /usr/local/bin/
sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter
node_exporter --version

Create /etc/systemd/system/node_exporter.service:

[Unit]
Description=Prometheus node_exporter
Wants=network-online.target
After=network-online.target

[Service]
User=node_exporter
Group=node_exporter
ExecStart=/usr/local/bin/node_exporter --web.listen-address=127.0.0.1:9100 --collector.systemd
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
curl -s http://127.0.0.1:9100/metrics | grep ^node_load

Three node_load lines prove that metrics are flowing.

How do I install Prometheus?

The steps mirror node_exporter, with a config folder and a data folder added:

PROM_VER=$(curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep -oP '"tag_name": "v\K[^"]+')
cd /tmp
curl -LO "https://github.com/prometheus/prometheus/releases/download/v${PROM_VER}/prometheus-${PROM_VER}.linux-amd64.tar.gz"
tar xzf "prometheus-${PROM_VER}.linux-amd64.tar.gz"
sudo install -m 0755 "prometheus-${PROM_VER}.linux-amd64/prometheus" "prometheus-${PROM_VER}.linux-amd64/promtool" /usr/local/bin/
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus
sudo mkdir -p /etc/prometheus /var/lib/prometheus
sudo chown prometheus:prometheus /var/lib/prometheus
prometheus --version

Write /etc/prometheus/prometheus.yml:

global:
  scrape_interval: 30s
  evaluation_interval: 30s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ["127.0.0.1:9090"]
  - job_name: node
    static_configs:
      - targets: ["127.0.0.1:9100"]
        labels:
          host: monitor

Then create /etc/systemd/system/prometheus.service:

[Unit]
Description=Prometheus
Wants=network-online.target
After=network-online.target

[Service]
User=prometheus
Group=prometheus
ExecStart=/usr/local/bin/prometheus \
  --config.file=/etc/prometheus/prometheus.yml \
  --storage.tsdb.path=/var/lib/prometheus \
  --storage.tsdb.retention.time=30d \
  --web.listen-address=127.0.0.1:9090
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure

[Install]
WantedBy=multi-user.target

How do I start it and prove it works?

Validate the config first, then start the service and ask the HTTP API whether both targets are healthy:

promtool check config /etc/prometheus/prometheus.yml
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
curl -s http://127.0.0.1:9090/-/ready
curl -s http://127.0.0.1:9090/api/v1/targets | grep -o '"health":"[a-z]*"'

Both lines of the last command should read "health":"up". To browse the built-in UI, open a tunnel from your computer with ssh -N -L 9090:127.0.0.1:9090 deploy@198.51.100.24 and visit http://localhost:9090. Try a query such as the CPU busy percentage:

100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)

Free memory as a percentage is node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes * 100.

How do I scrape another server over the public internet?

Our servers have no private network between them, so remote scrapes cross public IPs. Protect each remote node_exporter three ways: TLS, a password and a firewall rule. On the remote server (here 198.51.100.40), create a self-signed certificate that names its IP and a bcrypt password hash:

sudo mkdir -p /etc/node_exporter
cd /etc/node_exporter
sudo openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 825 \
  -keyout node.key -out node.crt -subj "/CN=node" -addext "subjectAltName=IP:198.51.100.40"
sudo chown node_exporter: node.key node.crt
# apache2-utils on Ubuntu/Debian, httpd-tools on Rocky/Alma
htpasswd -nBC 10 prom

Put the hash (the part after prom:) into /etc/node_exporter/web.yml:

tls_server_config:
  cert_file: /etc/node_exporter/node.crt
  key_file: /etc/node_exporter/node.key
basic_auth_users:
  prom: PASTE_BCRYPT_HASH

Change ExecStart to --web.listen-address=:9100 --web.config.file=/etc/node_exporter/web.yml, restart, and admit only the Prometheus server (here 203.0.113.10):

# Ubuntu and Debian
sudo ufw allow from 203.0.113.10 to any port 9100 proto tcp

# Rocky Linux and AlmaLinux
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="203.0.113.10" port port="9100" protocol="tcp" accept'
sudo firewall-cmd --reload

Copy node.crt to the Prometheus server as /etc/prometheus/web1.crt, store the plain password in /etc/prometheus/web1.pass (owned by prometheus, mode 600) and add a job:

  - job_name: node-remote
    scheme: https
    tls_config:
      ca_file: /etc/prometheus/web1.crt
    basic_auth:
      username: prom
      password_file: /etc/prometheus/web1.pass
    static_configs:
      - targets: ["198.51.100.40:9100"]
        labels:
          host: web1

Run promtool check config again and sudo systemctl reload prometheus. More on firewall rules in UFW and firewalld.

How do I add alert rules?

Prometheus evaluates rules and sends firing alerts to Alertmanager, which handles routing, grouping and delivery. A first rule file, /etc/prometheus/rules.yml, could flag missing targets and full disks:

groups:
  - name: basics
    rules:
      - alert: TargetDown
        expr: up == 0
        for: 5m
      - alert: DiskAlmostFull
        expr: node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"} / node_filesystem_size_bytes < 0.10
        for: 15m

Reference it with rule_files: ["rules.yml"] in the main config, check with promtool check rules and reload. Firing alerts are visible on the Alerts page even before Alertmanager is installed; alternatively, define alerts in Grafana instead.

How do I upgrade and troubleshoot?

To upgrade, download the new archive, stop the service, replace the binary with install and start it again; the data directory format is kept between minor releases. Read the release notes before jumping major versions.

  • Target down with a TLS error: the certificate does not list the IP you scrape; regenerate it with the correct subjectAltName.
  • 401 Unauthorized: the password file holds a trailing newline or a different password than the hash.
  • Context deadline exceeded: the remote firewall drops the scrape; test with curl -k -u prom https://198.51.100.40:9100/metrics from the Prometheus server.
  • Disk filling up: shorten --storage.tsdb.retention.time or add --storage.tsdb.retention.size=8GB.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-2Prometheus for a few servers1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months
A2-4Prometheus plus Grafana on one host2 vCPU, 4 GB RAM, 100 GB NVMe$14.40/mo$43.20 for 3 months

Questions about Prometheus and node_exporter

Which ports do they use?

Prometheus listens on 9090 and node_exporter on 9100. Keep 9090 on localhost, and open 9100 only to the Prometheus server IP when you scrape across the internet.

How much disk does Prometheus need?

It depends on the number of series and the retention. A handful of servers at a 30 second interval for 30 days usually fits in a few gigabytes; check with du -sh /var/lib/prometheus.

Can I protect the Prometheus UI with a password too?

Yes. Prometheus accepts the same --web.config.file format with TLS and basic_auth_users, or you can put it behind Caddy with HTTPS and basic auth.

Can I use an SSH tunnel instead of TLS for remote targets?

Yes. Keep node_exporter on 127.0.0.1 and run a persistent tunnel such as ssh -N -L 19100:127.0.0.1:9100 from the Prometheus server, then scrape 127.0.0.1:19100. It is simple but needs a service to keep the tunnel alive.

Do I still need the console Usage graphs?

They remain useful as an outside view and for checking monthly transfer. See monitor usage.