SELF-HOSTED MONITORING

node_exporter, Prometheus, Alertmanager and Grafana on one Ubuntu 24.04 box, with five alerts that reach you before an incident becomes an outage.

Self-hosted monitoring with Prometheus and Grafana

 

Self-hosted monitoring with Prometheus and Grafana

Self-hosted monitoring is how you find out a disk is filling or a RAID array is degraded before either becomes an outage. This guide is a complete Prometheus Grafana setup for server monitoring on Linux, built on Ubuntu 24.04 LTS: node_exporter for metrics, Prometheus to scrape and store them and run alert rules, Alertmanager to route the alerts, and a Grafana node exporter dashboard to see it all.

Server.Biz sells unmanaged dedicated servers, so the machine and its monitoring are yours to run. Everything below is standard, well-documented practice; every command is copy-and-run, and by the end you have a working stack that tells you when something is wrong instead of after it broke.

Why monitoring is the difference between an incident and an outage

An incident is a disk at 90% that you caught with three hours to spare. An outage is the same disk at 100% at 4am with the database refusing writes. The only thing between them is that someone saw the trend in time. On unmanaged hardware nobody else is watching, so monitoring is not a nice-to-have, it is the early-warning system that turns a quiet fix into a non-event.

Most tutorials stop at CPU and memory graphs. On a dedicated server the signals that actually save you are elsewhere. Watch disk space and its rate of change, because a filesystem fills on a trend you can predict, not a surprise. Watch RAID array state, because a mirrored array runs happily on one drive and stays silent until the second one dies. Watch SMART attributes, because drives usually warn you with reallocated sectors before they fail outright. And watch iowait, because storage that has started to stall shows up there long before the application errors out. A pretty CPU graph tells you nothing about any of these.

An honest note on hosted options

If you run exactly one box, be aware of the catch: Prometheus running on that box cannot tell you when the box itself dies, because it dies too. A hosted option such as the Grafana Cloud free tier pushes metrics off the machine and gives you host-down alerting for free, which is genuinely useful for a single server. Self-hosting wins once you run several machines, want everything on infrastructure you control, or need retention and dashboards without a per-metric bill. This guide self-hosts, and the discipline section covers how to catch the your-own-box-is-down case anyway.

The stack in one paragraph

Four small Go programs do the whole job, and each has one responsibility. node_exporter runs on every machine you watch and exposes hardware and OS metrics over HTTP. Prometheus scrapes those endpoints on a schedule, stores the numbers in its own time-series database, and evaluates your alert rules against them. When a rule fires, Prometheus hands the alert to Alertmanager, which deduplicates, groups and routes it to email, chat or a webhook. Grafana reads from Prometheus and draws the dashboards. You install them once and they run as systemd services from then on.

node_exporter

Runs on each monitored host and publishes metrics at /metrics on port 9100: disk, filesystem, RAID, CPU modes, memory, network and systemd unit state.

Prometheus

Scrapes every target on a schedule, stores the series with your chosen retention, and evaluates alert rules. The single source of truth for metrics.

Alertmanager

Takes firing alerts from Prometheus and routes them: dedupes duplicates, groups related ones, and delivers to email, a webhook or chat with sane repeat intervals.

Grafana

Queries Prometheus and renders dashboards. Import a community dashboard by ID and you have a full node view in minutes, no panel building required.

Install node_exporter as a systemd service

Start with the agent, because Prometheus needs something to scrape. node_exporter ships as a single static binary with no dependencies. Download it, run it under a dedicated unprivileged user, and bind it to localhost on this first box so nothing is exposed to the network yet. Adding remote machines comes later, over a private path.

Download and install the binary. Check the releases page for the current version and set it here; the commands are otherwise unchanged.

shell
NODE_EXPORTER_VERSION=1.8.2
cd /tmp
curl -LO https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz
tar xzf node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz
sudo cp node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/
sudo useradd --system --no-create-home --shell /usr/sbin/nologin node_exporter
sudo chown node_exporter:node_exporter /usr/local/bin/node_exporter

The systemd unit. The systemd collector is what makes the failed-unit alert work later; the md (RAID) and filesystem collectors are on by default. Binding to 127.0.0.1 keeps the exporter off the public internet.

