0

I want to know:

  1. how to get the number of queries a user makes per month in BigQuery?
  2. how many queries a specific user makes, how many per year.

I found the command

bq ls -j

with that bring the number of jobs and with the comand bq show get the detail, but it does not bring me all the elements that I need, I would like to know if someone knows another way to achieve this.

4

1 回答 1

1

您需要启用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
于 2021-08-19T06:47:57.053 回答