In this article, we are going to discuss resource monitors, but what are these, why do they matter? Lets discuss their importance, how they work and how can setting up monitors to track and control credit consumption and prevent runaway costs by setting limits and triggering actions based on credit usage thresholds.
Table of Contents
Open Table of Contents
Why Do Resource Monitors Exist?
Using Snowflake Virtual Warehouses costs money, and without clear ways to monitor credits, setting thresholds and alerting stakeholders when limits are met, you could find users spending significant amounts of credits without boundaries or controls in place.
Managing the costs associated with virtual warehouses in Snowflake requires a robust mechanism to track and control credit consumption, hence Resources Monitors were born.
Snowflake’s resource monitors provide precisely this capability, empowering administrators to prevent runaway costs by setting limits and triggering actions based on credit usage thresholds.
Resource Monitors can be applied and used at two levels within Snowflake:
-
Account Level: Monitor the credit consumption of multiple warehouses in an account.
-
Individual Warehouse Level: Tracking and controlling credit usage for a single warehouse.
Who Can Create Monitors?
Only account administrators, i.e., users with the Account Admin role, can create resource monitors.
However, account admins have the flexibility to allow other roles to view and modify these monitors.
What Actions Can You Apply?
Snowflake offers several actions when a trigger condition is satisfied:
Notify: Sends an alert to all account admins with notifications enabled.
Suspend: Sends an alert and suspends the associated virtual warehouse(s) after ongoing queries are completed.
Suspend Immediately: Similar to suspend but stops the warehouse(s) immediately by aborting running queries.
Example Monitors
Once monitors are created, a resource monitor can be applied to either a single virtual warehouse or at the account level to oversee multiple warehouses.
This flexibility allows for tailored monitoring based on specific usage patterns and organisational requirements. To help you get started, below are some examples to support you getting started.
Weekly Resource Monitor
The below query will create a resource monitor that will monitor credit usage up to 100
credits in a week, triggering when 75% credits have been used and suspend the warehouse completely, when reached 100% of the weekly quote used.
-- USE ACCOUNTADMIN ROLE
USE ROLE ACCOUNTADMIN;
-- CREATE MONITOR WITH WEEKLY QUOTA
CREATE RESOURCE MONITOR weekly_monitor
WITH CREDIT_QUOTA = 100
FREQUENCY = WEEKLY
START_TIMESTAMP = IMMEDIATELY
TRIGGERS ON 75 PERCENT DO NOTIFY
ON 100 PERCENT DO SUSPEND;
Account Usage Monitor
The below query will create a resource monitor that will monitor credit usage up to 1000
credits, triggering when 90% or more credits are used.
-- USE ACCOUNTADMIN ROLE
USE ROLE ACCOUNTADMIN;
-- RESOURCE MONITOR WITH NO RESET
CREATE RESOURCE MONITOR no_reset_monitor
WITH CREDIT_QUOTA = 1000
FREQUENCY = NEVER
START_TIMESTAMP = IMMEDIATELY
TRIGGERS ON 90 PERCENT DO NOTIFY
ON 100 PERCENT DO SUSPEND_IMMEDIATE;
Assigning Monitors
Once created the resource monitors, we need to assign monitors to respective accounts and/or a respective warehouse.
Change
<YOUR_WAREHOUSE>
to the desired warehouse you want to monitor.
-- USE ROLE ACCOUNTADMIN
USE ROLE ACCOUNTADMIN;
-- ASSIGN MONITOR AT WAREHOUSE-LEVEL
ALTER WAREHOUSE <YOUR_WAREHOUSE> SET RESOURCE_MONITOR = weekly_monitor;
-- ASSIGN MONITOR AT ACCOUNT-LEVEL
ALTER ACCOUNT SET RESOURCE_MONITOR = monthly_monitor;
By leveraging resource monitors effectively, you gain granular control over your Snowflake environment, ensuring optimal performance while safeguarding against unnecessary costs.