我目前正在使用烧瓶为在GKE上运行的在线服务构建管理仪表板。
我想显示自本月初以来该服务已累积了多大的账单。我已经研究过Google Cloud计费API,但这是一个血腥的丛林,我似乎找不到任何方法来检索所需的数据。
我认为应该可以,但我不知道如何做到。任何对Google Cloud API经验丰富的人都可以帮助我,最好是使用python代码段吗?
我看过this post中的答案,但无法真正弄清楚如何使用它们。
官方文档:
Get started with the Cloud Billing Budget API
Cloud Billing Budget API Setup
Using the Cloud Billing Budget API
Cloud Billing Budget Client Libraries
使用Cloud Billing Budget API来:
为每个Google Cloud项目创建单独的预算,这样您就可以了解您的Google Cloud环境中哪些方面的支出更多超出预期。
[在季度财务计划后批量更新所有预算。
与您公司的部署经理集成以添加创建您的云配置工作流程中的预算。
使用客户端库Client for Cloud Billing Budget API
from google.cloud import billing_budgets_v1beta1
client = billing_budgets_v1beta1.BudgetServiceClient()
#get all the budgets
parent = client.billing_account_path([BILLING_ACCOUNT])
for element in client.list_budgets(parent):
print(element)
pass
#for a specific budget
name = client.budget_path('[BILLING_ACCOUNT]', '[BUDGET]')
response = client.get_budget(name)
#The output should be in the form
display_name: "billing-budget"
budget_filter {
projects: "projects/"
credit_types_treatment:
}
amount {
last_period_amount {
}
}
threshold_rules {
threshold_percent: 0.5
spend_basis: CURRENT_SPEND
}
threshold_rules {
threshold_percent: 0.9
spend_basis: CURRENT_SPEND
}
threshold_rules {
threshold_percent: 1.0
spend_basis: CURRENT_SPEND
}
all_updates_rule {
}
etag: "" ```