#!/usr/bin/env bash # # Homelab monitoring, Part 2: Every VM, the NAS and the Wi-Fi # https://www.zadran.net/guides/homelab-monitoring-2-proxmox-truenas-unifi # Generated from the guide, last updated 2026-10-13. # # NO WARRANTY. This script is provided as is. You are responsible for # understanding what it does before running it, and for the consequences. # Take a backup first. See https://www.zadran.net/disclaimer # # Destructive steps are left commented out on purpose -- uncomment them # only once you have understood what they do. # # Where the guide writes a file with <<'EOF' and your values are in it, # this script uses < UNIFI_URL='https://192.168.1.15:11443' pveum user add prometheus@pve --comment "Monitoring (read-only)" pveum acl modify / --users prometheus@pve --roles PVEAuditor pveum user token add prometheus@pve exporter --privsep 0 pct enter ${CTID} # from the Proxmox host shell nano /opt/monitoring/prometheus/pve.yml # >> By hand: the guide has a yaml block here, to type or paste into # >> a file or a form. It is not a command, so it is not in this script. cat > /opt/monitoring/compose.override.yaml <<'EOF' services: pve-exporter: image: prompve/prometheus-pve-exporter:latest container_name: pve-exporter restart: unless-stopped volumes: - ./prometheus/pve.yml:/etc/prometheus/pve.yml:ro EOF cat >> /opt/monitoring/prometheus/prometheus.yml < /mnt/${POOL}/apps/node-exporter/zpool-metrics.sh < "\$TMP" chmod 644 "\$TMP" && mv "\$TMP" "\$DIR/zpool.prom" EOF bash /mnt/${POOL}/apps/node-exporter/zpool-metrics.sh && cat /mnt/${POOL}/apps/node-exporter/textfile/zpool.prom # >> By hand: the guide has a yaml block here, to type or paste into # >> a file or a form. It is not a command, so it is not in this script. curl -s http://${NAS_IP}:9100/metrics | grep '^zpool_' nano /opt/monitoring/prometheus/prometheus.yml # >> By hand: the guide has a yaml block here, to type or paste into # >> a file or a form. It is not a command, so it is not in this script. curl -s -X POST localhost:9090/-/reload && echo "reload OK" nano /opt/monitoring/.env cat >> /opt/monitoring/compose.override.yaml <> /opt/monitoring/prometheus/prometheus.yml <<'EOF' - job_name: unpoller static_configs: - targets: ['unpoller:9130'] EOF cd /opt/monitoring && docker compose up -d curl -s -X POST localhost:9090/-/reload && echo "reload OK" sleep 40 docker compose logs unpoller --since 1m | tail -5 curl -s 'localhost:9090/api/v1/targets?state=active' | jq -r '.data.activeTargets[] | "\(.health)\t\(.labels.job)\t\(.labels.host // .labels.instance)"' | sort -k2 | column -t