Last active
December 21, 2023 19:52
-
-
Save sfirke/533383f0656bba3c56d19dba2a35b946 to your computer and use it in GitHub Desktop.
Bash script to monitor health of Airflow scheduler container deployed with docker compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Monitors the health of the scheduler container in an Airflow docker compose deployment, sends SMTP email if it's unhealthy | |
# Change as needed to match your container name and your SMTP server settings | |
# Requires the sendemail package being installed on the host machine | |
# sudo apt-get install sendemail, if on Ubuntu | |
# Get container health status | |
healthy=$(docker inspect -f '{{.State.Health.Status}}' airflow-airflow-scheduler-1) | |
# Check if healthy | |
if [[ $healthy != "healthy" ]]; then | |
SERVER="smtpmail.company.com" | |
FROM="ITAlerts@company.com" | |
TO="You@company.com" | |
SUBJ="Airflow scheduler container is unhealthy" | |
MESSAGE="Please investigate as Airflow jobs may not be running." | |
CHARSET="utf-8" | |
sendemail -f $FROM -t $TO -u $SUBJ -s $SERVER -m $MESSAGE -v -o message-charset=$CHARSET | |
fi | |
# Save this ^^^ as airflow_health_monitor.sh | |
# Add to cron to run every 5 minutes: | |
# Run on command line: | |
crontab -e | |
# And add a new line for it to run every six hours: | |
0 */6 * * * ~/airflow_health_monitor.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment