What does each Streamlit app in Snowflake cost?
Snowflake shows you usage per account and per warehouse, not per app. But every query a Streamlit app runs carries the app’s name in its query tag, so the credits can be added up per app with plain SQL.
The query
QUERY_ATTRIBUTION_HISTORY gives the warehouse credits attributed to each query. This adds them up per app for the last
30 days, the last 7 days and this calendar month:
SELECT UPPER(REPLACE(TRY_PARSE_JSON(query_tag):StreamlitName::string, '"', '')) AS app,
SUM(IFF(start_time > DATEADD(day, -30, CURRENT_TIMESTAMP()), credits_attributed_compute, 0)) AS credits_30d,
SUM(IFF(start_time > DATEADD(day, -7, CURRENT_TIMESTAMP()), credits_attributed_compute, 0)) AS credits_7d,
SUM(IFF(start_time >= DATE_TRUNC('month', CURRENT_TIMESTAMP()), credits_attributed_compute, 0)) AS credits_month
FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_ATTRIBUTION_HISTORY
WHERE start_time > LEAST(DATEADD(day, -30, CURRENT_TIMESTAMP()), DATE_TRUNC('month', CURRENT_TIMESTAMP()))
AND query_tag LIKE '%"StreamlitName"%'
GROUP BY 1
ORDER BY credits_30d DESC;
Your role needs the SNOWFLAKE.USAGE_VIEWER database role (or IMPORTED PRIVILEGES on the SNOWFLAKE database).
The view runs up to several hours behind.
What it leaves out
- Warehouse idle time. These are the credits of the app’s own queries. A warehouse that stays up for an app also costs the time it waits, which no single query carries.
- App Runtime (Next.js) apps. They don’t carry the
StreamlitNametag, so they don’t appear here. - Money. Credits only; multiply by your price per credit.
Keep it as a daily list
StreamGen does this every day inside your account: every Streamlit and App Runtime app with its owner, viewers and credits, its cost in money once you enter your price per credit, apps that switch off at a set time or after a few hours without viewers, and a monthly budget with an email to the admins at 80% and 100%.
It is a Snowflake Native App on the Snowflake Marketplace. Installing is free, and a free 7-day trial key starts when you activate it.
More: list every app and who uses it · stop apps nobody is using