SELECTSUM(CAST(JSON_VALUE(labels.data_boost_usage)ASINT64))ASusage,REGEXP_EXTRACT(proto_payload.audit_log.resource_name,'projects/[^/]+/instances/[^/]+/databases/[^/]+')ASdatabase,proto_payload.audit_log.authentication_info.principal_emailASprincipal_email,IFNULL(JSON_VALUE(labels.data_boost_workload_id),'not from BQ')ASjob_idFROM`PROJECT_NAME.global._Default._AllLogs`WHEREtimestamp > TIMESTAMP_SUB(CURRENT_TIMESTAMP(),INTERVAL7DAY)ANDresource.type='spanner_instance'ANDoperation.lastISNULLANDJSON_VALUE(labels.data_boost_usage)!=''GROUPBYdatabase,principal_email,job_id;
将 PROJECT_NAME 替换为您的项目名称。
以下示例显示了按 BigQuery 作业 ID 细分的用量。
按 BigQuery SQL 文本查看用量
如需查看多个 BigQuery 作业的 Data Boost 用量(按这些作业的 SQL 文本汇总),请按以下步骤操作:
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Monitor Data Boost usage\n\n\u003cbr /\u003e\n\nThis page describes how to use Cloud Monitoring and Spanner audit\nlogs to monitor and analyze Spanner Data Boost usage.\n\nCloud Monitoring provides the ability to track total usage over time and to\nbreak down that usage by user. Spanner audit logs allow more\nflexible usage analysis, including providing metrics by user or by\nBigQuery job ID.\n\nUse Cloud Monitoring to track Data Boost usage\n----------------------------------------------\n\nFollow these steps to track overall Data Boost usage:\n\n1. In the Google Cloud console, go to **Monitoring** . \n [Go to Monitoring](https://console.cloud.google.com/monitoring)\n2. If **Metrics Explorer** is shown in the navigation menu, select it. Otherwise, click **Resources** , and then select **Metrics Explorer**.\n3. At the top of the page, select a time interval.\n4. In the **Metric** drop-down list, in the **Filter by resource or metric\n name** field, enter `spanner` and press `Enter` to narrow the search.\n5. In the **Metric** list, select **Cloud Spanner Instance \\\u003e Instance \\\u003e\n Processing unit second** , and then click **Apply**.\n\n This creates a line chart of aggregate Data Boost usage across\n all Spanner instances.\n6. To view usage for a particular instance, follow these steps:\n\n 1. Use the **Filter** field to add filters, such as the instance ID.\n 2. Click **+** to add other attributes.\n7. To view a breakdown of usage by all instances, follow these steps:\n\n 1. Clear any filters by clicking the **X** icon next to the filter fields.\n 2. In the **Aggregation** operator drop-down list, select **Sum** , and then select by **instance_id**.\n8. To break down usage by principal, in the **Aggregation** operator drop-down,\n select **Sum** , and then select by **credential_id**.\n\nUse audit logs to analyze Data Boost usage\n------------------------------------------\n\nSpanner audit logs allow more flexible analysis of\nData Boost usage. In addition to the ability to break down usage\nover time by instance or principal as with Cloud Monitoring,\nSpanner audit logs, if enabled and available, allow breaking down\nusage over time by database or BigQuery job ID.\n\nEnabling audit logs can incur extra charges. For information about\nLogging pricing, see\n[Google Cloud Observability pricing: Cloud Logging](https://cloud.google.com/stackdriver/pricing#logging-costs).\n\n### Enable Data Boost usage audit logs\n\nYou must enable data access audit logs for Spanner before you can\ncollect usage data for Data Boost. To do so, follow these steps:\n\n1. Follow the instructions in [Configure Data Access audit logs with the Google Cloud console](/logging/docs/audit/configure-data-access#config-console).\n2. Enable the **Data Read** log type for the **Spanner API** service.\n3. To obtain Data Boost usage by BigQuery job SQL text, ensure that that the audit logs for BigQuery are enabled as well.\n\n### View usage by principal\n\nTo query the audit logs to view Data Boost usage by user, follow\nthese steps:\n\n1. Go to the Logs Explorer in the Google Cloud console.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs)\n2. In the navigation menu, click **Log Analytics**.\n\n3. To show usage by user and database over the past 7 days, run the following\n query. To change the timespan for which usage is shown, modify the\n `timestamp` expression in the `WHERE` clause.\n\n SELECT\n SUM(CAST(JSON_VALUE(labels.data_boost_usage) AS INT64)) AS usage,\n REGEXP_EXTRACT(\n proto_payload.audit_log.resource_name,\n 'projects/[^/]+/instances/[^/]+/databases/[^/]+') AS database,\n proto_payload.audit_log.authentication_info.principal_email AS principal_email\n FROM `\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e.global._Default._AllLogs`\n WHERE\n timestamp \u003e TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n AND resource.type = 'spanner_instance' AND operation.last IS NULL\n AND JSON_VALUE(labels.data_boost_usage) != ''\n GROUP BY database, principal_email;\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e with your project name.\n\nThe following example shows usage in processing units for 4 principals.\n\n### View usage by BigQuery job ID\n\nTo query the audit logs to view Data Boost usage broken down by\ndatabase, user, and BigQuery job ID, follow these steps:\n\n1. Go to the Logs Explorer in the Google Cloud console.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs)\n2. In the navigation menu, click **Log Analytics**.\n\n3. Run the following query:\n\n SELECT\n SUM(CAST(JSON_VALUE(labels.data_boost_usage) AS INT64)) AS usage,\n REGEXP_EXTRACT(\n proto_payload.audit_log.resource_name,\n 'projects/[^/]+/instances/[^/]+/databases/[^/]+') AS database,\n proto_payload.audit_log.authentication_info.principal_email AS principal_email,\n IFNULL(JSON_VALUE(labels.data_boost_workload_id), 'not from BQ') AS job_id\n FROM `\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e.global._Default._AllLogs`\n WHERE\n timestamp \u003e TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n AND resource.type = 'spanner_instance' AND operation.last IS NULL\n AND JSON_VALUE(labels.data_boost_usage) != ''\n GROUP BY database, principal_email, job_id;\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e with your project name.\n\nThe following example shows usage by BigQuery job ID.\n\n### View usage by BigQuery SQL text\n\nTo view Data Boost usage for multiple BigQuery jobs\naggregated by the SQL text of those jobs, follow these steps:\n\n1. Go to the Logs Explorer in the Google Cloud console.\n\n [Go to Logs Explorer](https://console.cloud.google.com/logs)\n2. In the navigation menu, click **Log Analytics**.\n\n3. Run the following query:\n\n SELECT\n SUM(\n CAST(\n JSON_VALUE(db.labels.data_boost_usage)\n AS INT64)) AS usage,\n JSON_VALUE(\n bq.proto_payload.audit_log.metadata.jobInsertion.job.jobConfig.queryConfig.query)\n AS bq_query\n FROM\n `\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e.global._Default._AllLogs` db,\n `\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003ePROJECT_NAME\u003c/span\u003e\u003c/var\u003e.global._Default._AllLogs` bq\n WHERE\n db.timestamp \u003e TIMESTAMP_SUB(\n CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n AND db.resource.type = 'spanner_instance'\n AND JSON_VALUE(db.labels.data_boost_usage) != ''\n AND db.operation.last IS NULL\n AND bq.timestamp \u003e TIMESTAMP_SUB(\n CURRENT_TIMESTAMP(), INTERVAL 7 DAY)\n AND bq.proto_payload.audit_log.method_name\n = 'google.cloud.bigquery.v2.JobService.InsertJob'\n AND bq.resource.type = 'bigquery_project'\n AND JSON_VALUE(\n bq.proto_payload.audit_log.metadata.jobInsertion.job.jobConfig.queryConfig.query)\n IS NOT NULL\n AND JSON_VALUE(db.labels.data_boost_workload_id)\n = REGEXP_EXTRACT(bq.proto_payload.audit_log.resource_name, '[^/]*$')\n GROUP BY bq_query\n ORDER BY usage DESC\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_NAME\u003c/var\u003e with your project name.\n\nThe following example shows Data Boost usage by SQL text.\n\nCreate a Data Boost alert\n-------------------------\n\nTo create an alert that is issued when Data Boost usage exceeds\na predefined threshold, see\n[Set an alert for Data Boost usage](/spanner/docs/databoost/databoost-quotas#databoost-alert).\n\nWhat's next\n-----------\n\n- Learn about Data Boost in [Data Boost overview](/spanner/docs/databoost/databoost-overview)."]]