🔥 Prometheus
🎯 Visão Geral
Prometheus é o sistema de monitoramento e alerta do cluster AKS, coletando métricas de todos os componentes Kubernetes.
📦 Deployment
\\yaml
Namespace: observability
StatefulSet: prometheus-kube-prometheus-stack-prometheus
Image: quay.io/prometheus/prometheus:v3.9.1
Replicas: 1
Status: 1/1 Running
\\
💾 Storage
\\yaml
Storage: EmptyDir (ephemeral)
Retention: 15 dias
Storage Path: /prometheus
\\
⚠️ Nota: Dados são perdidos ao reiniciar o pod (sem PVC configurado).
Planejado: Migrar para Azure Disk com PVC.
🌐 Acesso
Via Port-Forward
\\ash
kubectl port-forward -n observability svc/prometheus-operated 9090:9090
\\
Acesse: http://localhost:9090
📊 Targets Monitorados
Kubernetes Components
- kube-apiserver — API Server do K8s
- kubelet — Agent nos nodes
- kube-controller-manager — Controller Manager
- kube-scheduler — Scheduler
- coredns — DNS interno
Node Exporters
- node-exporter — Métricas do sistema operacional
- CPU, memória, disco, rede
- Filesystem usage
- Network stats
Application Metrics
- cadvisor — Métricas de containers
- kube-state-metrics — Estado dos objetos K8s
Custom Exporters
- kubecost-cost-analyzer — Métricas de custo
📈 Métricas Principais
Cluster Health
\\promql
Número de nodes prontos
sum(kube_node_status_condition{condition="Ready",status="true"})
Pods em execução por namespace
sum(kube_pod_status_phase{phase="Running"}) by (namespace)
Capacidade de CPU disponível
sum(kube_node_status_allocatable{resource="cpu"})
\\
Resource Usage
\\promql
CPU usage por namespace
sum(rate(container_cpu_usage_seconds_total{namespace!=""}[5m])) by (namespace)
Memória usada por pod
sum(container_memory_working_set_bytes{namespace!=""}) by (pod, namespace)
Disk I/O
rate(node_disk_read_bytes_total[5m])
\\
Network
\\promql
Bytes recebidos por interface
rate(node_network_receive_bytes_total[5m])
Bytes transmitidos por interface
rate(node_network_transmit_bytes_total[5m])
\\
🚨 Alertas Configurados
Critical Alerts
| Alerta | Condição | Severidade |
|---|---|---|
| NodeDown | Node offline > 5min | Critical |
| KubePodCrashLooping | Restart > 5x em 10min | Critical |
| KubePodNotReady | Pod NotReady > 15min | Warning |
Resource Alerts
| Alerta | Condição | Severidade |
|---|---|---|
| NodeMemoryPressure | Memória > 90% | Warning |
| NodeDiskPressure | Disco > 85% | Warning |
| PodCPUThrottling | Throttling > 25% | Warning |
Verificar alertas ativos
\\ash
Via API
curl http://localhost:9090/api/v1/alerts
Via Grafana
Menu: Alerting → Alert Rules
\\
🔧 Service Discovery
Prometheus descobre targets automaticamente via:
Kubernetes SD
\\yaml
- role: node # Nodes do cluster
- role: pod # Pods com annotations
- role: service # Services com labels
- role: endpoints # Endpoints
\\
Annotations para Auto-Discovery
\\yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8080"
prometheus.io/path: "/metrics"
\\
📊 Retention Policy
\\yaml
Retention Time: 15 dias
Max Size: Sem limite (controlado pelo EmptyDir)
\\
Após 15 dias: Métricas antigas são automaticamente deletadas.
🔧 Troubleshooting
Prometheus não coleta métricas
\\ash
Ver targets ativos
curl http://localhost:9090/api/v1/targets
Verificar logs
kubectl logs -n observability statefulset/prometheus-kube-prometheus-stack-prometheus -f
\\
Target aparece como DOWN
\\ash
Testar conectividade do Prometheus
kubectl exec -n observability statefulset/prometheus-kube-prometheus-stack-prometheus -- wget -qO- http://
\\
Consulta muito lenta
- Reduzir intervalo de tempo
- Usar aggregations (\sum\, \vg)
- Verificar cardinality das séries
📚 Queries Úteis
Top 10 pods por CPU
\\promql
topk(10, sum(rate(container_cpu_usage_seconds_total{namespace!=""}[5m])) by (pod, namespace))
\\
Top 10 pods por memória
\\promql
topk(10, sum(container_memory_working_set_bytes{namespace!=""}) by (pod, namespace))
\\
Pods reiniciando
\\promql
sum(rate(kube_pod_container_status_restarts_total[5m])) by (pod, namespace) > 0
\\