Skip to content

Instantly share code, notes, and snippets.

@slopp
Last active October 12, 2022 15:16
Show Gist options
  • Save slopp/6137b105a4b6d0c198486d7ac681f5b8 to your computer and use it in GitHub Desktop.
Save slopp/6137b105a4b6d0c198486d7ac681f5b8 to your computer and use it in GitHub Desktop.
Airflow Usage Minutes

Dagster Cloud pricing is based on usage. If you are using Airflow, you can get an estimate of this usage by querying the Airflow metadata database.

For SQLite:

# navigate to your airflow DB, normally ~/airflow
sqlite3
.open airflowdb
SELECT SUM((julianday(end_date) - julianday(start_date))* 24 * 60) AS run_minutes FROM dag_run;

The Airflow dag_run table has the following fields which you can use to group or filter this query:

dag_id
run_id
state
run_type

For Postgres the SQL is similar. This query breaks down the run usage by month:

SELECT 
  date_trunc('month', start_date) AS month, 
  SUM(EXTRACT(epoch FROM (end_date - start_date))/60) AS run_minutes 
FROM dag_run 
GROUP BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment