lim*_*ack 4 google-api google-cloud-platform google-kubernetes-engine google-cloud-billing
我目前正在使用 Flask 为在 GKE 上运行的在线服务构建一个管理仪表板。
我想展示自本月初以来该服务已经产生了多少账单。我研究过 Google Cloud 计费 API,但这是一个血腥的丛林,我似乎找不到任何方法来检索我想要的数据。
我认为这应该是可能的,但我不知道如何实现。任何对 Google Cloud API 更有经验的人都可以帮助我吗?最好是使用 python 代码片段?
我已经查看了这篇文章中的答案,但无法真正弄清楚如何使用它们。
官方文档:
\n\n\n\n\n\n\n\n\n\n\n\n\n使用 Cloud Billing Budget API 可以:
\n\n为您的每个 Google Cloud 项目制定单独的预算,以便您\n 了解 Google Cloud 环境的哪些领域的支出\n 超出预期。
\n\n在季度财务规划后批量更新您的所有预算。
\n\n与您公司的部署管理器集成,将预算创建添加到您的云配置工作流程中。
\n
使用客户端库Client for Cloud Billing Budget API
\n\nfrom google.cloud import billing_budgets_v1beta1\nclient = billing_budgets_v1beta1.BudgetServiceClient()\n\n#get all the budgets\nparent = client.billing_account_path([BILLING_ACCOUNT])\nfor element in client.list_budgets(parent):\n print(element)\n pass\n\n#for a specific budget\nname = client.budget_path(\'[BILLING_ACCOUNT]\', \'[BUDGET]\')\nresponse = client.get_budget(name)\n\n#The output should be in the form \nRun Code Online (Sandbox Code Playgroud)\n\ndisplay_name: "billing-budget"\nbudget_filter {\nprojects: "projects/"\ncredit_types_treatment: \n}\namount {\nlast_period_amount {\n}\n}\nthreshold_rules {\nthreshold_percent: 0.5\nspend_basis: CURRENT_SPEND\n}\nthreshold_rules {\nthreshold_percent: 0.9\nspend_basis: CURRENT_SPEND\n}\nthreshold_rules {\nthreshold_percent: 1.0\nspend_basis: CURRENT_SPEND\n}\nall_updates_rule {\n}\netag: "" ```\nRun Code Online (Sandbox Code Playgroud)我检查了gcloud alpha billing命令,只能看到选项:
1. accounts(describe, get-iam-policy, list, projects(describe, link, list, unlink))\n\n 2. budgets(create, delete, describe, list, update) \n\n 3. projects(describe, link, list, unlink). These are the API that you can call. \nRun Code Online (Sandbox Code Playgroud)\n\n没有 API 可以让我了解当前的支出情况。您可以将账单导出到 BigQuery 或文件(已弃用)并进行分析。
\n| 归档时间: |
|
| 查看次数: |
1880 次 |
| 最近记录: |