Working with Resource Monitors

A virtual warehouse consumes Snowflake credits while it runs. The number of credits consumed depends on the size of the warehouse and how long it runs.

To help control costs and avoid unexpected credit usage caused by running warehouses, Snowflake provides resource monitors. Resource monitors can be used to impose limits on the number of credits that warehouses consume within a specified interval or date range. When these limits are reached and/or are approaching, the resource monitor can trigger various actions, such as sending alert notifications and/or suspending the warehouses.

Resource monitors can only be created by account administrators (i.e. users with the ACCOUNTADMIN role); however, account administrators can choose to enable users with other roles to view and modify resource monitors.

In this Topic:

Overview

Resource Monitor Properties

A resource monitor is a first-class object in Snowflake, consisting of the following properties.

Credit Quota

Credit quota specifies the number of Snowflake credits allocated to the monitor for the specified frequency interval. Any number can be specified.

In addition, Snowflake tracks the used credits/quota within the specified frequency interval by all warehouses assigned to the monitor. At the specified interval, this number resets back to 0.

Monitor Level

This property specifies whether the resource monitor is used to monitor the credit usage for your entire Account (i.e. all warehouses in the account) or a specific set of individual warehouses.

If this property is not set, the resource monitor doesn’t monitor any credit usage. It simply remains dormant.

Schedule

The default schedule for a resource monitor specifies that it starts monitoring credit usage immediately and the used credits reset back to 0 at the beginning of each calendar month (i.e. the start of the standard Snowflake billing cycle).

However, you can optionally customize the schedule for a resource monitor using the following properties:

Frequency

The interval at which the used credits reset relative to the specified start date and time.

Supported values:

  • Daily

  • Weekly

  • Monthly

  • Yearly

  • Never (used credits never reset; assigned warehouses continue using credits until the credit quota is reached)

Start

Date and time (i.e. timestamp) when the resource monitor starts monitoring the assigned warehouses.

Supported values:

  • Immediately (i.e. current timestamp)

  • Later (i.e. any future timestamp)

In addition, Snowflake uses this date and time to determine when to reset the used credits, based on the specified frequency. For example, if the start is 15-July-2019 (Monday) at 8:00 AM:

  • Frequency = Monthly: Used credits reset at 8:00 AM on the 15th of each following month.

  • Frequency = Weekly: Used credits reset at 8:00 AM on each following Monday.

Note that, if you specify the last day of a month as the start date, Snowflake resets the used credits on the last day of all following months, regardless of the number of days in the month. For example, if you set the start date to January 31, Snowflake subsequently resets the used credits for the resource monitor on February 28 (or February 29 in a leap year), March 31, April 30, and so on.

End

Date and time (i.e. timestamp) when Snowflake suspends the warehouses associated with the resource monitor, regardless of whether the used credits reached any of the thresholds defined for the resource monitor’s actions (see next section in this topic).

Supported values: Any future timestamp.

Note that this property is not commonly used.

Important

If you choose to customize the schedule for a resource monitor, the frequency is relative to the specified start date and time, which is different than the default schedule.

Also, if you specify a frequency, you must also specify a start date and time, and vice versa (i.e. you cannot set one without setting the other).

Actions

Also referred to as triggers, each action specifies a threshold, as a percentage of the credit quota for the resource monitor, and the action to perform when the threshold is reached within the specified interval. Note that actions support thresholds greater than 100.

Resource monitors support the following actions:

Notify & Suspend

Send a notification (to all account administrators with notifications enabled) and suspend all assigned warehouses after all statements being executed by the warehouse(s) have completed.

Notify & Suspend Immediately

Send a notification (to all account administrators with notifications enabled) and suspend all assigned warehouses immediately, which cancels any statements being executed by the warehouses at the time.

Notify

Perform no action, but send an alert notification (to all account administrators with notifications enabled).

Each resource monitor can have the following actions:

  • One Suspend action.

  • One Suspend Immediate action.

  • Up to five Notify actions.

Note

A resource monitor must have at least one action defined; if no actions have been defined, nothing happens when the used credits reach the threshold.

Assignment of Resource Monitors

A single monitor can be set at the account level to control credit usage for all warehouses in your account.

In addition, a monitor can be assigned to one or more warehouses, thereby controlling the credit usage for each assigned warehouse. Note, however, that a warehouse can be assigned to only a single resource monitor.

The following diagram illustrates a scenario in which one resource monitor is set at the account level and individual warehouses are assigned to two other resource monitors:

Warehouse and resource monitor relationships

Based on this diagram:

  • The credit quota for the entire account is 5000 for the interval (month, week, etc.), as controlled by Resource Monitor 1; if this quota is reached within the interval, the actions defined for the resource monitor (Suspend, Suspend Immediate, etc. ) are enforced for all five warehouses.

  • Warehouse 3 can consume a maximum of 1000 credits within the interval.

  • Warehouse 4 and 5 can consume a maximum combined total of 2500 credits within the interval.

Note that the actual credits consumed by Warehouses 3, 4, and 5 may be less than their quotas if the quota for the account is reached first.

Important

An account-level resource monitor does not override resource monitor assignment for individual warehouses. If either the account resource monitor or the warehouse resource monitor reaches its defined threshold and a suspend action has been defined, the warehouse is suspended.

This enables controlling global credit usage while also providing fine-grained control for individual/specific warehouses.

In addition, an account-level resource monitor does not control credit usage by the Snowflake-provided warehouses (used for Snowpipe, automatic reclustering, and materialized views); the monitor only controls the virtual warehouses created in your account.

Warehouse Suspension and Resumption

The used credits for a resource monitor reflects the sum of all credits consumed by all assigned warehouses within the specified interval. If a monitor has a Suspend or Suspend Immediately action defined and its used credits reach the threshold for the action, any warehouses assigned to the monitor are suspended and cannot be resumed until one of the following conditions is met:

  • The next interval, if any, starts, as dictated by the start date for the monitor.

  • The credit quota for the monitor is increased.

  • The credit threshold for the suspend action is increased.

  • The warehouses are no longer assigned to the monitor.

  • The monitor is dropped.

Tip

Resource monitors are not intended for strictly controlling consumption on an hourly basis; they are intended for tracking and controlling credit consumption per interval (day, week, month, etc.). Also, they are not intended for setting precise limits on credit usage (i.e. down to the level of individual credits). For example, when credit quota thresholds are reached for a resource monitor, the assigned warehouses may take some time to suspend, even when the action is Suspend Immediate, thereby consuming additional credits.

If you wish to strictly enforce your quotas, we recommend the following:

  • Utilize buffers in the quota thresholds for actions (e.g. set a threshold to 90% instead of 100%).

    This will help ensure that your credit usage doesn’t exceed the quota.

  • To more strictly control credit usage for individual warehouses, assign only a single warehouse to each resource monitor.

    When multiple warehouses are assigned to the same resource monitor, they share the same quota thresholds, which may result in credit usage for one warehouse impacting the other assigned warehouses.

Resource Monitor Notifications

When a resource monitor reaches the threshold for an action, it generates one of the following notifications, based on the action performed:

  • The assigned warehouses will be suspended after all running queries complete.

  • All running queries in the assigned warehouses will be canceled and the warehouses suspended immediately.

  • A threshold has been reached, but no action has been performed.

The notification is sent to all account administrators who have enabled receipt of notifications.

Important

Notifications can be received by account administrators through the web interface and/or email; however, by default, notifications are not enabled:

  • To receive notifications, each account administrator must explicitly enable notifications through their preferences in the web interface.

  • In addition, if an account administrator chooses to receive email notifications, they must provide a valid email address (and verify the address) before they will receive any emails.

DDL for Resource Monitors

Snowflake provides the following DDL commands for creating and using/managing resource monitors:

In addition, the following DDL commands can be used to assign a resource monitor to a warehouse and view whether a warehouse is assigned to a monitor:

Access Control Privileges for Resource Monitors

By default, resource monitors can only be created by account administrators and, therefore, can only be viewed and maintained by them.

However, Snowflake supports enabling other users to view and modify resource monitors as needed. This functionality is implemented through the following access control privileges, which can be granted on specified resource monitors to specified roles:

  • MONITOR

  • MODIFY

For more details, see Access Control Privileges and GRANT <privileges> … TO ROLE.

Enabling Receipt of Notifications

As an account administrator, you must enable notifications for yourself in the web interface before you can receive any notifications generated by resource monitors.

To enable notifications in the web interface:

  1. Make sure you are using the ACCOUNTADMIN role. If you aren’t, in the drop-down menu next to your name in the upper-right corner, select Switch role » ACCOUNTADMIN.

  2. In the same drop-down menu, select Preferences » Notifications.

  3. Select one of the options. If you selected Email or All and you do not already have a validated email address, you must enter an email address.

  4. If you enter an email address, you must then validate the address by following the instructions provided on-screen.

Creating Resource Monitors

Resource monitors can be created through either the web interface or SQL; however, only account administrators (i.e. users with the ACCOUNTADMIN role) can create resource monitors.

Important

You must assign at least one warehouse to a resource monitor or set the monitor at the account level for it to begin monitoring/tracking credit usage:

  • In the web interface, you are required to do this at creation time.

  • In SQL, you must create the resource monitor first, then assign one or more warehouses to it by executing ALTER WAREHOUSE as a separate, additional step.

Also, to receive notifications when resource monitor actions are triggered, you must enable notifications in your preferences in the web interface.

Creating a Resource Monitor with a Default Schedule

To create a resource monitor that uses the default schedule (i.e. starts monitoring immediately and resets on the first day of each calendar month):

Web Interface
  1. Make sure you are using the ACCOUNTADMIN role.

  2. Click on Account Account tab » Resource Monitors » Create Resource Monitor.

  3. Enter a name and quota.

  4. Specify whether the resource monitor will be used for monitoring your account or individual warehouses.

  5. Enter a threshold for at least one of the suspend actions. You can also specify up to five notify actions that simply send alerts without suspending any warehouses.

SQL

In SQL, this task is performed in two steps:

  1. Execute a CREATE RESOURCE MONITOR command, but do do not specify any scheduling properties.

  2. Execute an ALTER WAREHOUSE command to assign warehouses to the resource monitor or an ALTER ACCOUNT command to set the resource monitor for the account.

