How to Monitor Warehouse Usage in Snowflake
To monitor warehouse usage in Snowflake, use the
SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY view to track credit consumption and the QUERY_HISTORY view to analyze query activity. These views provide detailed information about warehouse credit usage, query counts, and execution times.Syntax
Use the WAREHOUSE_METERING_HISTORY view to see credit usage per warehouse over time. Use the QUERY_HISTORY view to see queries run on warehouses.
WAREHOUSE_METERING_HISTORY: Tracks credits used by each warehouse per hour.QUERY_HISTORY: Shows details of queries executed, including warehouse used and execution time.
sql
SELECT WAREHOUSE_NAME, START_TIME, CREDITS_USED FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP()) ORDER BY START_TIME DESC; SELECT QUERY_ID, WAREHOUSE_NAME, EXECUTION_STATUS, START_TIME, END_TIME, TOTAL_ELAPSED_TIME FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE WAREHOUSE_NAME = 'MY_WAREHOUSE' AND START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP()) ORDER BY START_TIME DESC;
Example
This example shows how to get the total credits used by each warehouse in the last 7 days and the number of queries run on a specific warehouse.
sql
WITH Credits AS ( SELECT WAREHOUSE_NAME, SUM(CREDITS_USED) AS TOTAL_CREDITS FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP()) GROUP BY WAREHOUSE_NAME ), Queries AS ( SELECT WAREHOUSE_NAME, COUNT(*) AS QUERY_COUNT FROM SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP()) GROUP BY WAREHOUSE_NAME ) SELECT c.WAREHOUSE_NAME, c.TOTAL_CREDITS, q.QUERY_COUNT FROM Credits c LEFT JOIN Queries q ON c.WAREHOUSE_NAME = q.WAREHOUSE_NAME ORDER BY c.TOTAL_CREDITS DESC;
Output
WAREHOUSE_NAME | TOTAL_CREDITS | QUERY_COUNT
---------------|---------------|------------
MY_WAREHOUSE | 150.25 | 1200
ANALYTICS_WH | 75.50 | 800
ETL_WH | 30.00 | 300
Common Pitfalls
Common mistakes when monitoring warehouse usage include:
- Not accounting for the time zone in
START_TIMEfilters, which can cause missing data. - Using
WAREHOUSE_METERING_HISTORYwithout proper date range filters, leading to large result sets and slow queries. - Confusing credit usage with query count; a warehouse can use credits even when idle due to auto-suspend delays.
sql
/* Wrong: No date filter, returns too much data */ SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY; /* Right: Filter by recent 7 days */ SELECT * FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY WHERE START_TIME >= DATEADD(day, -7, CURRENT_TIMESTAMP());
Quick Reference
| View | Purpose | Key Columns |
|---|---|---|
| WAREHOUSE_METERING_HISTORY | Tracks warehouse credit usage hourly | WAREHOUSE_NAME, START_TIME, CREDITS_USED |
| QUERY_HISTORY | Shows queries run on warehouses | QUERY_ID, WAREHOUSE_NAME, START_TIME, TOTAL_ELAPSED_TIME |
| WAREHOUSE_LOAD_HISTORY | Shows warehouse load and queue times | WAREHOUSE_NAME, START_TIME, AVG_RUNNING, AVG_QUEUED_LOAD |
Key Takeaways
Use SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSE_METERING_HISTORY to track warehouse credit usage over time.
Query SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY to analyze query activity per warehouse.
Always filter by date to avoid large, slow queries and ensure accurate monitoring.
Understand that credit usage can occur even when warehouses are idle due to auto-suspend delays.
Use warehouse load history views to monitor performance and queue times.
