# GENERATED by monitoring/controllers/home/dashboards/build.py — edit the script, not this file. # Provisioned by the kube-prometheus-stack dashboard sidecar (label grafana_dashboard=1, # NAMESPACE=ALL), so it wins over any UI edit. Dashboard uid: cnpg-postgres apiVersion: v1 kind: ConfigMap metadata: name: grafana-dashboard-cnpg-postgres 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 data: cnpg-postgres.json: | { "uid": "cnpg-postgres", "title": "CNPG Postgres", "description": "Metrics come from CNPG's instance-manager exporter on :9187, scraped by the per-cluster PodMonitors in apps/base/*/podmonitor.yaml.", "tags": [ "homelab", "postgres", "cnpg" ], "timezone": "browser", "editable": true, "graphTooltip": 1, "schemaVersion": 39, "version": 1, "refresh": "30s", "time": { "from": "now-6h", "to": "now" }, "annotations": { "list": [ { "builtIn": 1, "datasource": { "type": "grafana", "uid": "-- Grafana --" }, "enable": true, "hide": true, "iconColor": "rgba(0, 211, 255, 1)", "name": "Annotations & Alerts", "type": "dashboard" } ] }, "links": [], "templating": { "list": [ { "name": "namespace", "label": "Postgres cluster (namespace)", "type": "query", "datasource": { "type": "prometheus", "uid": "prometheus" }, "refresh": 1, "includeAll": true, "multi": true, "allValue": ".*", "current": { "selected": true, "text": [ "All" ], "value": [ "$__all" ] }, "options": [], "query": { "query": "label_values(cnpg_collector_up, namespace)", "refId": "PromQLNamespace" } } ] }, "panels": [ { "id": 23, "type": "row", "title": "Cluster health", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 0 }, "panels": [] }, { "id": 24, "type": "stat", "title": "Instances up", "description": "cnpg_collector_up from the instance manager (:9187) \u2014 1 = PostgreSQL answering.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 0, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "min by (namespace) (cnpg_collector_up{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": null }, { "color": "green", "value": 1 } ] } }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 25, "type": "stat", "title": "Nodes used / instances", "description": "1 with instances: 1 \u2014 no HA. Documented as a known limit, not a fault.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 4, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_collector_nodes_used{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": null }, { "color": "green", "value": 1 } ] } }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 26, "type": "stat", "title": "Connections used", "description": "pg_stat_activity backends, all states.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 8, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (cnpg_backends_total{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": null }, { "color": "green", "value": 1 } ] } }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 27, "type": "stat", "title": "Connections / max_connections", "description": "Used against the server's own max_connections setting, so it stays right if the setting changes.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 12, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "100 * sum by (namespace) (cnpg_backends_total{namespace=~\"$namespace\"}) / max by (namespace) (cnpg_pg_settings_setting{namespace=~\"$namespace\",name=\"max_connections\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "yellow", "value": 70 }, { "color": "red", "value": 90 } ] }, "unit": "percent" }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 28, "type": "stat", "title": "Manual switchover required", "description": "1 = the operator is asking for a manual switchover (e.g. after a fencing event).", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 16, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_collector_manual_switchover_required{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "green", "value": null }, { "color": "red", "value": 1 } ] } }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 29, "type": "stat", "title": "Last available backup", "description": "0 = never. There are NO Backup/Cluster backup resources in this cluster (verified: `kubectl get backups.postgresql.cnpg.io -A` is empty), so a 0 here is the honest answer, not a broken panel.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 5, "w": 4, "x": 20, "y": 1 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_collector_last_available_backup_timestamp{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "color": { "mode": "thresholds" }, "mappings": [], "thresholds": { "mode": "absolute", "steps": [ { "color": "red", "value": null }, { "color": "green", "value": 1 } ] }, "unit": "dateTimeAsIso" }, "overrides": [] }, "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": [ "lastNotNull" ], "fields": "", "values": false }, "textMode": "auto", "justifyMode": "auto" } }, { "id": 30, "type": "row", "title": "Throughput", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 6 }, "panels": [] }, { "id": 31, "type": "timeseries", "title": "Transactions/s \u2014 commit vs rollback", "description": "From pg_stat_database, which Forgejo's connection pool drives directly.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 12, "x": 0, "y": 7 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (rate(cnpg_pg_stat_database_xact_commit{namespace=~\"$namespace\"}[5m]))", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}} commit" }, { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (rate(cnpg_pg_stat_database_xact_rollback{namespace=~\"$namespace\"}[5m]))", "refId": "B", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}} rollback" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "ops" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 32, "type": "timeseries", "title": "Commit share", "description": "Commit / (commit + rollback). clamp_min keeps a quiet database from rendering NaN.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 6, "x": 12, "y": 7 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum(rate(cnpg_pg_stat_database_xact_commit{namespace=~\"$namespace\"}[5m])) / clamp_min(sum(rate(cnpg_pg_stat_database_xact_commit{namespace=~\"$namespace\"}[5m])) + sum(rate(cnpg_pg_stat_database_xact_rollback{namespace=~\"$namespace\"}[5m])), 0.0000001)", "refId": "A", "editorMode": "code", "range": true, "instant": false } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "percentunit" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 33, "type": "timeseries", "title": "Cache hit ratio", "description": "shared_buffers hit ratio. A lab database with 256Mi request will sit high; a drop means the working set outgrew the buffers.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 6, "x": 18, "y": 7 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (rate(cnpg_pg_stat_database_blks_hit{namespace=~\"$namespace\"}[5m])) / clamp_min(sum by (namespace) (rate(cnpg_pg_stat_database_blks_hit{namespace=~\"$namespace\"}[5m])) + sum by (namespace) (rate(cnpg_pg_stat_database_blks_read{namespace=~\"$namespace\"}[5m])), 0.0000001)", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "percentunit" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 34, "type": "row", "title": "Errors and pressure", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 15 }, "panels": [] }, { "id": 35, "type": "timeseries", "title": "Deadlocks (24h increase)", "description": "increase() on a counter that exists on every database, so a quiet DB renders a hard 0 rather than 'No data'.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 0, "y": 16 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (increase(cnpg_pg_stat_database_deadlocks{namespace=~\"$namespace\"}[24h]))", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "short" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 36, "type": "timeseries", "title": "Temp bytes/s", "description": "Spill to disk from sorts/hashes that did not fit work_mem. Non-zero during Forgejo Actions index scans is expected.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 8, "y": 16 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (rate(cnpg_pg_stat_database_temp_bytes{namespace=~\"$namespace\"}[5m]))", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "Bps" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 37, "type": "timeseries", "title": "Longest transaction age", "description": "Longest open transaction (pg_stat_activity.xact_start). The CNPG default query set exposes transaction age, not per-statement query age \u2014 see docs.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 16, "y": 16 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_backends_max_tx_duration_seconds{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "s" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 38, "type": "row", "title": "Size, WAL, replication", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 24 }, "panels": [] }, { "id": 39, "type": "timeseries", "title": "Database size", "description": "pg_database_size. Both PVs are 10Gi (forgejo/pg) and 5Gi (sirius-growth/portal) \u2014 this is the trend that fills them.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 0, "y": 25 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace, datname) (cnpg_pg_database_size_bytes{namespace=~\"$namespace\",datname!~\"template.*|postgres\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}/{{datname}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "bytes" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 40, "type": "timeseries", "title": "WAL generation", "description": "Bytes of WAL written per second. On a cluster with no backups, WAL has nothing archiving it away.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 8, "y": 25 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "sum by (namespace) (rate(cnpg_collector_wal_bytes{namespace=~\"$namespace\"}[5m]))", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "Bps" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 41, "type": "timeseries", "title": "WAL archiver failures", "description": "pg_stat_archiver.failed_count. Archiving is not configured on either cluster (no ObjectStore/backup), so treat non-zero here as 'something was attempted and failed'.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 8, "w": 8, "x": 16, "y": 25 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_pg_stat_archiver_failed_count{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "short" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 42, "type": "row", "title": "Replication (single instance \u2014 panels are honest about it)", "collapsed": false, "gridPos": { "h": 1, "w": 24, "x": 0, "y": 33 }, "panels": [] }, { "id": 43, "type": "timeseries", "title": "Replication lag", "description": "0 on the primary with no standby. With instances: 1 this metric is structurally zero, not evidence that replication is healthy.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 6, "w": 8, "x": 0, "y": 34 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_pg_replication_lag{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}}" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "s" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 44, "type": "timeseries", "title": "Streaming replicas / in recovery", "description": "Both clusters run instances: 1, so 0 streaming replicas and in_recovery=0 is the correct reading. A future replica would light these up with no dashboard change.", "datasource": { "type": "prometheus", "uid": "prometheus" }, "gridPos": { "h": 6, "w": 8, "x": 8, "y": 34 }, "targets": [ { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_pg_replication_streaming_replicas{namespace=~\"$namespace\"})", "refId": "A", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}} streaming" }, { "datasource": { "type": "prometheus", "uid": "prometheus" }, "expr": "max by (namespace) (cnpg_pg_replication_in_recovery{namespace=~\"$namespace\"})", "refId": "B", "editorMode": "code", "range": true, "instant": false, "legendFormat": "{{namespace}} in recovery" } ], "fieldConfig": { "defaults": { "custom": { "lineWidth": 1, "fillOpacity": 0, "showPoints": "never" }, "color": { "mode": "palette-classic" }, "unit": "short" }, "overrides": [] }, "options": { "legend": { "displayMode": "list", "placement": "bottom", "calcs": [ "lastNotNull" ] }, "tooltip": { "mode": "multi", "sort": "desc" } } }, { "id": 45, "type": "text", "title": "Known unknowns on the CNPG board", "gridPos": { "h": 8, "w": 24, "x": 0, "y": 40 }, "options": { "mode": "markdown", "code": { "language": "plaintext", "showLineNumbers": false, "showMiniMap": false }, "content": "- **No backups exist.** `kubectl get backups.postgresql.cnpg.io -A` returns nothing; neither Cluster\n declares `spec.backup`. The \"Last available backup\" stat therefore reads 0 (never) \u2014 that is the\n real state, not a missing metric.\n- **Single instance.** Both clusters run `instances: 1`, so replication lag / streaming replicas /\n in recovery are structurally zero. The panels show the zero and say so instead of hiding them.\n- **Query age vs transaction age.** CNPG's default query set exposes\n `cnpg_backends_max_tx_duration_seconds` (transaction age). Per-statement `query_start` age is not in\n the default set; adding it would need another custom query in the cluster's\n `customQueriesConfigMap`.\n- **Permissions.** Custom queries run as `cnpg_metrics_exporter`, not superuser. See\n docs/monitoring-dashboards.md for the GRANT the Forgejo Actions metrics need.\n" } } ] }