Some checks failed
CI/CD / lint (pull_request) Failing after 9s
CI/CD / test (pull_request) Failing after 9s
CI/CD / typecheck (pull_request) Failing after 24s
CI/CD / build (pull_request) Has been skipped
CI/CD / publish-rpm (pull_request) Has been skipped
CI/CD / publish-deb (pull_request) Has been skipped
The Grafana heatmap of 1s and 0s said almost nothing, and the state timeline
was an unreadable pile of overlapping series labels. Replaced as the primary
view with a purpose-built page served by the exporter itself.
- Probe now captures ICMP RTT, exposed as labsim_rtt_ms{src,dst}. A path that
is up but slow is a different problem from one that is down, and a pass/fail
grid cannot show it.
- Exporter serves / (topology), /api/matrix (JSON) and /metrics.
- topology.html: node per VLAN in a ring, VyOS router in the centre because
every inter-VLAN packet really does traverse it, one line per pair coloured
green/red with the RTT on it. Hovering gives per-direction state. A node ring
goes red if anything to or from it is blocked. Side panels list blocked paths
and the slowest links. Refreshes every 5s, no dependencies.
Grafana stays for what it is actually good at — history of when a path flipped.
Label placement is deliberate: RTT captions sit ~32% along each edge with a
perpendicular nudge, because every diagonal of a 6-node mesh crosses the centre
and midpoint labels stack on the router node.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DMVzWZgiKW2wquf5z8S1yH
83 lines
3.2 KiB
Bash
Executable File
83 lines
3.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Prometheus + Grafana for the labsim connectivity matrix.
|
|
#
|
|
# Grafana runs with anonymous auth as Admin — NO LOGIN. That is deliberate for
|
|
# a throwaway lab on localhost; do not copy this into anything reachable.
|
|
#
|
|
# ./monitoring-up.sh start exporter + prometheus + grafana
|
|
# ./monitoring-up.sh --down stop and remove them
|
|
#
|
|
# Grafana: http://localhost:3000 (dashboard "labsim — VLAN connectivity matrix")
|
|
# Prometheus: http://localhost:9090
|
|
# Exporter: http://localhost:9101/metrics
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
source "$SCRIPT_DIR/lib.sh"
|
|
|
|
GRAFANA_PORT="${GRAFANA_PORT:-3000}"
|
|
PROM_PORT="${PROM_PORT:-9090}"
|
|
EXPORTER_PORT="${EXPORTER_PORT:-9101}"
|
|
NET="labsim-mon"
|
|
|
|
if [ "${1:-}" = "--down" ]; then
|
|
pkill -f "labsim-exporter.py" 2>/dev/null || true
|
|
podman rm -f labsim-grafana labsim-prometheus >/dev/null 2>&1 || true
|
|
podman network rm -f "$NET" >/dev/null 2>&1 || true
|
|
log "monitoring stopped"
|
|
exit 0
|
|
fi
|
|
|
|
command -v podman >/dev/null 2>&1 || die "podman not installed"
|
|
|
|
# --- exporter (on the host: it needs SSH access to the VMs) ----------------
|
|
if pgrep -f "labsim-exporter.py" >/dev/null 2>&1; then
|
|
log "exporter already running on :$EXPORTER_PORT"
|
|
else
|
|
log "starting exporter on :$EXPORTER_PORT"
|
|
nohup "$SCRIPT_DIR/labsim-exporter.py" --port "$EXPORTER_PORT" --interval 15 \
|
|
> /tmp/labsim-exporter.log 2>&1 &
|
|
sleep 3
|
|
fi
|
|
curl -sS --max-time 5 "http://127.0.0.1:${EXPORTER_PORT}/metrics" >/dev/null \
|
|
|| die "exporter not answering on :$EXPORTER_PORT (see /tmp/labsim-exporter.log)"
|
|
|
|
podman network exists "$NET" 2>/dev/null || podman network create "$NET" >/dev/null
|
|
|
|
# --- prometheus -----------------------------------------------------------
|
|
podman rm -f labsim-prometheus >/dev/null 2>&1 || true
|
|
log "starting prometheus on :$PROM_PORT"
|
|
podman run -d --name labsim-prometheus --network "$NET" \
|
|
-p "${PROM_PORT}:9090" \
|
|
-v "$SCRIPT_DIR/monitoring/prometheus.yml:/etc/prometheus/prometheus.yml:ro,Z" \
|
|
--add-host "host.containers.internal:host-gateway" \
|
|
docker.io/prom/prometheus:latest >/dev/null
|
|
|
|
# --- grafana (anonymous, no login) ----------------------------------------
|
|
podman rm -f labsim-grafana >/dev/null 2>&1 || true
|
|
log "starting grafana on :$GRAFANA_PORT (anonymous auth — no password)"
|
|
podman run -d --name labsim-grafana --network "$NET" \
|
|
-p "${GRAFANA_PORT}:3000" \
|
|
-e GF_AUTH_ANONYMOUS_ENABLED=true \
|
|
-e GF_AUTH_ANONYMOUS_ORG_ROLE=Admin \
|
|
-e GF_AUTH_DISABLE_LOGIN_FORM=true \
|
|
-e GF_AUTH_BASIC_ENABLED=false \
|
|
-e GF_SECURITY_ALLOW_EMBEDDING=true \
|
|
-e GF_USERS_DEFAULT_THEME=dark \
|
|
-v "$SCRIPT_DIR/monitoring/grafana/provisioning:/etc/grafana/provisioning:ro,Z" \
|
|
docker.io/grafana/grafana:latest >/dev/null
|
|
|
|
log "waiting for grafana..."
|
|
for _ in $(seq 1 40); do
|
|
if curl -sS --max-time 3 "http://127.0.0.1:${GRAFANA_PORT}/api/health" >/dev/null 2>&1; then
|
|
break
|
|
fi
|
|
sleep 3
|
|
done
|
|
|
|
echo
|
|
log "Topology: http://localhost:${EXPORTER_PORT}/ <- live mesh, red/green + RTT"
|
|
log "Grafana: http://localhost:${GRAFANA_PORT}/d/labsim-matrix (no login, history)"
|
|
log "Prometheus: http://localhost:${PROM_PORT}"
|
|
log "Exporter: http://localhost:${EXPORTER_PORT}/metrics"
|