← Start of tutorial

WIUNIX ACADEMY

Build a Prometheus + Grafana monitoring stack

Page 4 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.

Rocky Linux 10.2Reviewed 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
14

LET’S BUILD

Start Grafana and verify its health endpoint

Restart once after saving provisioning; enabling an already running service does not reload it. Require exact HTTP 200 and database ok, then inspect the listener: it must be 127.0.0.1:3000 before you sign in.

Bash

Monitoring server terminal.

(
set -euo pipefail
sudo chown root:grafana /etc/grafana/provisioning/datasources/prometheus.yaml
sudo chmod 0640 /etc/grafana/provisioning/datasources/prometheus.yaml
sudo restorecon -Rv /etc/grafana
sudo restorecon -v /etc/systemd/system/grafana-server.service.d/academy-local.conf
sudo systemctl daemon-reload
sudo systemctl unmask grafana-server
sudo systemctl enable grafana-server
sudo systemctl restart grafana-server
systemctl is-active grafana-server
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:3000/api/health); 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:3000/api/health' >&2; exit 1; }
printf '%s -> 200\n' 'http://127.0.0.1:3000/api/health'
curl --noproxy '*' -fsS --connect-timeout 2 --max-time 5 http://127.0.0.1:3000/api/health | jq -e '.database == "ok"'
sudo ss -lntp 'sport = :3000'
)
EXAMPLE OUTPUT
Illustrative excerpt:
active
http://127.0.0.1:3000/api/health -> 200
true
Listener: 127.0.0.1:3000
How do I know it worked?

The grafana-server unit is active, the health endpoint prints an exact 200, and the JSON response reports database ok.

Grafana does not return HTTP 200

Inspect the Grafana service log and verify that the provisioning directory contains the expected data source file.

Bash
sudo journalctl -u grafana-server -n 100 --no-pager
sudo ls -l /etc/grafana/provisioning/datasources
sudo sed -n "1,120p" /etc/grafana/provisioning/datasources/prometheus.yaml
15

LET’S BUILD

Sign in to Grafana and confirm the data source

On your workstation, replace the two SSH placeholders with your existing login and server address. Keep the tunnel terminal open. Open http://127.0.0.1:13000 in your browser; the remote service remains private and the network leg is encrypted by SSH.

For a fresh installation, sign in with username admin and initial password admin, then immediately set a unique strong password. Do not reuse these defaults or put the new password in commands, source files or screenshots. The SSH server must permit local forwarding.

In Connections, find the provisioned Prometheus source. In Explore select it and run up. Both local instances must be 1; /api/health alone does not prove the data source works.

Bash

Workstation terminal, not the monitoring server. Replace YOUR_SSH_USER and MONITORING_SERVER before running.

ssh -N -o ExitOnForwardFailure=yes -L 127.0.0.1:13000:127.0.0.1:3000 YOUR_SSH_USER@MONITORING_SERVER
How do I know it worked?

You can sign in, change the initial password, and see the provisioned Prometheus data source available in Grafana.

16

LET’S BUILD

Create a first dashboard with practical PromQL panels

Create separate panels for CPU utilization, the approximate share of memory in use and filesystem available bytes. Paste one PromQL expression per panel and select matching units.

The MemAvailable ratio is not PSI or a direct measurement of memory pressure. Assess pressure with the relevant signals and application behavior separately.

PromQL

Grafana dashboard panel editor in the browser.

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

100 * (1 - (node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes))

node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}
How do I know it worked?

Each panel shows live data instead of an empty or error state, proving that Grafana can query Prometheus successfully.

Optional: reserve a fresh remote exporter identity

On a separate fresh disposable x86_64 systemd VM, repeat only the selected base-tools installation, then use this guard/account panel. Repeat the verified node_exporter download and exporter-only unit editor/content panels, retaining loopback initially. Do not repeat the main monitoring-host account panel, install Prometheus/Grafana, or start a public exporter. Continue below with the actual remote firewall before changing its listener.

Bash

Optional remote VM only · sudo

sudo bash <<'ROOT'
set -euo pipefail
test "$(uname -m)" = x86_64
for path in /usr/local/bin/node_exporter /etc/systemd/system/node_exporter.service /etc/systemd/system/node_exporter.service.d; do
  if test -e "$path" || test -L "$path"; then echo "STOP: existing exporter state $path" >&2; exit 1; fi
done
if getent passwd node_exporter >/dev/null || getent group node_exporter >/dev/null; then echo 'STOP: existing exporter identity' >&2; exit 1; fi
for unit in node_exporter node-exporter; do
  test "$(systemctl show "$unit" -p LoadState --value)" = not-found || { echo 'STOP: existing exporter unit' >&2; exit 1; }
done
useradd --system --user-group --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin node_exporter
ROOT
How do I know it worked?

Fresh exporter identity exists; verified binary and loopback unit are prepared using the earlier exporter-only steps.

Optional: prepare the remote node safely

Optional remote node only after fresh exporter preparation. firewalld must already be active with preserved SSH and default-deny exposure. Replace internal with the actual private interface zone from get-active-zones. Review its target, services, rules and upstream ACL; a broad existing allow defeats source restriction. Add only monitor-to-target TCP9100 in runtime and permanent state without reload. Record whether this exact rule already existed; retire only rules introduced by this lab.

Do not open exporter access globally or install/switch firewalls during diagnosis. Keep SELinux enabled; restore new unit/drop-in labels and inspect actual AVCs if startup or scraping fails.

Bash

Optional remote exporter VM only · sudo; monitoring host address is 10.20.30.10

(
set -euo pipefail
sudo firewall-cmd --state
sudo firewall-cmd --get-active-zones
zone=internal
sudo firewall-cmd --zone="$zone" --list-all
rule='rule family="ipv4" source address="10.20.30.10/32" destination address="10.20.30.41/32" port port="9100" protocol="tcp" accept'
sudo firewall-cmd --zone="$zone" --add-rich-rule="$rule"
sudo firewall-cmd --permanent --zone="$zone" --add-rich-rule="$rule"
sudo firewall-cmd --zone="$zone" --list-rich-rules
sudo firewall-cmd --permanent --zone="$zone" --list-rich-rules
sudo install -d -m 0755 /etc/systemd/system/node_exporter.service.d
sudo nano /etc/systemd/system/node_exporter.service.d/private.conf
)
How do I know it worked?

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

Remote exporter private listener

On the remote node, save this override with its actual private IP. Clearing ExecStart is required before replacing it. The private network carries unauthenticated metrics: use a trusted network/VPN, or configure exporter TLS/auth separately.

systemd · /etc/systemd/system/node_exporter.service.d/private.conf

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

[Service]
ExecStart=
ExecStart=/usr/local/bin/node_exporter --web.listen-address=10.20.30.41:9100
How do I know it worked?

The override selects only the private address.

Explore all tutorials ↗