/etc/systemd/system/node_exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network-online.target
Wants=network-online.target

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

[Install]
WantedBy=multi-user.target

Start it, enable it at boot, and confirm it is serving metrics.

shell
sudo systemctl daemon-reload
sudo systemctl enable --now node_exporter
curl -s http://127.0.0.1:9100/metrics | grep -E '^node_(filesystem_avail|md_disks) ' | head

Install Prometheus: scrape, store, retain

Prometheus does three things: it scrapes targets, stores the series on disk, and evaluates rules. Install it the same way, as a binary under its own user, with a data directory it owns. Bind the web interface to localhost too; Grafana and your browser reach it through a proxy later, never over the open internet.

Install the binaries and create the directories. Set the current version from the releases page.

shell
PROM_VERSION=3.1.0
cd /tmp
curl -LO https://github.com/prometheus/prometheus/releases/download/v${PROM_VERSION}/prometheus-${PROM_VERSION}.linux-amd64.tar.gz
tar xzf prometheus-${PROM_VERSION}.linux-amd64.tar.gz
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus
sudo mkdir -p /etc/prometheus/rules /var/lib/prometheus
sudo cp prometheus-${PROM_VERSION}.linux-amd64/prometheus /usr/local/bin/
sudo cp prometheus-${PROM_VERSION}.linux-amd64/promtool /usr/local/bin/
sudo chown -R prometheus:prometheus /etc/prometheus /var/lib/prometheus

The main config: a global scrape interval, where to send alerts, where the rule files live, and two scrape jobs (Prometheus scrapes itself, plus the node_exporter you just started). The instance label names the host in every graph and alert.

/etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets: ["127.0.0.1:9093"]

