🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

Monitoring and Alerting in Apache Airflow

đŸŸĸ Free Lesson

Advertisement

Monitoring and Alerting

Monitoring ArchitectureSchedulerMetrics sourceWorkersMetrics sourceWeb ServerMetrics sourceMetadata DBMetrics sourceStatsD/PromCollectionGrafanaVisualizationKey Metricsdag_run.success, task.run.duration, scheduler.heartbeatAlert ChannelsEmail {'>'} Slack {'>'} PagerDuty {'>'} Webhook (severity-based)StatsD for lightweight metrics; Prometheus for advanced querying

Architecture Diagram

Formal Definitions

Detailed Explanation

Why Monitoring Matters

Without proper monitoring, you won't know about problems until users complain. Proactive monitoring helps you detect issues before they impact business operations.

Key Insight: The goal of monitoring is to answer three questions: What happened? Why did it happen? How do I fix it?

Monitoring Stack Components

ComponentPurposeTool Options
Metrics CollectionGather performance dataStatsD, Prometheus
VisualizationDashboards and graphsGrafana, Kibana
AlertingNotify on issuesAlertmanager, PagerDuty
LoggingDetailed execution logsELK Stack, Loki
TracingTrack request flowsOpenTelemetry, Jaeger

Critical Metrics to Monitor

MetricWarning ThresholdCritical ThresholdImpact
Scheduler Lag> 60 seconds> 300 secondsTasks delayed
Task Failure Rate> 5%> 10%Data quality issues
Queue Depth> 50 tasks> 100 tasksResource exhaustion
Worker Memory> 80%> 95%OOM kills
Database Connections> 80%> 95%Connection failures

Prometheus Configuration

Custom Metrics Implementation

Grafana Dashboard Configuration

{
  "dashboard": {
    "title": "Airflow Overview",
    "panels": [
      {
        "title": "Task Success Rate",
        "type": "stat",
        "targets": [
          {
            "expr": "rate(airflow_task_success_total[5m]) / (rate(airflow_task_success_total[5m]) + rate(airflow_task_failure_total[5m]))",
            "legendFormat": "Success Rate"
          }
        ],
        "thresholds": [
          {"value": 0.95, "color": "green"},
          {"value": 0.9, "color": "yellow"},
          {"value": 0.8, "color": "red"}
        ]
      },
      {
        "title": "Task Duration",
        "type": "graph",
        "targets": [
          {
            "expr": "histogram_quantile(0.95, rate(airflow_task_duration_seconds_bucket[5m]))",
            "legendFormat": "P95 Duration"
          }
        ]
      },
      {
        "title": "Queue Depth",
        "type": "graph",
        "targets": [
          {
            "expr": "airflow_executor_queue_depth",
            "legendFormat": "Queued Tasks"
          }
        ]
      },
      {
        "title": "Scheduler Lag",
        "type": "stat",
        "targets": [
          {
            "expr": "airflow_scheduler_lag_seconds",
            "legendFormat": "Lag (seconds)"
          }
        ],
        "thresholds": [
          {"value": 60, "color": "green"},
          {"value": 300, "color": "yellow"},
          {"value": 600, "color": "red"}
        ]
      }
    ]
  }
}

Alert Severity Levels

SeverityResponse TimeEscalationAuto-resolve
Critical5 minutesImmediate pageNo
Warning30 minutes1 hour escalationPossible
InfoNext business dayNoneYes

Alert Best Practices

  1. Set meaningful thresholds — avoid alert fatigue from too many false positives
  2. Include context in alert messages — what failed, when, and impact
  3. Route alerts correctly — critical alerts to on-call, warnings to team channels
  4. Document runbooks — provide step-by-step resolution instructions
  5. Review alerts regularly — remove or adjust alerts that are no longer useful

Key Concepts Table

Metric CategoryExamplesCollection MethodAlert Threshold
SchedulerLag, parse timeStatsD/Prometheus> 5min lag
TasksSuccess rate, durationCallbacks< 95% success
QueueDepth, wait timeDatabase queries> 100 queued
ResourcesCPU, memory, diskSystem metrics> 85% utilization
DatabaseQuery time, connectionsSQLAlchemy> 100ms query
SLAMiss rateSLA callbacksAny SLA miss

Code Examples

Alert Rules Configuration

# prometheus/alert_rules.yml
groups:
  - name: airflow_alerts
    rules:
      - alert: AirflowSchedulerLagHigh
        expr: airflow_scheduler_lag_seconds > 300
        for: 5m
        labels:
          severity: warning
        annotations:
          summary: "Airflow scheduler lag is high"
          description: "Scheduler lag is {{ $value }} seconds"
      
      - alert: AirflowTaskFailureRateHigh
        expr: rate(airflow_task_failure_total[5m]) / rate(airflow_task_total[5m]) > 0.05
        for: 10m
        labels:
          severity: critical
        annotations:
          summary: "High task failure rate"
          description: "Task failure rate is {{ $value | humanizePercentage }}"
      
      - alert: AirflowQueueDepthHigh
        expr: airflow_executor_queue_depth > 100
        for: 15m
        labels:
          severity: warning
        annotations:
          summary: "High queue depth"
          description: "{{ $value }} tasks queued"
      
      - alert: AirflowDagRunStale
        expr: time() - airflow_dag_run_last_scheduling_decision > 3600
        for: 30m
        labels:
          severity: critical
        annotations:
          summary: "Stale DAG run detected"
          description: "DAG run has not been scheduled for {{ $value }} seconds"

Slack Alerting Integration

Monitoring Dashboard Script

Performance Metrics

Key Performance Indicators

KPITargetWarningCritical
Task Success Rate> 99%95-99%< 95%
Scheduler Lag< 60s60-300s> 300s
Avg Task Duration< 5min5-15min> 15min
Queue Depth< 5050-100> 100
MTTR< 15min15-30min> 30min
SLA Miss Rate0%< 1%> 1%

Alert Distribution

SeverityResponse TimeEscalationAuto-resolve
Critical5minImmediateNo
Warning30min1 hourPossible
InfoNext business dayNoneYes

See Also

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Airflow Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement