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 and Usage

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

Credit usage tracks the total number of Snowflake credits consumed 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.

Custom Schedule

By default, a resource monitor starts monitoring credit usage immediately and the usage resets at the beginning of each calendar month (i.e. the start of the standard Snowflake billing cycle).

However, you can define a custom schedule to implement more granular control over the following resource monitor behavior:

Frequency:

The interval at which the credit usage resets back to 0. Supported values:

  • Daily
  • Weekly
  • Monthly
  • Yearly
  • Never (credit quota never resets; warehouses continue using credits until the credit quota is reached)

Note that the actual date when the credit usage resets is relative to the specified start date and time (see next property).

Start:

Date and time (i.e. timestamp) when Snowflake starts monitoring the assigned warehouses. Supported values:

  • Current timestamp (i.e. “Immediately”)
  • Any timestamp beyond the current timestamp

Snowflake also uses this date and time to determine when to reset the credit usage, relative to the specified interval. If you specify the last day of a month as the start date, Snowflake resets credit usage on the last day of all following months, regardless of the number of days in each month. For example, you set the start date to February 28. Snowflake subsequently resets credit usage back to 0 on March 31, April 30, etc.

End:

Date and time (i.e. timestamp) at which Snowflake suspends the warehouses associated with the resource monitor, regardless of whether the credit usage has reached any of the thresholds defined for the resource monitor’s actions. Supported values:

Any timestamp beyond the current timestamp can be specified.

Note that this property is not commonly used.

Note

If you specify a frequency when customizing the schedule for a resource monitor, you must also specify a start timestamp, 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 one Suspend action, one Suspend Immediate action, and 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 credit usage reaches 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 over credit usage 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 credit usage for a resource monitor reflects the sum of all credits used by all assigned warehouses within the specified interval. If a monitor has a Suspend or Suspend Immediately action defined and its usage reaches 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 /sql-reference/sql/alter-resource-monitor` as a separate, additional step.

Also, to receive notifications when resource monitor actions are triggered, you must enable notifications in your preferences in the Snowflake 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 credit usage reaches 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 credit usage reaches 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 credit usage 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 credit usage reaches 100% of 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 the 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;
    

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 credit usage to-date for the monitor. All changes only affect credit usage 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;

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. Create the resource monitor (if it doesn’t exist already).
  2. 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 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.

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 :

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.