如何使用 StackDriver API 的 v2 查询 BigQuery 用法?
How to query BigQuery usage with v2 of the StackDriver API?
我计划使用 StackDriver API 跟踪 BigQuery 的使用情况,并且有一个很好的设置教程 here. However, the queries here use the deprecated v1 of the API and the 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 )
我计划使用 StackDriver API 跟踪 BigQuery 的使用情况,并且有一个很好的设置教程 here. However, the queries here use the deprecated v1 of the API and the 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 )