Alertas Grafana

📢 Configuração de Alertas - Grafana

Guia para configurar alertas no Grafana e notificações via Slack/Email.


🚀 Configuração Inicial

1. Acessar Grafana

  1. Acesse: https://grafana.internut.com.br
  2. Login: admin / Admin4C!
  3. Vá em AlertingNotification channels

2. Configurar Canal de Notificação

Email (SMTP)

  1. AlertingNotification channelsAdd channel
  2. Type: Email
  3. Name: Email Alerts
  4. Email addresses: admin@internut.com.br,ops@internut.com.br
  5. Send on all alerts:
  6. TestSend Test
  7. Save

Slack

  1. AlertingNotification channelsAdd channel
  2. Type: Slack
  3. Name: Slack Alerts
  4. Webhook URL: https://hooks.slack.com/services/YOUR/WEBHOOK/URL
  5. Obter em: https://api.slack.com/messaging/webhooks
  6. Channel: #alerts (opcional)
  7. TestSend Test
  8. 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


🔗 Recursos


Última atualização: 2025-12-06

🔊 Text-to-Speech

1.0x
1.0
Pronto para reproduzir