📢 Configuração de Alertas - Grafana
Guia para configurar alertas no Grafana e notificações via Slack/Email.
🚀 Configuração Inicial
1. Acessar Grafana
- Acesse: https://grafana.internut.com.br
- Login:
admin/Admin4C! - Vá em Alerting → Notification channels
2. Configurar Canal de Notificação
Email (SMTP)
- Alerting → Notification channels → Add channel
- Type: Email
- Name:
Email Alerts - Email addresses:
admin@internut.com.br,ops@internut.com.br - Send on all alerts: ✅
- Test → Send Test
- Save
Slack
- Alerting → Notification channels → Add channel
- Type: Slack
- Name:
Slack Alerts - Webhook URL:
https://hooks.slack.com/services/YOUR/WEBHOOK/URL - Obter em: https://api.slack.com/messaging/webhooks
- Channel:
#alerts(opcional) - Test → Send Test
- Save
📋 Alertas Recomendados
1. Serviço Indisponível
Configuração:
- Name: Service Unhealthy
- Query: up{job="csuite-services"} == 0
- Condition: WHEN last() OF query(A, 5m, now) IS BELOW 1
- For: 2m
- Notify: Email + Slack
Descrição:
Alerta quando um serviço fica indisponível por mais de 2 minutos.
2. Alta Latência
Configuração:
- Name: High Latency
- Query: http_request_duration_seconds{quantile="0.95"} > 1
- Condition: WHEN avg() OF query(A, 5m, now) IS ABOVE 1
- For: 5m
- Notify: Email + Slack
Descrição:
Alerta quando P95 latency excede 1 segundo por 5 minutos.
3. Alta Taxa de Erro
Configuração:
- Name: High Error Rate
- Query: rate(http_requests_total{status=~"5.."}[5m]) / rate(http_requests_total[5m])
- Condition: WHEN avg() OF query(A, 5m, now) IS ABOVE 0.05
- For: 5m
- Notify: Email + Slack
Descrição:
Alerta quando taxa de erro HTTP 5xx excede 5% por 5 minutos.
4. Alta Utilização de CPU
Configuração:
- Name: High CPU Usage
- Query: 100 - (avg(irate(container_cpu_usage_seconds_total[5m])) * 100)
- Condition: WHEN avg() OF query(A, 5m, now) IS ABOVE 80
- For: 10m
- Notify: Email
Descrição:
Alerta quando CPU excede 80% por 10 minutos.
5. Alta Utilização de Memória
Configuração:
- Name: High Memory Usage
- Query: container_memory_usage_bytes / container_spec_memory_limit_bytes * 100
- Condition: WHEN avg() OF query(A, 5m, now) IS ABOVE 85
- For: 10m
- Notify: Email
Descrição:
Alerta quando memória excede 85% por 10 minutos.
🔧 Configuração via API (Opcional)
Importar Alertas via API
# 1. Obter API Key do Grafana
# Configuration → API Keys → Add API Key
# Role: Admin
# Key: <api_key>
# 2. Importar alertas
curl -X POST \
-H "Authorization: Bearer <api_key>" \
-H "Content-Type: application/json" \
-d @grafana/alerts/service_unhealthy.json \
https://grafana.internut.com.br/api/alert-rules
📝 Templates de Mensagens
Email Template
Subject: [ALERT] {{ .GroupLabels.alertname }} - {{ .Status }}
{{ range .Alerts }}
Alert: {{ .Labels.alertname }}
Status: {{ .Status }}
Severity: {{ .Labels.severity }}
Service: {{ .Labels.service }}
Time: {{ .StartsAt }}
{{ .Annotations.description }}
{{ if .Annotations.runbook_url }}
Runbook: {{ .Annotations.runbook_url }}
{{ end }}
{{ end }}
Slack Template
{
"text": "🚨 *{{ .GroupLabels.alertname }}*",
"attachments": [
{
"color": "{{ if eq .Status \"firing\" }}danger{{ else }}good{{ end }}",
"fields": [
{
"title": "Status",
"value": "{{ .Status }}",
"short": true
},
{
"title": "Service",
"value": "{{ .Labels.service }}",
"short": true
}
]
}
]
}
✅ Checklist de Configuração
- [ ] Canal de Email configurado e testado
- [ ] Canal de Slack configurado e testado (opcional)
- [ ] 5 alertas básicos criados
- [ ] Alertas testados manualmente
- [ ] Runbooks criados para cada alerta
- [ ] Escalação configurada (se necessário)
🔗 Recursos
- Grafana Alerting Docs: https://grafana.com/docs/grafana/latest/alerting/
- Slack Webhooks: https://api.slack.com/messaging/webhooks
- Prometheus Alerts: https://prometheus.io/docs/alerting/latest/alerting_rules/
Última atualização: 2025-12-06