Keebo | Controlling Costs with Resource Monitors in Snowflake: What They Can (& Can’t) Do

Controlling Costs with Resource Monitors in Snowflake: What They Can (& Can’t) Do

Resource monitors in Snowflake are automated tools that help control credit usage. They’re relatively simple to set up, modify, and drop—which we’ll walk through in this article. 

However, if you’re serious about controlling Snowflake costs, resource monitors have some drawbacks. We’ll discuss what these tools can and can’t do, and some alternatives that actually optimize your Snowflake performance and spend. 

What is a resource monitor in Snowflake? 

Resource monitors in Snowflake are built-in tools that help users avoid unexpected credit consumption when running warehouses. After all, the more credits you consume, the more you spend (read our complete guide to how Snowflake pricing works here). 

Users can set up resource monitors to suspend a warehouse or send notifications when it consumes a certain number of credits. Here are the components that make up a resource monitor in Snowflake. 

Credit quota

Credit quota indicates the number of Snowflake credits allocated to the resource monitor for the specified frequency interval (monthly by default, but this can be customized). The quota includes the total of all resources consumed—warehouse, serverless, and cloud services. Credit quotas do not include the daily 10% adjustment for cloud services.

Monitor type

Resource monitors come in two types: account and warehouse. There can only be one account monitor per account, but you can have multiple warehouse monitors. You can also assign multiple warehouses to the same resource monitor, but each warehouse can only be assigned to one monitor. 

Resource monitors can also be configured at multiple levels. For example, if you have three warehouses, two of which belong to the same user, you can set up a warehouse monitor for the two, another warehouse monitor for the one, and an account monitor for all warehouses.

Keebo | Controlling Costs with Resource Monitors in Snowflake: What They Can (& Can’t) Do

Image source: Snowflake

Schedule

The schedule determines the interval after which used credits will reset to zero. By default, Snowflake sets resource monitor schedules to reset at the beginning of each calendar month, as this aligns with the standard Snowflake billing cycles

You can customize your resource monitor schedule by frequency (e.g. daily, weekly, monthly), never (i.e. used credits never reset), and start (i.e. immediately or later) and end times. 

Actions

You can set triggers for specific actions at certain percentages of the resource monitor’s credit quota. These actions include notification, suspend, or both. For example, if you consume 70% of your credit quota, you can send a notification to your account manager so they can make necessary adjustments. When you reach 100%, you can set the warehouse to automatically suspend. 

Notifications will look like the following:

Resource Monitor KEEBO_ACCOUNT_MONITOR has reached 50% of its MONTHLY quota of 500 credits which has triggered a NOTIFY action.  

Resource Monitor KEEBO_WAREHOUSE_1_MONITOR has reached 90% of its MONTHLY quota of 500 credits which has triggered a SUSPEND action.

Everyone other than users with the ACCOUNTADMIN role will receive these notifications via email. 

Once a resource monitor suspends a warehouse, it cannot be resumed until one of the following conditions is met: 

  • The next interval starts
  • Admin increases the monitor’s credit quota
  • Admin increases the credit threshold for suspend actions
  • Admin removes warehouses from the monitor
  • Admin drops the monitor

Snowflake’s DDL language for resource monitors

To create or manage resource monitors: 

CREATE RESOURCE MONITOR  

ALTER RESOURCE MONITOR

SHOW RESOURCE MONITORS

DROP RESOURCE MONITOR

When assigning a resource monitor to a warehouse, use the following DDL commands:

CREATE WAREHOUSE  

ALTER WAREHOUSE

SHOW WAREHOUSE

Although only users with the ACCOUNTADMIN role can create resource monitors by default, they can grant other users privileges to perform the following SQL actions on specific resource monitors:

MONITOR  

MODIFY

How to set up a resource monitor in Snowflake

You can set up a resource monitor in Snowflake using Snowsight, the classic console, or in SQL. As mentioned above, only users with the ACCOUNTADMIN role can create resource monitors, although they can assign privileges to other users upon creation. 

