Stack di Monitoring: Panoramica
Introduzione
La piattaforma Impronto Enterprise utilizza uno stack di monitoring cloud-native basato su kube-prometheus-stack, esteso con componenti custom per la visibilità a livello applicativo dei microservizi Moleculer.
Tutti i componenti risiedono nel namespace monitoring del cluster Kubernetes, separati dal namespace applicativo pos-enterprise.
Architettura Generale
┌─────────────────────────────────────────────────────────────┐
│ Grafana (porta 3000) │
│ Dashboard, Explore, Alerting UI │
└──────┬──────────────┬──────────────┬────────────────────────┘
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ Prometheus │ │ Loki │ │ Tempo │
│ (metriche)│ │ (log) │ │ (tracce) │
│ porta 9090│ │ porta 3100│ │ porta 3200│
└──────┬─────┘ └──────┬─────┘ └──────┬─────┘
│ │ │
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌──────────────────┐
│ Exporters │ │ Promtail │ │ OpenTelemetry │
│ & Targets │ │ (agente) │ │ Collector (OTLP)│
└────────────┘ └────────────┘ └──────────────────┘
Componenti Principali
| Componente | Versione | Ruolo | Namespace |
|---|---|---|---|
| Prometheus | 2.53+ | Raccolta e storage metriche (TSDB) | monitoring |
| Grafana | 11.x | Visualizzazione, dashboard, alerting | monitoring |
| Loki | 3.x | Aggregazione log (modalità SimpleScalable) | monitoring |
| Promtail | 3.x | Agente di raccolta log (DaemonSet) | monitoring |
| Tempo | 2.x | Distributed tracing backend | monitoring |
| Alertmanager | 0.27+ | Routing e deduplicazione alert | monitoring |
| kube-state-metrics | 2.x | Metriche sullo stato degli oggetti K8s | monitoring |
| node-exporter | 1.x | Metriche hardware/OS per nodo | monitoring |
Flusso Dati
Metriche (Prometheus)
- I pod Moleculer espongono metriche Prometheus sulla porta 3030 (
/metrics) - I
ServiceMonitordefiniscono i target di scraping nel namespacepos-enterprise - Prometheus esegue scrape ogni 15s (default) o 30s (servizi a basso traffico)
- Le metriche vengono conservate per 15 giorni (retention locale)
# Esempio ServiceMonitor per i nodi Moleculer
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: moleculer-services
namespace: monitoring
spec:
namespaceSelector:
matchNames: ["pos-enterprise"]
selector:
matchLabels:
app.kubernetes.io/part-of: impronto-enterprise
endpoints:
- port: metrics
interval: 15s
path: /metrics
Log (Loki + Promtail)
- I servizi Moleculer scrivono log JSON su stdout/stderr
- Promtail (DaemonSet) raccoglie i log dai container via
/var/log/pods/ - Promtail arricchisce con label:
namespace,pod,container,node_type - I log vengono inviati a Loki via push API
- Retention: 30 giorni (configurabile in
loki.yaml)
Tracce (Tempo)
- I servizi Moleculer instrumentati con OpenTelemetry inviano span via OTLP gRPC (porta 4317)
- Il Collector elabora e inoltra a Tempo
- Correlation:
traceIdincluso nei log strutturati per collegamento log-tracce in Grafana
Metriche Custom Moleculer
Il mixin health.mixin.js e il servizio infrastructure-monitor.service.js espongono metriche specifiche della piattaforma:
# Metriche di servizio
moleculer_action_duration_seconds{service, action, tenant}
moleculer_action_errors_total{service, action, error_type}
moleculer_action_requests_total{service, action, status}
# Metriche business
pos_orders_total{tenant, channel}
pos_active_sessions{tenant}
pos_sync_lag_seconds{tenant, device}
# Metriche infrastruttura custom
pos_mongodb_pool_size{cluster, database}
pos_redis_memory_used_bytes{instance}
pos_nats_reconnections_total{node}
Porte e Endpoint
| Servizio | Porta Interna | Porta Esterna (Ingress) | Path |
|---|---|---|---|
| Grafana | 3000 | 443 | grafana.platform.sellogic.cloud |
| Prometheus | 9090 | - | Accesso solo interno |
| Alertmanager | 9093 | - | Accesso solo interno |
| Loki | 3100 | - | Accesso solo interno |
| Tempo | 3200 / 4317 (OTLP) | - | Accesso solo interno |
| Health HTTP (pod) | 3001 | - | Vedi Health Check |
| Metrics (pod) | 3030 | - | /metrics |
Solo Grafana e accessibile dall'esterno tramite Ingress HTTPS. Prometheus, Loki e Alertmanager sono raggiungibili solo via kubectl port-forward o dalla VPN del team.
Risorse Utilizzate
Risorse allocate ai componenti di monitoring (valori di produzione):
| Componente | CPU Request | CPU Limit | Memory Request | Memory Limit | Storage |
|---|---|---|---|---|---|
| Prometheus | 500m | 2000m | 2Gi | 4Gi | 50Gi PVC |
| Grafana | 200m | 500m | 256Mi | 512Mi | 10Gi PVC |
| Loki (write) | 250m | 1000m | 512Mi | 1Gi | 20Gi PVC |
| Loki (read) | 250m | 1000m | 512Mi | 1Gi | - |
| Promtail | 100m | 200m | 128Mi | 256Mi | - |
| Alertmanager | 100m | 200m | 128Mi | 256Mi | 5Gi PVC |
| Tempo | 250m | 1000m | 512Mi | 1Gi | 30Gi PVC |
Totale approssimativo dello stack: ~1.7 CPU request, ~8 Gi RAM request.
Comandi Utili
# Verifica stato dei pod di monitoring
kubectl get pods -n monitoring
# Port-forward a Prometheus per query dirette
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090
# Port-forward a Grafana (se non raggiungibile via Ingress)
kubectl port-forward -n monitoring svc/prometheus-grafana 3000:80
# Verifica i target di scraping Prometheus
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-prometheus 9090:9090
# Poi aprire: http://localhost:9090/targets
# Verifica che Promtail stia raccogliendo log
kubectl logs -n monitoring daemonset/promtail --tail=50
# Stato di Alertmanager
kubectl port-forward -n monitoring svc/prometheus-kube-prometheus-alertmanager 9093:9093
Riferimenti Incrociati
- Dashboard Grafana: Guida Completa - Configurazione dashboard e query PromQL
- Sistema di Alerting - Configurazione Alertmanager e regole di alert
- Analisi Log con Loki - Query LogQL e analisi log strutturati
- Health Check e Probes - Sistema di health check per i servizi Moleculer