# What is the Prometheus Alert Lifecycle?

The **Prometheus alert lifecycle** describes the process alerts follow from creation to resolution, enabling effective monitoring and timely notifications. Prometheus generates alerts based on pre-defined rules, which are then processed and managed by systems like **Alertmanager**.

[ad-logs-small]

### Stages of the Alert Lifecycle

1. **Define Alert Rules**  
   Alerts are created using **alerting rules** in `prometheus.yml` or external rule files. Each rule specifies conditions to trigger an alert using PromQL.  
   Example:  
   ```yaml
   - alert: InstanceDown
     expr: up == 0
     for: 5m
     labels:
       severity: critical
     annotations:
       summary: "Instance {{ $labels.instance }} is down"
       description: "No response from {{ $labels.instance }} for 5 minutes"
   ```

2. **Alert Evaluation**  
   Prometheus evaluates alerting rules at its scrape interval. If the rule condition is true, the alert enters a **pending** state but remains silent during this phase.

3. **Firing Alerts**  
   When the condition persists for the specified `for` duration, the alert transitions to a **firing** state. Prometheus then sends the alert to Alertmanager, including metadata (e.g., labels and annotations).

4. **Routing and Notification**  
   Alertmanager routes alerts based on defined rules, determining the recipients and notification channels (e.g., email, Slack, PagerDuty).  
   Example configuration:  
   ```yaml
   route:
     group_by: ['alertname', 'severity']
     receiver: 'slack'
   receivers:
     - name: 'slack'
       slack_configs:
         - channel: '#alerts'
           text: "{{ .CommonAnnotations.summary }}"
   ```

5. **Resolution**  
   Once the alert condition is no longer true, Prometheus marks the alert as **resolved** and informs Alertmanager, which may notify users about the resolution.

---

### Lifecycle Summary

1. Define Rule →  
2. Evaluate Condition →  
3. Pending Alert →  
4. Firing Alert →  
5. Alertmanager Processing →  
6. Notification →  
7. Resolution

---

### Key Details

- **Pending State**: Alerts stay in this state until the `for` duration is met. No notifications are sent during this phase.
- **Firing State**: The alert is actively sent to Alertmanager for processing and notification.
- **Resolved State**: Alerts are marked resolved when the condition becomes false, and updates are sent to Alertmanager.
- **Expiration**: Resolved alerts that no longer match active rules are eventually purged from Prometheus.

---

Understanding and managing the alert lifecycle ensures that Prometheus monitoring is both reliable and actionable.

[ad-uptime]