For example:

  • To create a monitor that starts monitoring immediately, resets at the beginning of each month, and suspends the assigned warehouse assigned when the used credits reach 100% of the credit quota:

    USE ROLE ACCOUNTADMIN;
    
    CREATE OR REPLACE RESOURCE MONITOR limit1 WITH CREDIT_QUOTA=1000
      TRIGGERS ON 100 PERCENT DO SUSPEND;
    
    ALTER WAREHOUSE wh1 SET RESOURCE_MONITOR = limit1;
    

    The SUSPEND action waits for currently-executing queries to finish before suspending the warehouse. This means that a query started before the trigger fires executes to completion and the warehouse consumes credits even after the quota is reached.

  • To create a monitor that is similar to the first example, but suspends at 90% and suspends immediately at 100% to prevent all warehouses in the account from consuming credits after the quota has been reached:

    USE ROLE ACCOUNTADMIN;
    
    CREATE OR REPLACE RESOURCE MONITOR limit1 WITH CREDIT_QUOTA=1000
      TRIGGERS ON 90 PERCENT DO SUSPEND
               ON 100 PERCENT DO SUSPEND_IMMEDIATE;
    
    ALTER WAREHOUSE wh1 SET RESOURCE_MONITOR = limit1;
    

    In this example, a notification is generated and the assigned warehouses are suspended when 90% usage is reached, which prevents the warehouses from executing any new queries, but allows currently-executing queries to complete. If the assigned warehouses reach 100% usage, a notification is generated and the warehouses are suspended immediately, canceling all currently-executing queries.

  • To create a monitor that is similar to the first example, but lets the assigned warehouse exceed the quota by 10% and also includes two notification actions to alert account administrators as the used credits reach the halfway and three-quarters points for the quota:

    USE ROLE ACCOUNTADMIN;
    
    CREATE OR REPLACE RESOURCE MONITOR limit1 WITH CREDIT_QUOTA=1000
       TRIGGERS ON 50 PERCENT DO NOTIFY
                ON 75 PERCENT DO NOTIFY
                ON 100 PERCENT DO SUSPEND
                ON 110 PERCENT DO SUSPEND_IMMEDIATE;
    
    ALTER WAREHOUSE wh1 SET RESOURCE_MONITOR = limit1;
    

    In this example:

    • When 50% and 75% usage is reached, an alert notification is sent to all account administrators who have enabled notifications, but no other actions are performed.

    • When 100% usage is reached, the assigned warehouse is suspended.

    • If the warehouse is still running when 110% usage is reached, it is suspended immediately.

Creating a Resource Monitor with a Custom Schedule

To create a resource monitor that uses a schedule other than the default:

Web Interface
  1. Make sure you are using the ACCOUNTADMIN role.

  2. Click on Account Account tab » Resource Monitors » Create Resource Monitor.

  3. Enter a name and quota.

  4. Specify whether the resource monitor will be used for monitoring your account or individual warehouses.

  5. In the Schedule field, click the Customize link and specify one or more of the following properties, as desired:

    • Reset used credits based on the specified frequency.

    • Start monitoring credit usage immediately or at a later date and time.

    • Suspend warehouses at the specified end date and time, regardless of whether the credit quota threshold has been reached.

  6. Enter a threshold for at least one of the suspend actions. You can also specify up to five notify actions that simply send alerts without suspending any warehouses.

SQL

Execute a CREATE RESOURCE MONITOR command, with one or more of the following scheduling properties:

  • FREQUENCY

  • START_TIMESTAMP

  • END_TIMESTAMP

For example:

  • To create an account-level resource monitor that starts immediately (based on the current timestamp), resets monthly on the same day and time, has no end date or time, and suspends the assigned warehouse when the used credits reach 100% of the quota:

    USE ROLE ACCOUNTADMIN;
    
    CREATE OR REPLACE RESOURCE MONITOR limit1 WITH CREDIT_QUOTA=1000
        FREQUENCY = MONTHLY
        START_TIMESTAMP = IMMEDIATELY
        TRIGGERS ON 100 PERCENT DO SUSPEND;
    
    ALTER WAREHOUSE wh1 SET RESOURCE_MONITOR = limit1;
    
  • To create a resource monitor that starts at a specific date and time in the future, resets weekly on the same day and time, has no end date or time, and performs two different suspend actions at different thresholds on two assigned warehouses:

    USE ROLE ACCOUNTADMIN;
    
    CREATE OR REPLACE RESOURCE MONITOR limit1 WITH CREDIT_QUOTA=2000
        FREQUENCY = WEEKLY
        START_TIMESTAMP = '2019-03-04 00:00 PST'
        TRIGGERS ON 80 PERCENT DO SUSPEND
                 ON 100 PERCENT DO SUSPEND_IMMEDIATE;
    
    ALTER WAREHOUSE wh1 SET RESOURCE_MONITOR = limit1;
    
    ALTER WAREHOUSE wh2 SET RESOURCE_MONITOR = limit1;
    

Note

You cannot change the customized schedule for a resource monitor back to the default. You must drop the monitor and create a new monitor.

Modifying a Resource Monitor