Creating a resource monitor in Snowslight

  1. Sign into Snowsight
  2. Go to Admin >> Cost Management
  3. Select Resource Monitors, then + Resource Monitor
  4. Enter a Name for the resource monitor
  5. Enter the Credit Quota for the specified interval
  6. Select Monitor Type. Choose either Account or Warehouse.
  7. Enter a threshold next to each Action option. Select Add to create additional notifications. You can add up to five notify actions.
  8. Select Schedule >> Customize to set a custom interval within which the credit quota will reset. Keep in mind that you cannot change a customized schedule for a resource monitor back to the default. Instead, you must drop the monitor and recreate it. 

Creating a resource monitor in the Snowflake classic console

  1. Select Account >> Resource Monitors >> Create Resource Monitor
  2. Enter a resource monitor Name 
  3. Enter your Credit Quota 
  4. Select the Monitor Level (i.e. Account or Warehouse)
  5. Select the Actions and Notifications you want to enable indicating a threshold next to each option. 
  6. Select +Add to add additional actions (up to five notify actions total). 
  7. Select Schedule >> Customize to set a custom interval within which the credit quota will reset. Keep in mind that you cannot change a customized schedule for a resource monitor back to the default. Instead, you must drop the monitor and recreate it. 

Creating a resource monitor in SQL

  1. Execute a CREATE RESOURCE MONITOR command 
  2. Execute an ALTER WAREHOUSE command to assign warehouses to the resource monitor or ALTER ACCOUNT command to assign accounts to the warehouses

For example: 

USE ROLE ACCOUNTADMIN;  

CREATE OR REPLACE RESOURCE MONITOR control1 WITH CREDIT_QUOTA=5000
TRIGGERS ON 100 PERCENT DO SUSPEND;

ALTER WAREHOUSE keebo1 SET RESOURCE_MONITOR = control1;

If a query starts before the threshold is reached (in this case, 100%) and continues running after the SUSPEND action is triggered, that warehouse will continue consuming resources until the query is complete. 

To add additional credit quota thresholds and actions, execute the following command:

USE ROLE ACCOUNTADMIN;  

CREATE OR REPLACE RESOURCE MONITOR control1 WITH CREDIT_QUOTA=5000
   TRIGGERS ON 50 PERCENT DO NOTIFY
            ON 80 PERCENT DO NOTIFY
            ON 90 PERCENT DO SUSPEND
            ON 100 PERCENT DO SUSPEND_IMMEDIATE;

ALTER WAREHOUSE keebo1 SET RESOURCE_MONITOR = control1;

Remember: resource monitors in Snowflake reset at the beginning of each month unless you specify a custom schedule. To do this in SQL, execute the following command: 

USE ROLE ACCOUNTADMIN;  

CREATE OR REPLACE RESOURCE MONITOR control1 WITH CREDIT_QUOTA=5000
    FREQUENCY = MONTHLY
    START_TIMESTAMP = IMMEDIATELY
    TRIGGERS ON 50 PERCENT DO NOTIFY
             ON 80 PERCENT DO NOTIFY
             ON 90 PERCENT DO SUSPEND
             ON 100 PERCENT DO SUSPEND_IMMEDIATE;

ALTER WAREHOUSE keebo1 SET RESOURCE_MONITOR = control1;

To start the schedule at some point in the future, simply indicate a future DATETIME value for START_TIMESTAMP. 

Modifying a resource monitor in Snowflake upon creation

Once you create a resource monitor in Snowflake, you can go in and make the following changes:

  • Increase or decrease the credit quota
  • Modify the customized schedule (reverting to the default schedule requires dropping the monitor and launching a new one)
  • Add or remove actions
  • Adjust thresholds for existing actions
  • Convert account monitor to warehouse monitor
  • Convert warehouse monitor to account monitor
  • Add or remove warehouses from warehouse monitor

Keep in mind that making these changes won’t impact the credits used to date for that monitor. They only affect credits used after the changes are saved. 

