Managing Resource Monitors

A virtual warehouse consumes Snowflake credits for each hour that 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 related to using warehouses, Snowflake provides resource monitors. Resource Monitors can be used by account administrators (i.e. users with the ACCOUNTADMIN role) to impose limits on the number of credits that warehouses can consume within each monthly billing period. When these limits are approaching and/or reached, the resource monitor can trigger various actions, such as sending alert notifications and suspending the warehouses.

In this Topic:

Overview

Resource Monitor Properties

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

Credit quota:

The number of Snowflake credits allocated to the monitor for each monthly billing period.

Credit usage:

The total accumulated number of Snowflake credits used/consumed during the current monthly billing period by all warehouses assigned to the monitor. At the beginning of each monthly billing cycle, this number resets to 0.

Triggers:

A credit quota threshold, specified as a percentage (values greater than 100 are allowed), and an action to perform when the threshold is reached. If credit usage reaches the threshold for the monthly billing period, the trigger fires and the action defined for the threshold is performed. The following actions are supported:

  • Suspend: Send a notification (to all account administrators with notifications enabled) and suspend assigned warehouse(s) after all statements being executed by the warehouse(s) have completed.
  • Suspend Immediately: Send a notification (to all account administrators with notifications enabled) and suspend assigned warehouse(s) immediately, which cancels any statements being executed by the warehouse(s) at the time.
  • Notify: Send an alert notification (to all account administrators with notifications enabled), but perform no other actions. Each resource monitor can have up to 5 alert notifications defined.

A resource monitor must have at least one trigger defined to perform any actions (i.e. if a monitor does not have any triggers defined, nothing happens when the credit usage reaches the credit quota threshold for the month).

Resource Monitor Assignment

A monitor can be assigned one or more warehouses, thereby controlling the credit usage for each warehouse assigned to it. Note, however, each warehouse can be assigned to only a single resource monitor. In addition, a monitor can also be set at the account level to control credit usage for all warehouses in your account.

Important

An account-level resource monitor does not override resource monitor assignment for individual warehouses. If either resource monitor reaches its defined threshold, the warehouse is suspended. This enables controlling global credit usage while also providing fine-grained control over credit usage for individual/specific warehouses.

The following diagram illustrates a resource monitor set at the account level, as well as resource monitors assigned individual warehouses:

Warehouse and resource monitor relationships

Based on this diagram:

  • The credit quota for the entire account is 5000 per month (dictated by Resource Monitor 1); if this quota is reached, the actions defined for the resource monitor (e.g. warehouse suspension) are enforced.
  • Warehouse 3 can consume a maximum of 1000 credits for the month.
  • Warehouse 4 and 5 can consume a maximum combined total of 2500 credits for the month.
  • 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.

Warehouse Suspension and Resumption

The credit usage for a resource monitor reflects the sum of all credits used by all warehouses assigned the monitor during the current billing period. If a monitor’s usage reaches its quota for the month and a suspend action has been triggered for the monitor, any warehouses associated with the monitor are suspended and cannot be resumed until one of the following conditions is met:

  • A new monthly billing cycle starts.
  • The credit quota for the monitor is increased.
  • The credit threshold for the monitor trigger is increased.
  • The monitor is no longer assigned to the warehouse.
  • The monitor is dropped.

Tip

