Skip to main content

Monitoring DAGs in Apache Airflow

SLAs, Alerts, Email, Webserver & Metrics πŸ“ˆπŸš¨β€‹

The Story: When Pipelines Go Silent​

Imagine you’ve built a perfect Airflow DAG.
It runs daily, processes business-critical data, and everyone trusts it.

One morning, dashboards are empty.
No errors. No emails. No alerts.

The DAG did run β€” but it finished 4 hours late.

That’s when you realize:

Scheduling is not enough. Monitoring is mandatory.

In production Airflow, monitoring DAGs is as important as writing them. This article explains how Airflow monitors DAGs, how to configure SLAs, alerts, email notifications, UI monitoring, and metrics, and how to do it professionally at scale.


What Does β€œMonitoring a DAG” Really Mean?​

Monitoring in Airflow answers five critical questions:

  1. Did the DAG run?
  2. Did it finish on time?
  3. Did any task fail or retry?
  4. Did performance degrade?
  5. Did anyone get notified?

Airflow provides multiple monitoring layers, not just one.


Monitoring Layers in Airflow​

LayerPurpose
SLADetects slow tasks
AlertsReacts to failures
EmailNotifies humans
Webserver UIVisual monitoring
MetricsLong-term observability

Each layer covers a different failure mode.


SLA Monitoring – Detecting β€œSlow Success”​

What Is an SLA in Airflow?​

An SLA (Service Level Agreement) defines how long a task is allowed to run.

πŸ“Œ Important:
An SLA does not fail the task.
It triggers an SLA miss event.


SLA Example in a DAG​

from airflow import DAG
from airflow.operators.bash import BashOperator
from datetime import datetime, timedelta

with DAG(
dag_id="sales_reporting",
start_date=datetime(2024, 1, 1),
schedule_interval="@daily",
catchup=False,
) as dag:

generate_report = BashOperator(
task_id="generate_report",
bash_command="sleep 120",
sla=timedelta(minutes=1),
)

Input​

ParameterValue
Task runtime120 seconds
SLA60 seconds

Output (SLA Miss)​

  • Task succeeds βœ…
  • SLA is missed ❌
  • SLA callback is triggered
  • Visible in Airflow UI β†’ Browse β†’ SLA Misses

SLA Best Practices​

βœ… Use SLAs only for business-critical tasks
❌ Do not add SLAs to every task
βœ… Combine SLAs with alert callbacks


Alerts & Callbacks – Reacting to Failures​

Airflow allows callbacks to react to events.

Common Callbacks​

CallbackTrigger
on_failure_callbackTask fails
on_success_callbackTask succeeds
sla_miss_callbackSLA missed

Failure Alert Example​

def notify_failure(context):
dag_id = context["dag"].dag_id
task_id = context["task_instance"].task_id
print(f"ALERT: {dag_id}.{task_id} failed")

task = BashOperator(
task_id="load_data",
bash_command="exit 1",
on_failure_callback=notify_failure,
)

Input​

EventValue
Task exit code1

Output​

ALERT: sales_reporting.load_data failed

πŸ“Œ In production, this callback usually sends:

  • Email
  • Slack message
  • PagerDuty alert

Email Alerts – The Simplest Notification Layer​

Email is built-in and widely used.


Email Configuration Example​

default_args = {
"email": ["data-team@example.com"],
"email_on_failure": True,
"email_on_retry": False,
}

with DAG(
dag_id="email_alert_dag",
default_args=default_args,
schedule_interval="@daily",
):
...

Input​

ConditionValue
Task stateFAILED

Output​

πŸ“§ Email sent with:

  • DAG ID
  • Task ID
  • Execution date
  • Log link

Email Best Practices​

❌ Avoid email floods
βœ… Email only on final failure
βœ… Combine email with chat alerts


Webserver UI – Real-Time Visual Monitoring​

The Airflow Web UI is the first monitoring tool most teams use.

Key UI Views for Monitoring​

ViewUse Case
DAGs ViewOverall health
Grid ViewTask state history
Graph ViewDependencies
Gantt ViewPerformance bottlenecks
SLA MissesSlow tasks

What the UI Tells You Instantly​

  • Which DAG is failing
  • Which task is retrying
  • Where time is being spent
  • Historical stability

πŸ“Œ The UI reads directly from the metadata database.


Metrics – Production-Grade Monitoring​

For serious environments, metrics are non-negotiable.

Airflow emits metrics via StatsD.


Common Airflow Metrics​

MetricMeaning
dagrun.durationDAG runtime
task.durationTask runtime
task.failuresFailure count
scheduler.heartbeatScheduler health

Example Metric Flow​

Airflow β†’ StatsD β†’ Prometheus β†’ Grafana

Input​

| Task runtime | 95 seconds |

Output (Metric)​

airflow.task.duration{dag="sales_reporting",task="generate_report"} 95

πŸ“Š This enables:

  • SLA trend analysis
  • Capacity planning
  • Early performance warnings

Putting It All Together – A Monitoring Strategy​

ScenarioMonitoring Layer
Task failedCallback + Email
DAG slowSLA + Metrics
Scheduler downMetrics
Manual investigationWeb UI

No single tool is enough. Monitoring is a system.


Common Monitoring Mistakes​

❌ Relying only on email
❌ Ignoring SLA misses
❌ No metrics in production
❌ Alert fatigue
❌ No ownership of alerts


Input & Output – Realistic Monitoring Scenario​

Input​

  • DAG runs daily
  • 20 tasks
  • SLA = 30 minutes
  • Email on failure
  • Metrics enabled

Output​

EventResult
Task failsEmail + alert
Task slowSLA miss logged
DAG slower over timeGrafana trend
Scheduler unhealthyOps alert

Summary πŸ§ β€‹

  • Monitoring is not optional in Airflow
  • SLAs detect slow success
  • Alerts react to failures
  • Email notifies humans
  • UI helps investigate
  • Metrics ensure long-term stability

Key Takeaways​

  • βœ… Use SLAs sparingly but meaningfully
  • βœ… Always configure failure callbacks
  • βœ… Email is a baseline, not a strategy
  • βœ… Metrics are required for production
  • βœ… Monitoring prevents silent failures

What’s Next? πŸš€β€‹

➑️ Task Retries & Error Handling in Airflow
(How retries work, backoff strategies, and failure design patterns)