简体   繁体   English

按元数据标签对 GCP 计费数据进行排序

[英]sort GCP billing data by metadata tags

I'm a little confused in GCP with tags , labels and metadata and I do not find how to sort my billing informations by the metadata tags i set for every objects in the storage.我在 GCP 中对tagslabelsmetadata有点困惑,我找不到如何通过我为存储中的每个对象设置的元数据标签对我的账单信息进行排序。 I have added a metadata tagging process which gives the id of the account that uploads a file through signed url headers or through blobs uploads.我添加了一个元数据标记过程,它给出了通过签名的 url 标头或通过blob上传上传文件的帐户的 ID。 Then I launch requests on the billing with big query .然后我使用big query发起计费请求。 ...but I do not see my tags in the "labels" field of the exports How can I enable metadata tags sorting on billing exports? ...但我在导出的“标签”字段中看不到我的标签 如何在计费导出中启用元数据标签排序?

Thank you for your help谢谢您的帮助

Metadata identifies properties of the object, as well as specifies how the object should be handled when it's accessed. 元数据标识对象的属性,并指定在访问对象时应如何处理该对象。 Metadata exists as key:value pairs. 元数据以键:值对的形式存在。 Metadata has fixed-key metadata, also Custom metadata, that is to say you can add any key:value value in your metadata. 元数据有固定键的元数据,也有自定义元数据,也就是说你可以在元数据中添加任意键值:

If a group of GCP resources has the same key:value in its custom mateadata, who can take this key:value as the Bucket labels are key:value that allow you to group your buckets along with other Google Cloud resources such as virtual machine instances and persistent disks. 如果一组 GCP 资源在其自定义 mateadata 中具有相同的键:值,谁可​​以将此键:值作为存储分区标签是键:值,允许您将存储分区与其他 GCP 资源(例如虚拟机实例)一起分组和永久性磁盘。

Tagging actually is like a condition, for example, I want to query those resources which have a specific key:value, then the service will look for those resources which have a label the same as key value. 标记实际上就像一个条件,例如,我想查询具有特定键值的资源,然后服务将查找具有与键值相同的标签的资源。

May the explanation is still not easy to understand, let me use sql query as an example.可能解释还是不太好理解,我以sql查询为例。

SELECT GCP.Resources.Cost FROM GCP.Resources WHERE GCP.Resources.Lable = Tag GROUP BY GCP.Resources.Metadata SELECT GCP.Resources.Cost FROM GCP.Resources WHERE GCP.Resources.Lable = Tag GROUP BY GCP.Resources.Metadata

GCP billing doesn't break down Bucket costs by object. GCP 计费不会按 object 细分存储桶成本。

It simply tells you how much the whole bucket cost you.它只是告诉你整个桶花了你多少钱。

If you want to calculate what portion of your Bucket bill can be attributed to an object you will need to know when the object was uploaded and how big it was, and then do math to calculate the portion of the cost it's responsible for.如果您想计算您的 Bucket 账单的哪一部分可归因于 object,您需要知道 object 的上传时间和大小,然后进行数学计算以计算其负责的成本部分。

You would need to turn on logging on the buck to get that data.您需要打开降压日志以获取该数据。

Tags data is available in both the Standard usage cost export and the Detailed usage cost export标签数据在标准使用成本导出和详细使用成本导出中均可用

SELECT
  invoice.month AS invoice_month,
  tag.value AS cost_center,
  ROUND((SUM(CAST(cost AS NUMERIC))
    + SUM(IFNULL((SELECT SUM (CAST(c.amount AS NUMERIC))
                  FROM UNNEST(credits) AS c), 0))), 2)
    AS net_cost
FROM `ivory-vim-309221.billing_export_dataset.gcp_billing_export_resource_v1_018ADD_3CEBBB_A4DF22`, UNNEST(tags) AS tag
WHERE tag.key = "cost_center" AND tag.namespace = "821092389413"
GROUP BY invoice.month, tag.value
ORDER BY invoice.month, tag.value;

https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/standard-usage#tags https://cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/standard-usage#tags

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM