Mastering Resource Monitors in Snowflake
Learn how to effectively control and monitor credit usage in Snowflake using resource monitors. This guide covers the setup, customisation, and management of resource monitors to optimise your Snowflake environment.
Resource monitors in Snowflake are powerful tools designed to help you control and monitor the credit usage of your warehouses and entire account. Available from the Standard Edition onwards, these monitors are essential for efficient resource management.
Overview#
Purpose#
Resource monitors are used to control and monitor credit usage, ensuring that your Snowflake environment runs efficiently and within budget.
Availability#
This feature is available in the Standard Edition and higher editions of Snowflake.
Scope#
Resource monitors can be applied at various levels:
- Account Level: Monitors credit usage for the entire Snowflake account.
- Individual Warehouses: Monitors credit usage of specific warehouses.
- Group of Warehouses: Monitors a collection of warehouses under one resource monitor.
Setting Credit Quotas#
Credit Quota#
A credit quota is a limit set on credit usage for a defined cycle. The default cycle is monthly, but it can be customised to fit different time frames such as daily, weekly, or any other period as needed.
Customisation#
Schedules can be adjusted to suit your operational needs, providing flexibility in how credit usage is monitored.
Scope#
Resource monitors can be tailored to monitor credit usage at different levels:
- Account Level: For the entire Snowflake account.
- Individual Warehouses: For specific warehouses.
- Group of Warehouses: For multiple warehouses collectively.
Actions Based on Quota#
Resource monitors allow for specific actions to be set when certain usage thresholds are met. The primary actions include:
1. Notify#
Trigger: When a specified percentage of the credit quota is used (e.g., 50%).
Action: Sends a notification to designated users.
Purpose: Alerts administrators before the quota is fully utilised, allowing for proactive management.
2. Suspend and Notify#
Trigger: When a higher percentage of the credit quota is used.
Action:
- Suspends the specified warehouse(s) after completing current running queries.
- Sends a notification to designated users.
Detail: “Suspend” means no new queries will start, but existing queries will complete, allowing administrators to manage workloads without abrupt interruptions.
3. Suspend Immediately and Notify#
Trigger: When the credit quota is reached.
Action:
- Immediately suspends the specified warehouse(s).
- Aborts any running queries.
- Sends a notification to designated users.
Detail: Provides strict control to ensure no further credit consumption beyond the set quota, useful for environments with strict budget constraints.
Setting Percentages Above 100%#
Usage: Allows for handling scenarios where it’s acceptable to exceed the quota temporarily.
Purpose: Provides flexibility in managing unexpected surges in credit usage.
Creation and Management#
Roles and Permissions#
Creation: Only users with the ACCOUNTADMIN role can create resource monitors.
Delegation: ACCOUNTADMIN can grant privileges to other roles for monitoring and modifying resource monitors.
Privileges:
- Monitor: View usage and status of resource monitors.
- Modify: Adjust settings and quotas of existing resource monitors.
Steps to Create a Resource Monitor#
-
Define Credit Quota:
- Determine the limit of credits for the chosen cycle.
- Select the cycle period (monthly, weekly, daily, etc.).
-
Specify Scope:
- Choose to apply the monitor at the account level, for individual warehouses, or for a group of warehouses.
-
Set Actions and Thresholds:
- Define the percentage thresholds and corresponding actions (notify, suspend and notify, suspend immediately and notify).
-
Assign Notifications:
- Specify which users or roles should receive notifications.
Practical Example#
Here’s how to create and configure a resource monitor in Snowflake:
CREATE RESOURCE MONITOR monthly_monitor
WITH CREDIT_QUOTA = 1000
FREQUENCY = MONTHLY
START_TIMESTAMP = IMMEDIATE
NOTIFY_USERS = ('admin@example.com', 'ops@example.com');
-- Adding actions
ALTER RESOURCE MONITOR monthly_monitor
SET SUSPEND_AT = 90
NOTIFY_AT = 75
SUSPEND_IMMEDIATELY_AT = 100;
Monitoring Usage
You can monitor the status and usage of resource monitors using SQL queries:
sql
SHOW RESOURCE MONITORS;
By leveraging resource monitors, you can ensure efficient management of credit usage in your Snowflake environment, avoiding unexpected costs and ensuring smooth operation.sql