monitoring: custom Forgejo runner, CNPG and workload dashboards from git
Dashboards (uid forgejo-runners, cnpg-postgres, home-lab-workloads) live as ConfigMaps generated from monitoring/controllers/home/dashboards/build.py and are loaded by the kube-prometheus-stack grafana sidecar. Postgres was not scraped at all before this: add a hand-written PodMonitor per CNPG cluster (release=kube-prometheus-stack, which is what this Prometheus's podMonitorSelectorNilUsesHelmValues default requires) plus spec.monitoring.customQueriesConfigMap on both Clusters. enablePodMonitor stays false — deprecated in CNPG 1.27 and it gives no control over labels. pg-actions-queries.yaml adds the Forgejo Actions queue/outcome/last_online metrics that only the forgejo database can answer. prometheus-node-exporter is no longer pinned to siriussec: the arm64 runner's jobs are host containers on rpi, so the Pi's root filesystem is the disk that matters there and kubelet cannot see it. docs/monitoring-dashboards.md documents the PromQL, the exporter GRANT and the known unknowns (arm64 per-job breakdown, hostPath PVs have no kubelet volume stats, single-instance replication, no backups).
This commit is contained in:
parent
de30bc43e7
commit
9e851f4dfe
15 changed files with 4400 additions and 5 deletions
111
apps/base/forgejo/pg-actions-queries.yaml
Normal file
111
apps/base/forgejo/pg-actions-queries.yaml
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
# Custom CNPG monitoring queries for Forgejo's Actions tables.
|
||||
#
|
||||
# Why this ConfigMap exists: Forgejo's Actions queue lives in PostgreSQL, not in
|
||||
# any exporter. `action_run_job` is the only place that knows how many jobs are
|
||||
# waiting for a runner and how the last N runs ended, so the runner dashboard
|
||||
# reads it through CNPG's built-in metrics exporter (`:9187`) instead of
|
||||
# inventing a new exporter.
|
||||
#
|
||||
# How it is wired: `Cluster/pg` lists this ConfigMap under
|
||||
# `spec.monitoring.customQueriesConfigMap` (alongside the operator's own
|
||||
# `cnpg-default-monitoring`), so every query here runs on the cluster's *main*
|
||||
# database — `forgejo` for this cluster, per CNPG's initdb.database rule — and is
|
||||
# exported as `cnpg_<name>_<column>` on the instance's metrics port.
|
||||
#
|
||||
# Privileges: CNPG runs custom queries as the `cnpg_metrics_exporter` role
|
||||
# (pg_monitor, NOT superuser). That role cannot read Forgejo's tables until it
|
||||
# is granted, and the grant is a database-side step that cannot live in this
|
||||
# file. When the dashboard shows an empty queue metric, run:
|
||||
#
|
||||
# GRANT USAGE ON SCHEMA public TO cnpg_metrics_exporter;
|
||||
# GRANT SELECT ON action_run_job, action_task,
|
||||
# action_runner TO cnpg_metrics_exporter;
|
||||
#
|
||||
# (see docs/monitoring-dashboards.md for the exact kubectl one-liner).
|
||||
#
|
||||
# Semantics, verified against this instance rather than guessed (task t_c45b2d73):
|
||||
# action_run_job.status / action_run.status: 1 = success, 2 = failure,
|
||||
# 3 = cancelled, 4 = skipped. Cross-checked against
|
||||
# GET /api/v1/repos/sirius/onionwire/actions/runs, where DB run 1189
|
||||
# (status 1) reports conclusion "success" and run 1191 (status 2) "failure".
|
||||
# A job that has not started yet carries started = 0; a job that has not
|
||||
# finished carries stopped = 0. Rows for skipped jobs never start, never stop
|
||||
# and are kept forever, so queue depth deliberately excludes status 4 —
|
||||
# otherwise the queue would read "3" at all times with nothing queued.
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: forgejo-actions-queries
|
||||
namespace: forgejo
|
||||
data:
|
||||
queries: |
|
||||
# Queue depth: jobs handed to a runner that have not started, plus the age
|
||||
# of the oldest of them. Always returns exactly one row, so the panel shows
|
||||
# a hard 0 instead of "No data" when the queue is empty.
|
||||
actions_queue:
|
||||
query: |
|
||||
SELECT count(*) AS depth
|
||||
, COALESCE(max(EXTRACT(EPOCH FROM pg_catalog.now())::bigint - NULLIF(j.created, 0)), 0) AS oldest_pending_seconds
|
||||
FROM action_run_job j
|
||||
WHERE j.started = 0
|
||||
AND j.stopped = 0
|
||||
AND j.status <> 4
|
||||
metrics:
|
||||
- depth:
|
||||
usage: "GAUGE"
|
||||
description: "Jobs assigned to a runner that have not started yet"
|
||||
- oldest_pending_seconds:
|
||||
usage: "GAUGE"
|
||||
description: "Age in seconds of the oldest not-yet-started job"
|
||||
# Jobs currently executing (a runner picked them up and has not finished).
|
||||
actions_running:
|
||||
query: |
|
||||
SELECT count(*) AS total
|
||||
FROM action_run_job j
|
||||
WHERE j.started > 0
|
||||
AND j.stopped = 0
|
||||
metrics:
|
||||
- total:
|
||||
usage: "GAUGE"
|
||||
description: "Jobs currently running on a runner"
|
||||
# Job outcomes inside a rolling window. A rolling count (not a counter):
|
||||
# Forgejo prunes old rows, so rate() over a row count would lie; asking for
|
||||
# "stopped within the last hour/day" is always right.
|
||||
actions_jobs_window:
|
||||
query: |
|
||||
SELECT w.label AS window
|
||||
, s.status AS status
|
||||
, COALESCE((
|
||||
SELECT count(*)
|
||||
FROM action_run_job j
|
||||
WHERE j.status = s.status
|
||||
AND j.stopped > (EXTRACT(EPOCH FROM pg_catalog.now())::bigint - w.secs)
|
||||
), 0) AS total
|
||||
FROM (VALUES ('1h', 3600), ('24h', 86400)) AS w(label, secs)
|
||||
CROSS JOIN (VALUES (0), (1), (2), (3), (4)) AS s(status)
|
||||
metrics:
|
||||
- window:
|
||||
usage: "LABEL"
|
||||
description: "Rolling window: 1h or 24h"
|
||||
- status:
|
||||
usage: "LABEL"
|
||||
description: "1 success, 2 failure, 3 cancelled, 4 skipped"
|
||||
- total:
|
||||
usage: "GAUGE"
|
||||
description: "Jobs that finished inside the window with this status"
|
||||
# How long ago each runner last polled Forgejo. This is the only signal that
|
||||
# says "the runner process is alive" independently of the pod being Ready —
|
||||
# a runner that cannot reach the forge stays Running but goes stale here.
|
||||
actions_runners:
|
||||
query: |
|
||||
SELECT r.name AS runner
|
||||
, COALESCE(EXTRACT(EPOCH FROM pg_catalog.now())::bigint - NULLIF(r.last_online, 0), -1) AS last_online_seconds
|
||||
FROM action_runner r
|
||||
metrics:
|
||||
- runner:
|
||||
usage: "LABEL"
|
||||
description: "Runner name as registered with Forgejo"
|
||||
- last_online_seconds:
|
||||
usage: "GAUGE"
|
||||
description: "Seconds since the runner last polled (-1 = never)"
|
||||
Loading…
Reference in a new issue