← Start of tutorial

WIUNIX ACADEMY

Build a Prometheus + Grafana monitoring stack

Page 3 of 6. Review the earlier steps and prerequisites before continuing.

YOUR SYSTEM. YOUR STEPS.

Where are you working?

Choose your OS and version. The prerequisites, commands and troubleshooting follow your environment.

Arch Linux rolling · 2026-11-05Reviewed against official documentation ·

USE YOUR OWN VALUES

Configure this tutorial

Set the example values for your environment; related explanations and copy panels update together. Never enter passwords, private keys or tokens. Values stay in this tab and are not sent to the server or share links. Check actual DNS, certificates and network policy before running commands.

Different IP addresses, domains or ports? Open the settings below, change the values and select “Apply to tutorial”, then copy the updated commands.

Set values for my environment2 editable values
10

LET’S BUILD

Start Prometheus and node_exporter, then verify exact HTTP 200 responses

Validate as the service user before starting either service. The bounded readiness loop accepts only HTTP 200 and rejects redirects, transport failures and timeouts; service active alone is insufficient.

The Prometheus ready endpoint proves it can serve queries. The next step separately confirms that both targets have actually been scraped.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo chown root:prometheus /etc/prometheus/prometheus.yml
sudo chmod 0640 /etc/prometheus/prometheus.yml
sudo -u prometheus /usr/local/bin/promtool check config /etc/prometheus/prometheus.yml
sudo systemctl daemon-reload
sudo systemctl enable --now prometheus node_exporter
systemctl is-active prometheus node_exporter
ok=0
for attempt in $(seq 1 12); do
  if code=$(curl --noproxy '*' -sS --connect-timeout 2 --max-time 5 -o /dev/null -w '%{http_code}' http://127.0.0.1:9090/-/ready); then
    if [ "$code" = 200 ]; then ok=1; break; fi
  fi
  sleep 2
done
[ "$ok" = 1 ] || { echo 'Endpoint did not become ready: http://127.0.0.1:9090/-/ready' >&2; exit 1; }
printf '%s -> 200\n' 'http://127.0.0.1:9090/-/ready'
ok=0
for attempt in $(seq 1 12); do
  if code=$(curl --noproxy '*' -sS --connect-timeout 2 --max-time 5 -o /dev/null -w '%{http_code}' http://127.0.0.1:9100/metrics); then
    if [ "$code" = 200 ]; then ok=1; break; fi
  fi
  sleep 2
done
[ "$ok" = 1 ] || { echo 'Endpoint did not become ready: http://127.0.0.1:9100/metrics' >&2; exit 1; }
printf '%s -> 200\n' 'http://127.0.0.1:9100/metrics'
sudo ss -lntp 'sport = :9090 or sport = :9100'
)
EXAMPLE OUTPUT
Illustrative success (additional promtool messages omitted):
active
active
http://127.0.0.1:9090/-/ready -> 200
http://127.0.0.1:9100/metrics -> 200
How do I know it worked?

Both services report active, and each checked URL prints an exact 200 status code.

Prometheus does not stay active

Inspect the recent journal entries and validate that the configuration file and storage path are readable by the Prometheus service account.

Bash
sudo journalctl -u prometheus -n 80 --no-pager
sudo ls -ld /etc/prometheus /var/lib/prometheus
sudo ls -l /etc/prometheus/prometheus.yml
sudo -u prometheus /usr/local/bin/promtool check config /etc/prometheus/prometheus.yml
node_exporter is not listening on port 9100

Check the service log and confirm that no other process already owns the chosen listen address.

Bash
sudo journalctl -u node_exporter -n 80 --no-pager
sudo ss -lntp | grep 9100 || true
11

LET’S BUILD

Query Prometheus directly before you open Grafana

Initial scrapes take time. Retry the API a bounded 12 times, with five seconds between attempts. Require HTTP 200, API status success and up=1 for the exact local Prometheus and node_exporter instances.

Bash

Monitoring server terminal.

(
set -euo pipefail
response=$(mktemp)
trap 'rm -f "$response"' EXIT
ok=0
for attempt in $(seq 1 12); do
  if code=$(curl --noproxy '*' -sS --connect-timeout 2 --max-time 5 -G \
    --data-urlencode 'query=up' -o "$response" -w '%{http_code}' \
    http://127.0.0.1:9090/api/v1/query); then
    if [ "$code" = 200 ] && jq -e '.status == "success" and .data.resultType == "vector" and any(.data.result[]; .metric.job == "prometheus" and .metric.instance == "127.0.0.1:9090" and .value[1] == "1") and any(.data.result[]; .metric.job == "node-exporter" and .metric.instance == "127.0.0.1:9100" and .value[1] == "1")' "$response" >/dev/null; then
      ok=1; break
    fi
  fi
  sleep 5
done
[ "$ok" = 1 ] || { cat "$response" >&2; echo 'Both local targets must have up=1' >&2; exit 1; }
jq . "$response"
)
EXAMPLE OUTPUT
Illustrative result excerpt; actual timestamps vary:
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"job":"prometheus","instance":"127.0.0.1:9090"},"value":[1792444800,"1"]},{"metric":{"job":"node-exporter","instance":"127.0.0.1:9100"},"value":[1792444800,"1"]}]}}
How do I know it worked?

