Query Cost Monitoring
Query Cost Monitoring
A notebook that breaks down compute costs by individual query, allowing teams to identify high-cost operations.
Here's our 4 step process:
- SQL query to retrieve query cost data
- Convert SQL table to a Pandas DataFrame
- Data preparation and filtering (using user input from Streamlit widgets)
- Data visualization and exploration
1. Retrieve Data
To gain insights on query costs, we'll write a SQL query to retrieve the credits_used data from the snowflake.account_usage.metering_history table and merging this with associated user, database, schema and warehouse information from the snowflake.account_usage.query_history table.
2. Convert Table to a DataFrame
Next, we'll convert the table to a Pandas DataFrame.
3. Create an Interactive Slider Widget & Data Preparation
Here, we'll create an interactive slider for dynamically selecting the number of days to analyze. This would then trigger the filtering of the DataFrame to the specified number of days.
Next, we'll reshape the data by calculating the frequency count by hour and task name, which will subsequently be used for creating the heatmap in the next step.
4. Create a Heatmap for Visualizing Query Cost
Finally, a heatmap, and stacked bar chart, and bubble chart are generated that will allow us to gain insights on query cost and frequency.
Want to learn more?
- Snowflake Docs on Account Usage, METERING_HISTORY view and QUERY_HISTORY
- More about Snowflake Notebooks
- For more inspiration on how to use Streamlit widgets in Notebooks, check out Streamlit Docs and this list of what is currently supported inside Snowflake Notebooks
- Check out the Altair User Guide for further information on customizing Altair charts