Skip to content

Commit

Permalink
Merge pull request #29 from epoch8/fix_mysql
Browse files Browse the repository at this point in the history
Fix mysql
  • Loading branch information
elephantum authored Nov 21, 2018
2 parents eec9df8 + f3c1280 commit b60a8ec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## 0.4.4 - 2018-11-21

- Fix [#29](https://github.com/epoch8/airflow-exporter/issues/29): fix run with mysql by @cleverCat

## 0.4.3 - 2018-11-21

- Fix [#23](https://github.com/epoch8/airflow-exporter/issues/23): Airflow database CPU usage by @cleverCat
Expand Down
14 changes: 12 additions & 2 deletions prometheus_exporter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from sqlalchemy import func
from sqlalchemy import text

from flask import Response
from flask_admin import BaseView, expose
Expand Down Expand Up @@ -63,7 +64,12 @@ def get_dag_duration_info():
'''get duration of currently running DagRuns
:return dag_info
'''
duration = func.sum(func.now() - DagRun.start_date)
driver = Session.bind.driver
durations = {
'mysqldb': func.sum(func.timestampdiff(text('second'), func.now(), DagRun.start_date)),
'default': func.sum(func.now() - DagRun.start_date)
}
duration = durations.get(driver, durations['default'])

with session_scope(Session) as session:
return session.query(
Expand Down Expand Up @@ -111,8 +117,12 @@ def collect(self):
'Duration of currently running dag_runs in seconds',
labels=['dag_id', 'run_id']
)
driver = Session.bind.driver
for dag in get_dag_duration_info():
dag_duration.add_metric([dag.dag_id, dag.run_id], dag.duration.seconds)
if driver == 'mysqldb':
dag_duration.add_metric([dag.dag_id, dag.run_id], dag.duration)
else:
dag_duration.add_metric([dag.dag_id, dag.run_id], dag.duration.seconds)
yield dag_duration


Expand Down

0 comments on commit b60a8ec

Please sign in to comment.