google-bigquery - 如何使用 StackDriver API v2 查询 BigQuery 使用情况?

标签 google-bigquery google-cloud-platform stackdriver

我计划使用 StackDriver API 跟踪 BigQuery 的使用情况,并且有一个很好的教程来设置它here .但是,这里的查询使用 deprecated v1 API 和 available documentation也仍然适用于 v1。

在 BigQuery 控制台中,v2 仅提供以下字段:

logName
timestamp
severity
insertId
resource
resource.type
resource.labels
resource.labels.project_id
httpRequest
httpRequest.requestMethod
httpRequest.requestUrl
httpRequest.requestSize
httpRequest.status
httpRequest.responseSize
httpRequest.userAgent
httpRequest.remoteIp
httpRequest.serverIp
httpRequest.referer
httpRequest.cacheHit
httpRequest.cacheValidatedWithOriginServer
httpRequest.latency
httpRequest.cacheLookup
httpRequest.cacheFillBytes
operation
operation.id
operation.producer
operation.first
operation.last
protopayload_google_cloud_audit_auditlog
protopayload_google_cloud_audit_auditlog.serviceName
protopayload_google_cloud_audit_auditlog.methodName
protopayload_google_cloud_audit_auditlog.resourceName
protopayload_google_cloud_audit_auditlog.numResponseItems
protopayload_google_cloud_audit_auditlog.status
protopayload_google_cloud_audit_auditlog.status.code
protopayload_google_cloud_audit_auditlog.status.message
trace
sourceLocation  
sourceLocation.file 
sourceLocation.line 
sourceLocation.function

现在没有 totalBilledBytes 字段,它在示例 v1 查询中用于计算使用量。如何使用API​​的v2查询使用成本?

最佳答案

有个好tutorial用于查询审计日志以获取此信息。这是来自那里的示例查询(假设您已经将审核日志数据导出回 BigQuery)。

SELECT
  query_date,
  ROUND(((total_bytes*5)/1000000000000),2) Cost_In_Dollars
FROM (
  SELECT
    STRFTIME_UTC_USEC(metadata.timestamp,"%Y-%m-%d") AS query_date,
    SUM(protoPayload.serviceData.jobCompletedEvent.job.jobStatistics.totalBilledBytes) AS total_bytes
  FROM
    TABLE_DATE_RANGE(AuditLogs.cloudaudit_googleapis_com_data_access_, DATE_ADD(CURRENT_TIMESTAMP(), -7, 'DAY'), CURRENT_TIMESTAMP())
  WHERE
    protoPayload.serviceData.jobCompletedEvent.eventName = 'query_job_completed'
  GROUP BY
    query_date )

关于google-bigquery - 如何使用 StackDriver API v2 查询 BigQuery 使用情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41636106/

相关文章:

arrays - Bigquery - 如何将两个数组压缩为一个?

google-bigquery - 如何在 BigQuery 中进行子选择

firebase - 将数据从Firestore导入到bigQuery中

java - 如何衡量我的 Google App Engine(网络应用程序)计划每天可以处理多少个请求?

kubernetes - GKE群集不受StackDriver监视

google-cloud-platform - 我可以在 Kubernetes Pod 中运行 Google Monitoring Agent 吗?

python - Google BigQuery 对奇怪尝试的不完整查询回复

java - 如何使用 Google Cloud Endpoints 返回文件?

kubernetes - 从 GKE 上的 pod 访问 GCP Cloud DNS

python - 如何将日志记录 'tags' 添加到 stackdriver