Airflow Log Clean up and DAG Management

Disable Example DAGs

Some example DAGs generate a significant amount of data as they run daily. To prevent excessive log accumulation and resource consumption, it is recommended to disable them.

Steps to Disable Example DAGs

  1. Open the airflow.cfg configuration file.
  2. Locate the parameter load_examples = True.
  3. Change it to load_examples = False.
  1. Restart the Airflow webserver and scheduler.

Alternatively, you can manually disable the DAGs from the Airflow UI by pausing them.

Example DAG Logs Location

Bash
Copy

Airflow Log Cleanup DAG

Airflow generates a large number of logs over time, especially for example DAGs and other scheduled tasks. These logs accumulate in the scheduler directory, consuming significant disk space.

To address this, we can deploy an Airflow DAG that periodically removes old log files from the scheduler directory. This cleanup process helps optimize storage usage and maintain a more efficient Airflow environment.

Implementation Details

This DAG performs the following tasks:

  • Deletes log files older than a specified number of days.
  • Removes empty directories to maintain a clean log structure.
  • Runs daily at 1 AM to ensure logs are regularly cleaned.

DAG Configuration

Bash
Copy

Key Parameters

ParameterDescription
schedule_interval="0 1 * * *"Runs the cleanup daily at 1 AM.
-mtime +1Removes logs older than 1 day (can be adjusted as needed).
find ... -exec rm -f {}Deletes all .log files meeting the criteria.
find ... -exec rm -rf {}Removes empty directories after cleanup.

Deployment Steps

  1. Save the DAG file as airflow_log_cleanup.py inside the Airflow DAGs directory.
  2. Enable the DAG in the Airflow UI (DAGs → airflow_log_cleanup → Toggle ON ✅).
  3. Monitor logs and disk space to confirm cleanup efficiency.

Benefits

  • Automated log cleanup reduces manual intervention.
  • Prevents log file buildup, improving storage management.
  • Keeps Airflow scheduler directory clean for better performance.
Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard
  Last updated