You can modify the following properties for an existing resource monitor:

  • Increase or decrease the credit quota for the monitor.

  • If the monitor is monitoring your account, convert it to monitor individual warehouses.

  • If the monitor is monitoring individual warehouses:

    • Add or remove warehouses from the list.

    • Convert it to monitor your account.

  • Customize the schedule (frequency, start timestamp, and end timestamp) for the monitor.

  • Add or remove actions, or modify the threshold percentages for existing actions.

Note

Changing any of these properties does not affect the used credits to-date for the monitor. All changes only affect used credits after the changes are saved.

Resource monitors can be modified through either the web interface or SQL:

Web Interface
  1. Make sure you are using the ACCOUNTADMIN role (or a role that has been granted the MODIFY privilege on the desired resource monitor).

  2. Click on Account Account tab » Resource Monitors.

  3. Click on the resource monitor.

  4. Click Edit.

SQL

The SQL commands you use depend on the change you are making:

For example, to increase the credit quota for limit1 to 3000:

ALTER RESOURCE MONITOR limit1 SET CREDIT_QUOTA=3000;

Note

If a resource monitor has a customized schedule, you cannot change the schedule back to the default. You must drop the monitor and create a new monitor.

Setting a Resource Monitor for Your Account

A resource monitor can be set for your account through either the web interface or SQL:

Web Interface

The process is the same as creating or modifying a resource monitor (see instructions in this topic).

SQL

In SQL, this task is performed in two steps:

  1. Use CREATE RESOURCE MONITOR to create the resource monitor (if it doesn’t exist already).

  2. Use ALTER ACCOUNT to set the resource monitor you created as the monitor for your account.

For example:

USE ROLE ACCOUNTADMIN;

CREATE RESOURCE MONITOR accountmax WITH CREDIT_QUOTA=10000
  TRIGGERS ON 100 PERCENT DO SUSPEND;

ALTER ACCOUNT SET RESOURCE_MONITOR = accountmax;

To view whether a resource monitor is set for your account, use the web interface or the SHOW RESOURCE MONITORS command. The LEVEL column for a resource monitor displays whether it is set for your account or individual warehouses.

Important

An account-level resource monitor only controls the virtual warehouses explicitly created in your account; it does not control credit usage by the Snowflake-provided warehouses (for Snowpipe, Automatic Clustering, and materialized views).

Assigning Warehouses to a Resource Monitor

Warehouses can be assigned to an existing resource monitor through either the web interface or SQL:

Web Interface
  1. Make sure you are using the ACCOUNTADMIN role (or a role that has been granted the MODIFY privilege on the desired resource monitor).

  2. Click on Account Account tab » Resource Monitors.

  3. Click on the resource monitor.

  4. Click Edit.

  5. In Monitor Level, add the desired warehouses. If the monitor does not already have any warehouses assigned, first select Warehouse from the list, then select one or more warehouses.

SQL

Execute an ALTER WAREHOUSE command.

For example, using the resource monitor (limit1) from a previous example, assign a different warehouse to the monitor:

ALTER WAREHOUSE wh3 SET RESOURCE_MONITOR = limit1;

Viewing Resource Monitors

Resource monitors can be viewed through either the web interface or SQL:

Web Interface
  1. Make sure you are using the ACCOUNTADMIN role (or a role that has been granted the MONITOR or MODIFY privilege on the desired resource monitor).

  2. Click on Account Account tab » Resource Monitors.

SQL

Execute a SHOW RESOURCE MONITORS command.

In addition, using any role, you can execute a SHOW WAREHOUSES command to view the warehouses owned by the role (or for which the role has been granted USAGE privilege). The output includes the resource monitor, if any, to which the warehouse is assigned.

Note

For provider accounts that have created reader accounts, Snowflake provides an additional view, RESOURCE_MONITORS. This view can be used for querying resource monitor usage in the provider’s reader accounts. For more details, see Account Usage.