如何使用Python获取Google Cloud Platform的计费信息

huangapple go评论51阅读模式
英文:

How to fetch billing info for Google Cloud Platform using python

问题

可以使用Python客户端库使用计费API获取我们项目的结算信息吗?例如,如果我想知道特定月份每个虚拟机产生的费用,应该如何操作?

英文:

Can we fetch the billing info for our projects using Billing API using python client libraries? For example if I wanted to know the cost incurred with each VM for a specified month, how would I should do it?

答案1

得分: 1

如在文档Python Cloud Billing API客户端中提到:

> 云计费 API:允许开发人员管理其计费帐户
> 或浏览 SKU 和定价目录。

要使用此库,您首先需要执行以下步骤:

  1. 选择或创建一个云平台项目。
  2. 为您的项目启用计费。
  3. 启用云计费 API。
  4. 设置身份验证。

还可以参考云计费客户端库文档

更新:

正如@John hanley所提到的,Google没有提供API来获取计费成本详细信息。

您需要启用将云计费数据导出到BigQuery

> 要将云计费数据导出到BigQuery,请执行以下步骤:
>
> 1. 创建一个用于存储云计费数据的项目,并在项目上启用计费(如果尚未完成)。
>
> 2. 在项目和云计费帐户上配置权限。
>
> 3. 启用BigQuery数据传输服务API(用于导出您的定价数据所需)。
>
> 4. 创建一个BigQuery数据集,用于存储数据。
>
> 5. 启用将成本数据和定价数据导出到数据集中的云计费导出。

英文:

As mentioned in the document Python Client for Cloud Billing API:

> Cloud billing API: allows developers to manage their billing accounts
> or browse the catalog of SKUs and pricing.

In order to use this library, you first need to go through the following steps:

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Cloud Billing API.
  4. Setup Authentication.

Also refer to this document on Cloud Billing Client Libraries.

Update:

As @John hanley mentioned , Google does not provide an API to fetch billing cost details.

You have to enable Cloud Billing data export to BigQuery.

> To export Cloud Billing data to BigQuery, take the following steps:
>
> 1. Create a project where the Cloud Billing data will be stored, and enable billing on the project (if you have not already done so).
>
> 2. Configure permissions on the project and on the Cloud Billing account.
>
> 3. Enable the BigQuery Data Transfer Service API (required to export your pricing data).
>
> 4. Create a BigQuery dataset in which to store the data.
>
> 5. Enable Cloud Billing export of cost data and pricing data to be written into the dataset.

huangapple
  • 本文由 发表于 2023年6月5日 18:18:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405445.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定