rule_files:
  - /etc/prometheus/rules/*.yml

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:
          instance: web01

The systemd unit. The retention flag decides how long history is kept: 90 days is a sensible default for one box, and you can trim it to match your disk. ExecReload lets you apply new rules without a full restart.

/etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
After=network-online.target
Wants=network-online.target

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

[Install]
WantedBy=multi-user.target

Enable and start it, then confirm the config parses.

shell
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus
promtool check config /etc/prometheus/prometheus.yml

Alertmanager and five alerts that actually matter

Prometheus decides when an alert fires; Alertmanager decides where it goes. Install it the same way, then give it one working receiver. Email through an SMTP relay is shown here; swap in a webhook if you route to chat instead. The placeholders in capitals are yours to fill in.

Install Alertmanager and create its directories. Set the current version from the releases page.

shell
ALERTMANAGER_VERSION=0.28.1
cd /tmp
curl -LO https://github.com/prometheus/alertmanager/releases/download/v${ALERTMANAGER_VERSION}/alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz
tar xzf alertmanager-${ALERTMANAGER_VERSION}.linux-amd64.tar.gz
sudo useradd --system --no-create-home --shell /usr/sbin/nologin alertmanager
sudo mkdir -p /etc/alertmanager /var/lib/alertmanager
sudo cp alertmanager-${ALERTMANAGER_VERSION}.linux-amd64/alertmanager /usr/local/bin/
sudo cp alertmanager-${ALERTMANAGER_VERSION}.linux-amd64/amtool /usr/local/bin/
sudo chown -R alertmanager:alertmanager /etc/alertmanager /var/lib/alertmanager

The routing config with one email receiver. group_by collapses a storm into one message per host and alert; repeat_interval stops it nagging every minute. Replace the SMTP relay, credentials and addresses with your own; if you use a webhook instead, delete the email_configs block and use webhook_configs with your endpoint URL.

/etc/alertmanager/alertmanager.yml
global:
  resolve_timeout: 5m

route:
  receiver: team-email
  group_by: ['alertname', 'instance']
  group_wait: 30s
  group_interval: 5m
  repeat_interval: 4h

receivers:
  - name: team-email
    email_configs:
      - to: 'ops@YOUR_DOMAIN'
        from: 'alertmanager@YOUR_DOMAIN'
        smarthost: 'smtp.YOUR_RELAY:587'
        auth_username: 'YOUR_SMTP_USER'
        auth_password: 'YOUR_SMTP_PASSWORD'
        require_tls: true

The systemd unit, again bound to localhost.

/etc/systemd/system/alertmanager.service
[Unit]
Description=Prometheus Alertmanager
After=network-online.target
Wants=network-online.target

[Service]
User=alertmanager
Group=alertmanager
Type=simple
ExecStart=/usr/local/bin/alertmanager \
  --config.file=/etc/alertmanager/alertmanager.yml \
  --storage.path=/var/lib/alertmanager \
  --web.listen-address=127.0.0.1:9093
Restart=on-failure

[Install]
WantedBy=multi-user.target

Now the rules that earn their keep. These five cover the failures that actually take a dedicated server down, and none of them fire on noise. Save the file, then validate and reload.

/etc/prometheus/rules/node-alerts.yml
groups:
  - name: node-alerts
    rules:
      # 1. A filesystem is trending toward full: predict the next 4 hours
      #    from the last hour of growth, and only alert if it is also
      #    already below 20% free (ignores brief, harmless dips).
      - alert: DiskWillFillIn4Hours
        expr: |
          predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay|squashfs"}[1h], 4*3600) < 0
          and
          node_filesystem_avail_bytes / node_filesystem_size_bytes < 0.20
        for: 15m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.mountpoint }} on {{ $labels.instance }} fills within 4h"
          description: "At the current rate {{ $labels.mountpoint }} runs out of space in under four hours."
          runbook: "https://YOUR_DOMAIN/runbooks/disk-full"

      # 2. A software RAID array is degraded: fewer active disks than the
      #    array requires, or a disk marked failed.
      - alert: RaidArrayDegraded
        expr: |
          (node_md_disks_required - on(instance, device) node_md_disks{state="active"}) > 0
          or node_md_disks{state="failed"} > 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "RAID array {{ $labels.device }} on {{ $labels.instance }} is degraded"
          description: "Replace the failed drive and let the array rebuild before a second one goes."
          runbook: "https://YOUR_DOMAIN/runbooks/raid-degraded"

      # 3. Storage is stalling the CPU (high iowait), or the box is being
      #    starved by a hypervisor (steal). On bare metal steal should be
      #    ~0, so any sustained steal is worth a look.
      - alert: CpuBlockedOnStorageOrSteal
        expr: |
          avg by (instance) (rate(node_cpu_seconds_total{mode="iowait"}[5m])) > 0.25
          or
          avg by (instance) (rate(node_cpu_seconds_total{mode="steal"}[5m])) > 0.05
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "{{ $labels.instance }} is spending too long waiting on IO or steal"
          description: "Sustained iowait or steal. Check disk health, IO load and neighbours."

      # 4. A systemd unit has entered the failed state.
      - alert: SystemdUnitFailed
        expr: node_systemd_unit_state{state="failed"} == 1
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "systemd unit {{ $labels.name }} failed on {{ $labels.instance }}"
          description: "Run: systemctl status {{ $labels.name }} to see why."

      # 5. A monitored host stopped answering scrapes.
      - alert: HostDown
        expr: up{job="node"} == 0
        for: 2m
        labels:
          severity: critical
        annotations:
          summary: "{{ $labels.instance }} is not responding to scrapes"
          description: "node_exporter is unreachable. The host or the exporter is down."

Validate the rules before you trust them, start Alertmanager, and reload Prometheus so it picks up the new file.

shell
sudo systemctl daemon-reload
sudo systemctl enable --now alertmanager
promtool check rules /etc/prometheus/rules/node-alerts.yml
sudo systemctl reload prometheus

The disk rule is the one people underestimate. predict_linear fits a line to the last hour of free space and projects it forward four hours; if that line crosses zero and the filesystem is already under 20% free, you get warned while there is still time to clear logs or grow the volume. It catches a runaway log or a stuck upload long before df would make you panic.

Grafana behind TLS, with dashboard 1860

Prometheus can draw a graph, but Grafana is where you live. Install it from the official apt repository so it stays current, bind it to localhost, and put a reverse proxy with TLS in front so the login page is never served over plain HTTP.

Add the Grafana apt repository and install.

shell
sudo apt-get install -y apt-transport-https software-properties-common wget
sudo mkdir -p /etc/apt/keyrings
wget -q -O - https://apt.grafana.com/gpg.key \
  | gpg --dearmor | sudo tee /etc/apt/keyrings/grafana.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" \
  | sudo tee /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install -y grafana

Bind Grafana to localhost and tell it its public URL. Edit these keys in the server section of the config.

/etc/grafana/grafana.ini
[server]
http_addr = 127.0.0.1
http_port = 3000
domain = monitoring.YOUR_DOMAIN
root_url = https://monitoring.YOUR_DOMAIN/

Provision the Prometheus datasource automatically, so you never wire it up by hand.

/etc/grafana/provisioning/datasources/prometheus.yml
apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    url: http://127.0.0.1:9090
    isDefault: true

Start Grafana, then put Caddy in front for automatic TLS. Caddy fetches and renews the certificate itself; this whole file is the reverse proxy. Point monitoring.YOUR_DOMAIN at the server first.

/etc/caddy/Caddyfile
monitoring.YOUR_DOMAIN {
    reverse_proxy 127.0.0.1:3000
}

Enable both services.

shell
sudo systemctl enable --now grafana-server
sudo systemctl reload caddy

Log in at your monitoring hostname, change the default admin password immediately, then import the node view: Dashboards, then Import, then enter dashboard ID 1860 (Node Exporter Full), and select the Prometheus datasource. That one dashboard gives you disk, RAID, CPU, memory and network panels for every host you scrape, with no panel building. If you would rather run nginx as the proxy, or need TLS options, client certificates and rate limiting, the high-traffic web server guide covers that proxy setup in depth.

Monitoring more machines, without exposing anything

One box is a start; the point of a central Prometheus is watching your whole fleet from one place. The rule that matters here is simple: never expose a node_exporter on the public internet. Its /metrics endpoint leaks a detailed map of your machine to anyone who asks, and it has no authentication of its own. Reach it over a private path instead.

The clean option is a WireGuard tunnel between your servers, so every exporter binds to a private tunnel address that does not exist on the public interface. The lighter option, if you already trust your host firewall, is to bind the exporter to the machine and allow port 9100 only from the monitoring server. Both are shown; pick one.

On the second server, install node_exporter exactly as before, then bind it to its private tunnel address (a WireGuard IP like 10.8.0.2) instead of localhost. Only the monitoring host on the same tunnel can reach it.

/etc/systemd/system/node_exporter.service
ExecStart=/usr/local/bin/node_exporter \
  --collector.systemd \
  --web.listen-address=10.8.0.2:9100

If you bind to the machine's real interface instead of a tunnel, lock the port down so only the monitoring server can reach it. Replace 203.0.113.10 with the monitoring host address.

shell
sudo ufw allow from 203.0.113.10 to any port 9100 proto tcp
sudo ufw deny 9100/tcp

Then add the new host to the node job in prometheus.yml. Give each target a clear instance label so alerts name the right machine.

/etc/prometheus/prometheus.yml
  - job_name: node
    static_configs:
      - targets: ["127.0.0.1:9100"]
        labels:
          instance: web01
      - targets: ["10.8.0.2:9100"]
        labels:
          instance: db01

Reload Prometheus and confirm the new target is up on the targets page.

shell
promtool check config /etc/prometheus/prometheus.yml
sudo systemctl reload prometheus

Every alert rule you wrote already applies to the new host automatically, because they match on the metric, not the machine. Add a server, get disk, RAID, iowait, failed-unit and host-down coverage for free. The getting-your-server-online guide covers the firewall basics for each new box before you add it here.

SMART and RAID, the bare-metal specifics

node_exporter tells you an array is already degraded. Two lower-level tools warn you earlier and independently, which matters on hardware you own end to end. smartmontools reads the drive's own health counters, and mdadm has its own monitor that mails you the instant an array changes state. Run both alongside Prometheus, not instead of it.

Install smartmontools and let smartd scan every drive, run periodic self-tests, and email you on a failing attribute. This config runs a short test nightly and a long test weekly.

/etc/smartd.conf
DEVICESCAN -a -o on -S on \
  -s (S/../.././02|L/../../6/03) \
  -m ops@YOUR_DOMAIN -M exec /usr/share/smartmontools/smartd-runner

Enable the smartd service so the checks run in the background.

shell
sudo apt-get install -y smartmontools
sudo systemctl enable --now smartd
sudo smartctl -H /dev/sda

For Linux software RAID, set the notification address and let mdadm's monitor daemon watch every array. It mails you on a degraded, failed or rebuilt event, which is your fastest signal after a drive dies.

/etc/mdadm/mdadm.conf
MAILADDR ops@YOUR_DOMAIN

Enable the monitor and send yourself a test message to prove mail actually leaves the box.

shell
sudo systemctl enable --now mdmonitor.service
sudo mdadm --monitor --scan --test --oneshot

Above both of these sits the out-of-band layer: the BMC (IPMI/Redfish). It runs on its own processor with its own network port, so it reads fan speed, temperature and power state even when the operating system is dead, which is exactly when Prometheus on the same box can tell you nothing. While the operating system runs you read the same sensors on the server itself with ipmitool sensor, and a small IPMI exporter on the server feeds them to Prometheus. Out-of-band access to the BMC is not self-service: access to the management console is on request, through support. The sensors and their thresholds are yours to watch.

The discipline that keeps alerts useful

A monitoring stack is easy to build and easy to ruin. The failure mode is not too few alerts, it is too many: once people start ignoring the noise, they miss the one that mattered. Three habits keep it honest.

Alert only on things a human must act on now. If an alert fires and the right response is to do nothing, it should not have fired. Everything else belongs on a dashboard you look at, not in your inbox at 4am. The five rules above are deliberately few for this reason. Add to them slowly, and delete any alert you have muted twice.

Test alerts by breaking something on purpose. An alert you have never seen fire is a guess. Stop node_exporter and watch HostDown trip; run the mdadm monitor test; force a unit to fail. Do it in daylight, on purpose, so you learn the path works before a real failure needs it to.

Put a runbook link in the alert itself. The rules above carry a runbook annotation for exactly this: when the disk alert wakes someone, the message should link to the two commands that clear space, not send them hunting through a wiki. A tired person at 4am needs the next action, not a puzzle.

The simplest honest test: stop the exporter and watch HostDown fire on the Prometheus alerts page, then start it again.

shell
sudo systemctl stop node_exporter
# Wait ~2 minutes, then check http://127.0.0.1:9090/alerts
sudo systemctl start node_exporter

Add one more rule that is worth having: a heartbeat that always fires, routed to a dead-man's-switch monitor. If this alert ever goes quiet, your monitoring itself is down. On a single box, this is how you catch the case where Prometheus cannot report its own death: route it to an external service such as the Grafana Cloud free tier or a healthchecks-style ping, not to the same box.

/etc/prometheus/rules/node-alerts.yml
      # Always-firing heartbeat: silence means monitoring itself broke.
      - alert: Watchdog
        expr: vector(1)
        labels:
          severity: none
        annotations:
          summary: "Monitoring is alive"

Route the Watchdog to a receiver that expects a message on a schedule and shouts when one does not arrive. That flips the logic in your favour: no news becomes bad news, which is the only safe default for a system whose whole job is to warn you.

Symptom, metric, alert

The whole stack comes down to matching a real-world symptom to the metric that sees it and the alert that pages you. This is the map.

Symptom Metric Alert
Disk about to fill node_filesystem_avail_bytes + predict_linear DiskWillFillIn4Hours
RAID array degraded node_md_disks vs node_md_disks_required RaidArrayDegraded
Storage stalling the CPU node_cpu_seconds_total{mode="iowait"} CpuBlockedOnStorageOrSteal
A service crashed node_systemd_unit_state{state="failed"} SystemdUnitFailed
Whole host unreachable up{job="node"} HostDown
Drive failing quietly SMART attributes (smartd) smartd email + weekly self-test

Build it before you need it

Monitoring is the one piece of setup that is worthless the day you install it and priceless six months later. Do it in the first hour, alongside the firewall, updates and a tested backup from the getting-your-server-online guide, so the machine is watching itself from day one. When you are ready to add a box built for the job, the dedicated server catalog lists the current range and pricing.

Continue reading

Need help choosing?

Our experts can help you find the perfect server for your needs.

Contact us »