Metrics Configuration¶
Airflow can be set up to send metrics to StatsD or OpenTelemetry.
Setup - StatsD¶
To use StatsD you must first install the required packages:
pip install 'apache-airflow[statsd]'
then add the following lines to your configuration file e.g. airflow.cfg
[metrics]
statsd_on = True
statsd_host = localhost
statsd_port = 8125
statsd_prefix = airflow
If you want to use a custom StatsD client instead of the default one provided by Airflow,
the following key must be added to the configuration file alongside the module path of your
custom StatsD client. This module must be available on your PYTHONPATH
.
[metrics]
statsd_custom_client_path = x.y.customclient
See Modules Management for details on how Python and Airflow manage modules.
Setup - OpenTelemetry¶
To use OpenTelemetry you must first install the required packages:
pip install 'apache-airflow[otel]'
Add the following lines to your configuration file e.g. airflow.cfg
[metrics]
otel_on = False
otel_host = localhost
otel_port = 8889
otel_prefix = airflow
otel_interval_milliseconds = 30000 # The interval between exports, defaults to 60000
otel_ssl_active = False
Enable Https¶
To establish an HTTPS connection to the OpenTelemetry collector
You need to configure the SSL certificate and key within the OpenTelemetry collector’s config.yml
file.
receivers:
otlp:
protocols:
http:
endpoint: 0.0.0.0:4318
tls:
cert_file: "/path/to/cert/cert.crt"
key_file: "/path/to/key/key.pem"
Allow/Block Lists¶
If you want to avoid sending all the available metrics, you can configure an allow list or block list of prefixes to send or block only the metrics that start with the elements of the list:
[metrics]
metrics_allow_list = scheduler,executor,dagrun
[metrics]
metrics_block_list = scheduler,executor,dagrun
Rename Metrics¶
If you want to redirect metrics to a different name, you can configure the stat_name_handler
option
in [metrics]
section. It should point to a function that validates the stat name, applies changes
to the stat name if necessary, and returns the transformed stat name. The function may look as follows:
def my_custom_stat_name_handler(stat_name: str) -> str:
return stat_name.lower()[:32]
Metric Descriptions¶
Counters¶
Name |
Description |
---|---|
|
Number of started |
|
Number of ended |
|
Number of failed Heartbeats for a |
|
Number of |
|
Number of |
|
Operator |
|
Operator |
|
Operator |
|
Operator |
|
Overall task instances failures. Metric with dag_id and task_id tagging. |
|
Overall task instances successes. Metric with dag_id and task_id tagging. |
|
Number of previously succeeded task instances. Metric with dag_id and task_id tagging. |
|
Zombie tasks killed. Metric with dag_id and task_id tagging. |
|
Scheduler heartbeats |
|
Relative number of currently running DAG parsing processes (ie this delta is negative when, since the last metric was sent, processes have completed). Metric with file_path and action tagging. |
|
Number of file processors that have been killed due to taking too long. Metric with file_path tagging. |
|
Number of SLA callbacks received |
|
Number of non-SLA callbacks received |
|
Number of times we’ve scanned the filesystem and queued all existing dags |
|
(DEPRECATED) same behavior as |
|
Number of stalled |
|
Number of failures loading any DAG files |
|
Number of tasks killed externally. Metric with dag_id and task_id tagging. |
|
Number of Orphaned tasks cleared by the Scheduler |
|
Number of Orphaned tasks adopted by the Scheduler |
|
Count of times a scheduler process tried to get a lock on the critical section (needed to send tasks to the executor) and found it locked by another process. |
|
Number of SLA misses. Metric with dag_id and task_id tagging. |
|
Number of failed SLA miss callback notification attempts. Metric with dag_id and func_name tagging. |
|
Number of failed SLA miss email notification attempts. Metric with dag_id tagging. |
|
Number of started task in a given dag. Similar to <job_name>_start but for task |
|
Number of started task in a given dag. Similar to <job_name>_start but for task. Metric with dag_id and task_id tagging. |
|
Number of completed task in a given dag. Similar to <job_name>_end but for task |
|
Number of completed task in a given dag. Similar to <job_name>_end but for task Metric with dag_id and task_id tagging. |
|
Number of exceptions raised from DAG callbacks. When this happens, it means DAG callback is not working. Metric with dag_id tagging |
|
Number of |
|
Number of non-zero exit code from Celery task. |
|
Number of tasks removed for a given dag (i.e. task no longer exists in DAG). |
|
Number of tasks removed for a given dag (i.e. task no longer exists in DAG). Metric with dag_id and run_type tagging. |
|
Number of tasks restored for a given dag (i.e. task instance which was previously in REMOVED state in the DB is added to DAG file) |
|
Number of tasks restored for a given dag (i.e. task instance which was previously in REMOVED state in the DB is added to DAG file). Metric with dag_id and run_type tagging. |
|
Number of tasks instances created for a given Operator |
|
Number of tasks instances created for a given Operator. Metric with dag_id and run_type tagging. |
|
Triggerer heartbeats |
|
Number of triggers that blocked the main thread (likely due to not being fully asynchronous) |
|
Number of triggers that errored before they could fire an event |
|
Number of triggers that have fired at least one event |
|
Number of updated datasets |
|
Number of datasets marked as orphans because they are no longer referenced in DAG schedule parameters or task outlets |
|
Number of DAG runs triggered by a dataset update |
Gauges¶
Name |
Description |
---|---|
|
Number of DAGs found when the scheduler ran a scan based on its configuration |
|
Number of errors from trying to parse DAG files |
|
Seconds taken to scan and import |
|
Number of DAG files to be considered for the next scan |
|
Seconds since |
|
Number of tasks that cannot be scheduled because of no open slot in pool |
|
Number of tasks that are ready for execution (set to queued) with respect to pool limits, DAG concurrency, executor state, and priority. |
|
Number of open slots on executor |
|
Number of queued tasks on executor |
|
Number of running tasks on executor |
|
Number of open slots in the pool |
|
Number of open slots in the pool. Metric with pool_name tagging. |
|
Number of queued slots in the pool |
|
Number of queued slots in the pool. Metric with pool_name tagging. |
|
Number of running slots in the pool |
|
Number of running slots in the pool. Metric with pool_name tagging. |
|
Number of deferred slots in the pool |
|
Number of deferred slots in the pool. Metric with pool_name tagging. |
|
Number of starving tasks in the pool |
|
Number of starving tasks in the pool. Metric with pool_name tagging. |
|
Number of triggers currently running for a triggerer (described by hostname) |
|
Number of triggers currently running for a triggerer (described by hostname). Metric with hostname tagging. |
Timers¶
Name |
Description |
---|---|
|
Milliseconds taken to check DAG dependencies |
|
Seconds taken to run a task |
|
Seconds a task spends in the Scheduled state, before being Queued |
|
Seconds a task spends in the Scheduled state, before being Queued. Metric with dag_id and task_id tagging. |
|
Seconds a task spends in the Queued state, before being Running |
|
Seconds a task spends in the Queued state, before being Running. Metric with dag_id and task_id tagging. |
|
Seconds taken to load the given DAG file |
|
Seconds taken to load the given DAG file. Metric with file_name tagging. |
|
Seconds taken for a DagRun to reach success state |
|
Seconds taken for a DagRun to reach success state. Metric with dag_id and run_type tagging. |
|
Seconds taken for a DagRun to reach failed state |
|
Seconds taken for a DagRun to reach failed state. Metric with dag_id and run_type tagging. |
|
Milliseconds of delay between the scheduled DagRun start date and the actual DagRun start date |
|
Milliseconds of delay between the scheduled DagRun start date and the actual DagRun start date. Metric with dag_id tagging. |
|
Milliseconds spent in the critical section of scheduler loop – only a single scheduler can enter this loop at a time |
|
Milliseconds spent running the critical section task instance query |
|
Milliseconds spent running one scheduler loop |
|
Seconds elapsed between first task start_date and dagrun expected start |
|
Seconds elapsed between first task start_date and dagrun expected start. Metric with dag_id and run_type tagging. |
|
Milliseconds taken for fetching all Serialized Dags from DB |
|
Milliseconds taken for clearing not launched queued tasks in Kubernetes Executor |
|
Milliseconds taken to adopt the task instances in Kubernetes Executor |