You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用BigQuery账单导出查询GCS存储量与Cloud Metrics数据不符排查

问题描述

尝试通过BigQuery用量导出功能查询GCS(Cloud Storage)存储用量,查询结果显示10876GB,远低于Cloud Metrics中显示的309TB。

执行的查询语句:

select name, month, sum(used_storage) as used_storage
from (
  SELECT project.name, sku.description, invoice.month, max(usage.amount_in_pricing_units) as used_storage
  FROM `mybilling_table` 
  WHERE service.description = "Cloud Storage" and sku.description in (
    "Standard Storage US Multi-region",
  "Standard Storage Northern Virginia",
  "Nearline Storage Northern Virginia",
  "Standard Storage US Regional",
  "Coldline Storage Northern Virginia",
  "Nearline Storage US Multi-region",
  "Coldline Storage US Multi-region",
  "Archive Storage US Multi-region",
  "Standard Storage Europe Multi-region",
  "Archive Storage Northern Virginia"
  )
  and project.name = 'my-project'
  and invoice.month = '202211'
  group by 1,2,3

  order by invoice.month desc
)
group by 1,2
order by 1,2 desc

查询返回结果:

name            month   used_storage
my-project      202211  10876.467154139504

疑问:查询语句存在哪些遗漏?

查询语句的遗漏点梳理
  • SKU描述覆盖不全:你手动枚举的SKU列表只包含了部分区域和存储类别的组合,比如遗漏了亚洲区域的所有存储类别、其他未列出的单区域存储(如Standard Storage的欧洲单区域)、特殊存储类别(如Durable Reduced Availability Storage)等,这些未被包含的SKU对应的存储用量自然不会被统计到。
  • 聚合函数使用错误:usage.amount_in_pricing_units在GCS账单数据中,通常是每日存储快照值或周期内累计用量,用max()只会取该SKU下的最大值,而非正确的统计逻辑。如果是统计月度总用量,应该用sum()(若为每日累计)或avg()(若为每日快照的月度平均值),具体取决于账单数据的统计规则。
  • 项目范围过滤可能不全:如果你的项目存在关联子项目、文件夹下的其他项目,或者存储资源归属到了其他项目ID,仅过滤project.name = 'my-project'会漏掉这部分用量,需要确认所有存储资源对应的项目是否都被纳入查询。
  • 统计口径不匹配:Cloud Metrics显示的可能是月度峰值存储量,而账单数据的统计逻辑是月度平均存储量或计费周期内的累计用量,两者统计口径不同会导致数值差距,需要对齐两者的统计规则。
  • 单位认知偏差:需确认usage.amount_in_pricing_units的单位——GCS账单中存储用量的单位可能是TB而非GB,若你误将数值当成GB计算,会进一步放大差距(不过此案例中10876TB和309TB差距过大,核心还是前面的SKU和聚合问题)。

内容的提问来源于stack exchange,提问作者lightweight

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 09:20:42