Resource monitors are intended for tracking and controlling credit consumption on a monthly basis; they are not intended for strictly controlling consumption on an hourly basis. 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 that you set for each trigger action (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 warehouses share the same resource monitor, they share monitor thresholds, which may result in credit usage for one warehouse impacting the other assigned warehouses.

Resource Monitor Notifications

When a resource monitor reaches a threshold for a trigger, it generates a notification for the action defined for the threshold:

  • Suspend the assigned warehouse(s) after all running queries complete.
  • Immediately cancel all running queries and suspend the assigned warehouse(s).
  • Send an alert that the threshold has been reached.

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

  • 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 (and verify) a valid email 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:

Enabling Receipt of Notifications

As an account administrator, you must enable notifications before you can receive any notifications generated by resource monitors. To enable notifications for yourself:

  1. Log into the Snowflake web interface.
  2. 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.
  3. In the same drop-down menu, select Preferences > Notifications.
  4. 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.
  5. To complete the process, you must validate the email address you entered by following the instructions provided on-screen.

Creating Resource Monitors

Note

Only account administrators (i.e. users with the ACCOUNTADMIN role) can create resource monitors.

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

Web Interface:
  1. Make sure you are using the ACCOUNTADMIN role.
  2. Click on Account > Resource Monitors > Create Resource Monitor.
  3. Enter a name and quota, and specify whether the resource monitor will be used for monitoring your account or individual warehouses (default is Account).
  4. You can also specify suspend actions and up to 5 alert notifications.
SQL:

CREATE RESOURCE MONITOR

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 can do this at creation time.
  • In SQL, you must create the resource monitor first, then assign one or more warehouses to it using a separate command.

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

The following three examples illustrate using SQL to create a resource monitor:

  • The first SQL example creates a monitor named limit1 that generates a notification and suspends all associated warehouses when 100% of the quota (1000 credits) is reached for the month:

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

    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 prevent warehouses from consuming credits after the quota has been reached, use SUSPEND_IMMEDIATE. For example:

    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;
    

    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.

  • Use NOTIFY actions to alert account administrators when usage for a resource monitor is nearing the quota:

    CREATE OR REPLACE RESOURCE MONITOR limit WITH CREDIT_QUOTA=1000
       TRIGGERS ON 50 PERCENT DO NOTIFY
                ON 80 PERCENT DO NOTIFY
                ON 100 PERCENT DO SUSPEND
                ON 120 PERCENT DO SUSPEND_IMMEDIATE;
    

    In this example, when 50% and 80% usage is reached, an alert notification is sent to all account administrators who have enabled notifications, but no other actions are performed.

Assigning Warehouses to a Resource Monitor

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

Web Interface:

You can assign warehouses when creating a resource monitor or after the monitor has been created; however, for an existing resource monitor, you can only assign warehouses through the interface if the resource monitor is not assigned to the account. If the resource monitor is already assigned to the account, you must drop and recreate it.

To assign warehouses to a non-Account resource monitor:

  1. Make sure you are using the ACCOUNTADMIN role.
  2. Click on Account > Resource Monitors.
  3. Click on the resource monitor to display the details panel.
  4. Click Edit.
  5. Select Warehouse, then select one or more warehouses from the list.
SQL:

The following SQL example uses the warehouse (mywh) and resource monitor (limit1) created in the previous example:

ALTER WAREHOUSE mywh SET RESOURCE_MONITOR = limit1;

Modifying a Resource Monitor

You can modify the monthly credit quota for a monitor, as well as change the trigger percentages for the monitor and add more notifications.

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

Web Interface:
  1. Make sure you are using the ACCOUNTADMIN role.
  2. Click on Account > Resource Monitors.
  3. Click on the resource monitor to display the details panel.
  4. Click Edit.
  5. Change the credit quota or suspend action percentages, or add more notifications.
SQL:

ALTER RESOURCE MONITOR

The following SQL example changes the monthly credit quota for limit1 to 2000:

ALTER RESOURCE MONITOR limit1 SET CREDIT_QUOTA=2000;

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.
  2. Click on Account > Resource Monitors.
  3. Click on a resource monitor to display the details panel.
SQL:

SHOW RESOURCE MONITORS

In addition, with any role, you can use the 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.

Defining a Global Resource Monitor for Your Account

Global monthly credit usage for an account can be controlled by setting a resource monitor at the account level. When the combined credit usage for all warehouses in the account reaches the defined threshold, all the warehouses are suspended.

For example:

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 SHOW RESOURCE MONITORS command. In the output, if ACCOUNT appears in the LEVEL column for a resource monitor, it is set for the account.