Airflow 모니터링 (Python)

2022. 8. 24. 09:00Infra/Airflow

import subprocess

def check_celery():
    cmd = "/home/ubuntu/airflow/bin/celery --app airflow.executors.celery_executor.app inspect ping"
    result = subprocess.getoutput(cmd)
    if 'pong' in result:
        return 0
    else:
        return result

def check_db():
    cmd = '/home/ubuntu/airflow/bin/airflow db check'
    result = subprocess.getoutput(cmd)
    if 'Connection successful' in result:
        return 1
    else:
        return result

def check_scheduler():
    cmd = 'airflow jobs check --job-type SchedulerJob --allow-multiple --limit 100'
    result = subprocess.getoutput(cmd)
    if 'Found one alive job' in result:
        return 1
    else:
        return result

if __name__ == '__main__':
    if check_celery() != 0:
        print('error')
    if check_db() != 0:
        print('error')
    if check_scheduler() != 0:
        print('error')

'Infra > Airflow' 카테고리의 다른 글

[Airflow] ubuntu 18, python 3.6 airflow  (0) 2021.10.19