Modifying a resource monitor in Snowsight

  1. Go to Admin >> Cost Management
  2. Select Resource Monitors, then select the resource monitor you want to modify
  3. Select the menu (…) in the top right-hand corner
  4. Select Edit

Modifying a resource monitor in the classic console

  1. Go to Account >> Resource Monitors
  2. Select the resource monitor you want to modify
  3. Select Edit

Modifying a resource monitor in SQL

Execute an ALTER RESOURCE MONITOR statement. For example, change the credit quota with the following command:

ALTER RESOURCE MONITOR control1 SET CREDIT_QUOTA=4000;

Assigning warehouses to a resource monitor

In Snowsight and Classic Console, navigate to the Resource Monitor screen using the same instructions listed above. Then select the resource monitor you want to use, and use the Select Warehouse option to add warehouses to that resource monitor. 

In SQL you can use the ALTER WAREHOUSE command like the following:

ALTER WAREHOUSE keebo1 SET RESOURCE_MONITOR = control1;

Is a resource monitor in Snowflake the best way to control costs?

The main advantage of creating resource monitors in Snowflake is obvious: it gives you the opportunity to monitor and control credit consumption, and thus keep Snowflake costs under control. However, relying solely on resource monitors for Snowflake cost optimization isn’t the best strategy. Here’s why.

Rigid structure 

Snowflake resource monitors,  as we’ve extensively laid out above, are based on rigid parameters. At best, you set your credit quotas and schedules based on previous performance. At worst, you’re guessing at how many credits you’ll actually need.

In either case, data cloud workloads are dynamic, and often rely on factors outside anyone’s control. A growing user base, inefficient query writing, unexpected spikes in requests—these always come up unexpectedly, and they don’t care what your credit quota is. 

The only solution is to go in and manually adjust quotas based on these changes. But that’s a lot of work, and whatever you’re saving in credits you’re probably spending in the hours spent in manual adjustments. 

Obscured performance metrics

Snowflake resource monitors are based solely on credit usage. A number of factors go into determining credit usage: query volume, execution time, and warehouse size being the most relevant. 

For example, if you set a NOTIFY command when your credit quota reaches 50%, all you really know is you’ve used half your credits. You don’t have insight into why those credits were consumed so quickly and, most importantly, how to fix it. Did you get an influx of users that increased your query volume for a 24-hour period? Did a handful of inexperienced data analysts write inefficient queries that consumed too much compute? Snowflake resource monitors won’t answer those questions—which means you can’t act on the information you receive. 

Brute force cost control

Snowflake optimizations are a delicate exercise. Scale up a warehouse for too long, and you consume resources you don’t need. Scale it down for too long, and you slow performance. Set the auto-suspend too high, and you’re running unused warehouses; set it too low, and you risk pulling data from cold storage. 

Rather than take into account these nuances, resource monitors in Snowflake use a brute force method: just shutting down the warehouse. When that happens, however, system performance suffers, and most Snowflake users can’t avoid the downtime. 

So what ends up happening in reality? Users drop monitors or set their credit quotas so high that it’s meaningless. In other words, no one’s really saving costs. 

An alternative solution: use automated Snowflake monitoring & warehouse optimization

Obviously, we wouldn’t point out these problems with resource monitoring in Snowflake unless we had a better solution to offer—which we do. Our cost optimization approach comes in two steps:

  1. Monitor actual usage and performance metrics so you not only are aware of your resource consumption, but know how to fix it. Use Snowflake Workload Intelligence—our free Snowflake Marketplace app—to surface these insights natively within Snowsight. 
  2. Leverage AI to monitor activity 24/7 and make Snowflake optimization adjustments to your warehouses in real time. 

By following these two steps, you can get your desired outcome—reduced spend—without the frustration of managing a brute force, time-consuming monitoring solution. 

Read how Lightcast implemented AI-powered Snowflake optimizations with Keebo and saved $92,000 in the process. 

Keebo | Controlling Costs with Resource Monitors in Snowflake: What They Can (& Can’t) Do
Collin David
Articles: 5