您需要启用Audit Logs,并为 Bigquery 创建一个接收器。
然后您可以编写一个查询,用于protoPayload.methodName
第一列的google.cloud.bigquery.v2.JobService.Query
值
示例:每个用户身份处理的字节数
此查询显示每个用户为查询作业计费的总字节数,以 TB 为单位。
#standardSQL
WITH data as
(
SELECT
protopayload_auditlog.authenticationInfo.principalEmail as principalEmail,
protopayload_auditlog.metadataJson AS metadataJson,
CAST(JSON_EXTRACT_SCALAR(protopayload_auditlog.metadataJson,
"$.jobChange.job.jobStats.queryStats.totalBilledBytes") AS INT64) AS totalBilledBytes,
FROM
`MYPROJECTID.MYDATASETID.cloudaudit_googleapis_com_data_access_*`
)
SELECT
principalEmail,
FORMAT('%9.2f',SUM(totalBilledBytes)/POWER(2, 40)) AS Billed_TB
FROM
data
WHERE
JSON_EXTRACT_SCALAR(metadataJson, "$.jobChange.job.jobConfig.type") = "QUERY"
GROUP BY principalEmail
ORDER BY Billed_TB DESC