97 lines
3.5 KiB
YAML
97 lines
3.5 KiB
YAML
# =====================================================================
|
|
# 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."
|
|
}
|