监控预算

本主题介绍如何监控预算支出和确定跟踪特定资源 Credit 使用量的预算。

创建自定义角色以监控预算

您可以创建供非管理员用户用来监控预算的自定义角色,从而委派预算监控。

创建自定义角色以监控账户预算

You can create a custom role to enable non-account administrator users to monitor the account budget. For a full list of privileges and roles that must be granted to a role to monitor the account budget, see Budgets roles and privileges.

示例

Note

只有账户管理员才能执行本示例中的语句。

For example, create role account_budget_monitor and grant the role the ability to view credit usage for the account budget:

USE ROLE ACCOUNTADMIN;

CREATE ROLE account_budget_monitor;
 
GRANT APPLICATION ROLE SNOWFLAKE.BUDGET_VIEWER TO ROLE account_budget_monitor;

GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE TO ROLE account_budget_monitor;

创建自定义角色以监控自定义预算

You can create a custom role to enable non-account administrator users to monitor custom budgets. For a full list of privileges and roles that must be granted to a role to monitor a custom budget, see Budgets roles and privileges.

示例

Note

只有预算所有者(具有 OWNERSHIP 权限的角色)才能执行本示例中的语句。

Use the budget owner role to grant the custom role budget_monitor the ability to monitor the budget my_budget in schema budgets_db.budgets_schema:

USE ROLE custom_budget_owner;

GRANT USAGE ON DATABASE budgets_db TO ROLE budget_monitor;

GRANT USAGE ON SCHEMA budget_db.budgets_schema TO ROLE budget_monitor;

GRANT SNOWFLAKE.CORE.BUDGET ROLE budgets_db.budgets_schema.my_budget!VIEWER
  TO ROLE budget_monitor;

GRANT DATABASE ROLE SNOWFLAKE.USAGE_VIEWER TO ROLE budget_monitor;

监控预算

You can monitor budgets using Snowsight or SQL.

Use Snowsight to monitor budgets

You can view current and historical budget spending using the Budgets page in Snowsight.

Note

Only a user with the ACCOUNTADMIN role or a role granted the required privileges and role can monitor budgets using Snowsight.

  1. Sign in to Snowsight.
  2. In the navigation menu, select Admin » Cost management.
  3. Select Budgets.

In the Current Month view for a budget, you can review the credit usage per day up to the current day. You can see whether you might exceed your budget for the month. The bar graph continues to the end of the month with your projected credit usage based on your actual credit usage for the month. The Spending limit line indicates the spending limit at which a budget notification is triggered.

Select Clock icon (months to display) to filter the view by Current Month or longer time periods.

You can compare the Spend (current credit usage) to Interval (time left in the current month) to see if your spending is outpacing your monthly budget.

You can filter the view by selecting Budgets icon Budgets or Resources icon Resources:

  • You can select a custom budget in the Budgets view for details on a specific budget.

    Note

    The Service Type list for a custom budget includes an Unused Resources type. This service type is displayed when an object in a budget has no credit usage data to display. This can happen if the object has no credit usage for compute costs, or if you recently added an object to a budget and the serverless background task has not yet executed.

  • In the Resources view, you can filter and sort by Service Type, object Name, and Credit Usage.

使用 SQL 命令来监控预算

To monitor the account budget, you must have the required privileges. For more information, see 创建自定义角色以监控账户预算.

Use the account_budget_monitor role to view the spending history for the account budget:

USE ROLE account_budget_monitor;

CALL snowflake.local.account_root_budget!GET_SPENDING_HISTORY(
  TIME_LOWER_BOUND => DATEADD('days', -7, CURRENT_TIMESTAMP()),
  TIME_UPPER_BOUND => CURRENT_TIMESTAMP()
);

您可以按服务类型监控支出历史记录。要查看八个月周期账户预算的搜索优化无服务器功能的支出历史记录,请执行以下语句:

USE ROLE account_budget_monitor;

SELECT *
   FROM table(snowflake.local.account_root_budget!GET_SERVICE_TYPE_USAGE_V2(
         '2025-05', '2025-12'))
   WHERE service_type = 'SEARCH_OPTIMIZATION';

To monitor a custom budget, you must have the required privileges. For more information, see 创建自定义角色以监控自定义预算.

Use the budget_monitor role to view spending history for a custom budget. For example, to view the spending history for custom budget na_finance_budget in schema budgets_db.budgets_schema, execute the following statements:

USE ROLE budget_monitor;

CALL budgets_db.budgets_schema.na_finance_budget!GET_SPENDING_HISTORY(
  TIME_LOWER_BOUND => DATEADD('days', -7, CURRENT_TIMESTAMP()),
  TIME_UPPER_BOUND => CURRENT_TIMESTAMP()
);

您可以按服务类型监控支出历史记录。例如,要查看一年周期预算中包含的物化视图的支出历史记录,请执行以下语句:

USE ROLE budget_monitor;

SELECT *
   FROM table(budgets_db.budgets_schema.na_finance_budget!GET_SERVICE_TYPE_USAGE_V2(
         '2025-05', '2025-12'))
   WHERE service_type = 'MATERIALIZED_VIEW';

For more information, see Budget methods.

确定资源跟踪预算

If you want to determine which budgets track a resource, you can call the SYSTEM$SHOW_BUDGETS_FOR_RESOURCE function.

例如:

SELECT SYSTEM$SHOW_BUDGETS_FOR_RESOURCE('TABLE', 'my_db.my_schema.my_table');
+-----------------------------------------------------------------------+
| SYSTEM$SHOW_BUDGETS_FOR_RESOURCE('TABLE', 'MY_DB.MY_SCHEMA.MY_TABLE') |
%-----------------------------------------------------------------------%
| [BUDGETS_DB.BUDGETS_SCHEMA.MY_BUDGET]                                 |
+-----------------------------------------------------------------------+

该函数返回已在其中添加资源的预算。它包含因以下任意原因而涉及该资源的预算:

  • 资源已直接添加到预算中。
  • 资源的标签/值组合已添加到预算中。
  • 资源属于已添加到预算的对象(例如,数据库)。