The response status is success and the result contains value 1 for both the prometheus and node-exporter jobs.

The query returns an empty result

Review the discovered targets to see whether Prometheus can scrape each job and whether any target is marked down.

Bash
curl -fsS --connect-timeout 2 --max-time 5 http://127.0.0.1:9090/api/v1/targets | jq .

Prepare private Grafana binding before installation

Create this systemd override before installing the package, so even a package-triggered start binds only to loopback.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo install -d -m 0755 /etc/systemd/system/grafana.service.d
sudo nano /etc/systemd/system/grafana.service.d/academy-local.conf
)
How do I know it worked?

The command completes successfully; stop and inspect any error before continuing.

Grafana private binding override

Paste this file, save and exit. The environment override takes precedence over grafana.ini. An approved TLS reverse proxy can later use this same local listener.

systemd · /etc/systemd/system/grafana.service.d/academy-local.conf

File contents; save in the named file, not in the shell.

[Service]
Environment="GF_SERVER_HTTP_ADDR=127.0.0.1"
Environment="GF_PATHS_PROVISIONING=/etc/grafana/provisioning"
Environment="GF_PATHS_DATA=/var/lib/grafana"
How do I know it worked?

Only a loopback bind is configured.

12

LET’S BUILD

Install Grafana from the official APT repository

Install Grafana from the selected distribution’s signed repository with a full synchronized transaction. Review whole-system changes, reboot if required and recheck addresses/time. Do not add Grafana’s APT/RPM repo here. Arch currently lists 13.3.0-2; Manjaro branches may differ.

The package uses /etc/grafana.ini, /usr/bin/grafana and grafana.service. This fresh drop-in explicitly selects /etc/grafana/provisioning and /var/lib/grafana. Inspect the package unit and any unexpected command-line paths before starting; stop rather than guessing around overrides. This community path does not establish Grafana vendor OS support.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo pacman -Syu --needed grafana
pacman -Q grafana
sudo cat /usr/lib/systemd/system/grafana.service
)
How do I know it worked?

APT can read the Grafana repository and installs the grafana package without signature or dependency errors.

Package or unit differs

Inspect this distribution package and unit; do not mix packages or disable signature checks.

Bash
pacman -Qi grafana
sudo cat /usr/lib/systemd/system/grafana.service

Open the next configuration file

Open the file, paste the contents in the following panel, then save and exit (nano: Ctrl+O, Enter, Ctrl+X). Do not run file contents as shell commands.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo install -d -o root -g grafana -m 0750 /etc/grafana/provisioning/datasources
sudo test ! -e /etc/grafana/provisioning/datasources/prometheus.yaml
sudo test ! -L /etc/grafana/provisioning/datasources/prometheus.yaml
sudo nano /etc/grafana/provisioning/datasources/prometheus.yaml
)
How do I know it worked?

The command completes successfully; stop and inspect any error before continuing.

13

LET’S BUILD

Provision the Prometheus data source for Grafana

Grafana supports data source provisioning from declarative files. Using provisioning keeps the first setup reproducible and avoids a manual click path for a basic local Prometheus source.

Create the file below so Grafana loads Prometheus as the default data source at startup.

YAML · /etc/grafana/provisioning/datasources/prometheus.yaml

File contents; save in the named file, not in the shell.

apiVersion: 1

datasources:
  - name: Prometheus
    uid: prometheus-local
    type: prometheus
    access: proxy
    url: http://127.0.0.1:9090
    isDefault: true
    editable: true
How do I know it worked?

The provisioning file exists and points Grafana to the local Prometheus API.

Explore all tutorials ↗