Observability and Code Quality : pve-1

Observability and code quality

A dedicated ops VM that watches the whole lab and every line of code that ships to it: Prometheus collects metrics from the Proxmox host, every guest and the k3s cluster, Loki collects their logs, Grafana shows both, Alertmanager sends problems to my phone, and SonarQube scans each repository on every push.

I built it after consolidating everything onto one host. With apps, CI, Kubernetes and monitoring all sharing 32 GB of RAM, sizing decisions need numbers, not guesses. The RAM freed by replacing GitLab with Gitea paid for it.

The setup

node-exporter, pve-exporter, Gitea metrics, cAdvisor and kube-state-metrics feed Prometheus, which feeds Grafana; Gitea Actions sends scans to SonarQube

Everything runs from one Docker Compose project on a Debian VM cloned from my cloud-init template (4 vCPU, 6 GB). It starts at boot, and each container restarts on its own.

ContainerRoleExposed
prometheusScrapes 14 targets every 30 s and evaluates 15 alert rules; keeps 30 days (capped at 15 GB)Home network only
alertmanagerGroups alerts and sends them to a Telegram bot, with a message when each one clearsHome network only
lokiLogs from every machine and pod, kept for 14 daysHome network only
grafanaDashboards and log search, with Prometheus and Loki provisioned as data sourcesCloudflare Tunnel, login required
blackboxLoads every public site through Cloudflare once a minute, like a visitor wouldInternal only
node-exporterThe ops VM's own metricsHome network only
pve-exporterReads the Proxmox API with a read-only tokenInternal only
sonarqubeStatic analysis of every repositoryCloudflare Tunnel, login required
sonarqube-dbPostgreSQL 17 for SonarQubeInternal only

What Prometheus watches

  • Every machine: node-exporter on the Proxmox host, the app VM, both k3s nodes, the workstation, the Gitea container and the ops VM itself. CPU, memory, disk, filesystem and network.
  • Proxmox: pve-exporter reports each guest's state and usage, storage pools and the thin pool, through an API user that can read but never change anything.
  • Kubernetes: kube-state-metrics (installed with Helm) reports pods, deployments and restarts, and each kubelet's cAdvisor gives per-pod CPU and memory, read through the API server with a read-only service account.
  • Gitea: its built-in metrics (repositories, users, Actions), with the endpoint locked behind a token.
  • App containers: cAdvisor on the app VM gives per-container CPU and memory for this site, GridTwin and PostgreSQL.
  • Public sites: the blackbox exporter checks this site, GridTwin, DataBI, Gitea, Grafana, SonarQube, Argo CD and Headlamp from the internet side.

Grafana starts with community dashboards for the machines, Proxmox, the app containers and three Kubernetes views (cluster, namespaces, pods), loaded from files so a rebuilt VM comes back with the same views.

Logs next to the metrics

Grafana Alloy runs on the Proxmox host, the Gitea container and every VM, and ships to Loki:

  • the systemd journal everywhere, labelled by host, service and level;
  • Docker container logs on the app VM and the ops VM;
  • pod logs on both k3s nodes, labelled by namespace, pod and container.

One install script sets each machine up and only adds the sources that exist there. In Grafana, a spike on a dashboard is one click from the logs of the same minute, for example {namespace="databi"}.

Alerts on my phone

Fifteen Prometheus rules cover the failures that matter in this lab. Alertmanager groups them, sends them to a Telegram bot, repeats them every four hours while they last and sends a message when they clear. A critical alert hides its own warning, and a guest that is down hides the scrape failures it causes.

AreaAlerts when
Machinesa target stops reporting; a disk passes 85% or 95%; under 10% RAM is free; the kernel kills a process; CPU stays above 90%; a service fails
Proxmoxthe thin pool passes 80% or 90%; host storage passes 85%; a guest that should start on boot is not running
Kubernetesa pod is crash-looping; a deployment is short of pods; a pod is not ready for 15 minutes
Sitesa public site has not answered from the internet for 5 minutes

SonarQube in every pipeline

Every Gitea workflow (this site, GridTwin, DataBI and the demo app) has a sonarqube job that runs beside the tests. For the TypeScript and Python projects the scanner comes from npm and downloads its own Java runtime from the SonarQube server, so the existing Node-based runner image needed no changes. The token is a single user-level Gitea secret shared by every repository.

DataBI uses SonarScanner for .NET instead: it wraps the build and the xUnit run, so its C# gets the full analysis and coverlet's test coverage shows up in SonarQube.

The job is informational on purpose: continue-on-error means a scanner problem never holds back a deploy. Trivy remains the hard gate for container vulnerabilities in the DataBI pipeline. This site's first scan found 39 issues; 33 were in leftover template files nothing loaded, and after fixing the rest, including running Nginx as a non-root user, it is at zero.

Lessons

Check headroom before you add

Before building it I measured the host: 12 threads nearly idle and 16 GB of RAM free, while the app VM and the k3s control plane had little to spare. So the stack got its own VM instead of being squeezed into an existing one.

Monitoring has a memory bill too

With everything added the host reached 86% RAM. SonarQube's default Java heaps were the largest cost, so I capped them (2.8 GB down to 1.7 GB), cut the ops VM from 8 to 6 GB and turned off an unused desktop on the app VM. The host went back to about 70%.

SonarQube is picky about the kernel

Its embedded search engine needs vm.max_map_count=524288, and it will not start without it. A sysctl file on the VM sets it at every boot.

Least privilege for metrics

Prometheus, Loki and Alertmanager have no login, so they stay off the internet. Proxmox and Kubernetes are read with read-only tokens, and Gitea's metrics need a bearer token. Only Grafana and SonarQube are published, and both require a login.

Next

  • Quality gates on pull requests once the baselines are clean
  • Clear the GridTwin and DataBI SonarQube findings, starting with the vulnerabilities
  • Raise DataBI's test coverage from its first measured baseline
  • Alerts for failed Gitea Actions runs and expiring tokens