dashboards: zero-render stats, drop the aspirational folder annotation, keep the validator in the repo

- every count-style stat that can legitimately have no series now ends in
  'or vector(0)', so an empty result renders 0 instead of 'No data' (that bit
  the Pending-pods stat the moment the one Pending pod went away)
- no grafana_folder annotation: the sidecar's API reload 401s (Grafana's live
  admin password is the out-of-band one; the Secret is the first-boot seed), so
  the dashboards are imported by Grafana's file provider, which has no
  per-dashboard folder option and puts them in General. The annotation described
  a path the boards never take.
- validate_panels.py lives next to build.py: reads the panel PromQL out of the
  provisioned ConfigMap and queries Prometheus, so 'every panel returns data' is
  a command, not a claim. 55/55 targets pass.
This commit is contained in:
Lance Walters 2026-10-27 01:40:15 -04:00
commit e63af123c5
6 changed files with 149 additions and 21 deletions

View file

@ -140,7 +140,7 @@ RPI_FS = 'instance="10.10.0.1:9100",mountpoint="/"'
runners = [
row("Runners & queue", 0),
stat("Runner pods Ready", [target('sum(kube_deployment_status_replicas_ready{namespace="forgejo",deployment=~"forgejo-runner-.*"})')],
stat("Runner pods Ready", [target('sum(kube_deployment_status_replicas_ready{namespace="forgejo",deployment=~"forgejo-runner-.*"}) or vector(0)')],
{"h": 5, "w": 4, "x": 0, "y": 1}, desc="replicas_ready summed across the three runner Deployments. Expected 3.",
thresholds=[{"color": "red", "value": None}, {"color": "yellow", "value": 2}, {"color": "green", "value": 3}]),
stat("Runner pods not Ready", [target('sum(kube_pod_status_ready{%s,condition="false"} == 1) or vector(0)' % RUN)],
@ -309,13 +309,13 @@ cnpg = [
# -------------------------------------------------------------- workloads -----
workloads = [
row("Cluster", 0),
stat("Nodes Ready", [target('count(kube_node_status_condition{condition="Ready",status="true"} == 1)')],
stat("Nodes Ready", [target('count(kube_node_status_condition{condition="Ready",status="true"} == 1) or vector(0)')],
{"h": 5, "w": 4, "x": 0, "y": 1}, thresholds=[{"color": "red", "value": None}, {"color": "yellow", "value": 2}, {"color": "green", "value": 3}]),
stat("Nodes with DiskPressure", [target('sum(kube_node_status_condition{condition="DiskPressure",status="true"} == 1) or vector(0)')],
{"h": 5, "w": 4, "x": 4, "y": 1},
desc="The taint that evicted Forgejo and pg-1 in the past. >0 here is an incident, not a warning.",
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]),
stat("Pending pods", [target('sum(kube_pod_status_phase{phase="Pending"} == 1)')],
stat("Pending pods", [target('sum(kube_pod_status_phase{phase="Pending"} == 1) or vector(0)')],
{"h": 5, "w": 4, "x": 8, "y": 1},
desc="Pods that cannot be scheduled — usually an unschedulable taint or an exhausted resource request.",
thresholds=[{"color": "green", "value": None}, {"color": "red", "value": 1}]),
@ -323,7 +323,7 @@ workloads = [
{"h": 5, "w": 4, "x": 12, "y": 1},
desc="blackbox-exporter probes of http://10.10.0.2:8081/ and :8084/ (monitoring/controllers/home/gateway-probe.yaml). 2 = both internal services answering.",
thresholds=[{"color": "red", "value": None}, {"color": "yellow", "value": 1}, {"color": "green", "value": 2}]),
stat("PVCs bound", [target('sum(kube_persistentvolumeclaim_status_phase{phase="Bound"} == 1)')],
stat("PVCs bound", [target('sum(kube_persistentvolumeclaim_status_phase{phase="Bound"} == 1) or vector(0)')],
{"h": 5, "w": 4, "x": 16, "y": 1}),
stat("PVC capacity requested", [target('sum(kube_persistentvolumeclaim_resource_requests_storage_bytes)')],
{"h": 5, "w": 4, "x": 20, "y": 1}, unit="bytes",
@ -409,8 +409,13 @@ for uid, panels in PANELS.items():
"name": "grafana-dashboard-" + uid,
"namespace": "monitoring",
"labels": {"grafana_dashboard": "1", "app.kubernetes.io/part-of": "homelab-dashboards"},
"annotations": {"grafana_folder": "Homelab",
"homelab.siriusdevops.com/managed-by": "monitoring/controllers/home/dashboards/build.py"},
# No grafana_folder annotation: the sidecar's API-backed import cannot
# authenticate (Grafana's live admin password is the out-of-band one,
# not monitoring/grafana-admin — that Secret is only the first-boot
# seed), so the dashboards are imported by Grafana's *file* provider,
# which ignores per-dashboard folder annotations and puts every board
# in General next to the chart's own 28. Verified in grafana.db.
"annotations": {"homelab.siriusdevops.com/managed-by": "monitoring/controllers/home/dashboards/build.py"},
},
"data": {uid + ".json": json.dumps(d, indent=2) + "\n"},
}
@ -422,8 +427,7 @@ for uid, panels in PANELS.items():
# hand-rolled YAML emitter: keeps the JSON block literal and diffable
f.write("apiVersion: v1\nkind: ConfigMap\nmetadata:\n name: %s\n namespace: monitoring\n" % doc["metadata"]["name"])
f.write(" labels:\n grafana_dashboard: \"1\"\n app.kubernetes.io/part-of: homelab-dashboards\n")
f.write(" annotations:\n grafana_folder: Homelab\n")
f.write(" homelab.siriusdevops.com/managed-by: monitoring/controllers/home/dashboards/build.py\n")
f.write(" annotations:\n homelab.siriusdevops.com/managed-by: monitoring/controllers/home/dashboards/build.py\n")
f.write("data:\n %s.json: |\n" % uid)
for line in doc["data"][uid + ".json"].rstrip("\n").split("\n"):
f.write(" " + line + "\n")