This commit is contained in:
alessandro barucci
2026-08-09 17:03:02 +02:00
parent 5997a56cb3
commit 1a2cca2cd2
11 changed files with 1334 additions and 4 deletions

View File

@@ -0,0 +1,96 @@
# =====================================================================
# Monitoring per CloudNativePG (CNPG)
#
# Applica con: kubectl apply -f 02-cnpg-monitoring.yaml
#
# Prerequisiti:
# - CNPG operator già installato (namespace tipico: cnpg-system)
# - kube-prometheus-stack già installato nel namespace "monitoring"
# con podMonitorSelectorNilUsesHelmValues: false (vedi file 01),
# così Prometheus scopre PodMonitor in TUTTI i namespace.
# =====================================================================
# ---------------------------------------------------------------------
# 1) PodMonitor per l'operatore CNPG stesso
# (metriche interne: reconcile loop, controller-runtime, porta 8080)
# ---------------------------------------------------------------------
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: cnpg-operator
namespace: cnpg-system
labels:
release: kube-prometheus-stack
spec:
selector:
matchLabels:
app.kubernetes.io/name: cloudnative-pg
podMetricsEndpoints:
- port: metrics
interval: 30s
---
# ---------------------------------------------------------------------
# 2) PodMonitor generico per TUTTI i cluster Postgres gestiti da CNPG
#
# Nota: se preferisci il metodo "automatico" (enablePodMonitor: true
# nella risorsa Cluster), questo PodMonitor manuale NON serve per
# quel cluster specifico — ma il manuale è consigliato dalla doc
# ufficiale CNPG perché dà controllo esplicito sul lifecycle,
# indipendente dal singolo Cluster CR.
#
# Il selettore usa la label standard "cnpg.io/cluster" che CNPG
# applica automaticamente a tutti i pod di ogni cluster gestito,
# quindi UN SOLO PodMonitor copre TUTTI i cluster Postgres presenti
# nel namespace target (adatta matchExpressions se i tuoi cluster
# vivono in namespace diversi: serve un PodMonitor per namespace,
# oppure passa a un selector cross-namespace via namespaceSelector).
# ---------------------------------------------------------------------
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: cnpg-clusters
namespace: monitoring
labels:
release: kube-prometheus-stack
spec:
namespaceSelector:
any: true # scropa i pod CNPG in QUALSIASI namespace
selector:
matchExpressions:
- key: cnpg.io/cluster
operator: Exists
podMetricsEndpoints:
- port: metrics # exporter per-istanza, porta 9187
interval: 30s
scrapeTimeout: 10s
path: /metrics
---
# ---------------------------------------------------------------------
# 3) Import automatico dashboard CNPG ufficiale (grafana.com ID 20417)
# tramite sidecar dashboards di Grafana (già incluso nel chart
# kube-prometheus-stack). Basta un ConfigMap con la label
# "grafana_dashboard: '1'" nel namespace di Grafana.
#
# In alternativa più semplice: Grafana UI -> Dashboards -> Import
# -> inserisci ID 20417 -> seleziona datasource Prometheus.
# ---------------------------------------------------------------------
apiVersion: v1
kind: ConfigMap
metadata:
name: cnpg-grafana-dashboard
namespace: monitoring
labels:
grafana_dashboard: "1"
data:
cnpg-dashboard.json: |
{
"annotations": {"list": []},
"title": "CloudNativePG (import via ID 20417)",
"__inputs": [],
"__requires": [],
"schemaVersion": 39,
"panels": [],
"_comment": "Placeholder: sostituisci con l'export JSON completo scaricato da https://grafana.com/grafana/dashboards/20417 per avere la dashboard reale, oppure importa manualmente da Grafana UI usando l'ID."
}