首页 > 解决方案 > 有没有办法在一次 api 调用中获得整合的 IBM Cloud 计费

问题描述

我需要获得基于组织或资源组的综合账单。就像是:

    org1   $100
    org2   $200
    rg1    $150

有没有一种方法可以在一个 api 调用中得到这个?我可以使用以下 cli 命令获得详细的账单:

ibmcloud billing account-usage

标签: ibm-cloudbilling

解决方案


@VidyasagarMachupalli 和@data_henrik 的答案是合适的。虽然没有单一的 API 调用,但ibmcloud billing resource-instances-usage它提供了最接近的解决方案,因为它根据组织、空间和资源组对数据进行分段。

您可以使用电子表格(即数据透视表)进行最后一步,并对整个组织或资源组的数据求和。提到的教程(本节)使用 IBM Cloud CLI、jq 和 json2csv 完全采用这种方法。

ibmcloud billing resource-instances-usage --output json | jq '.[] | {month,resource_name,resource_group_name,organization_name,space_name,metric: .usage[].metric,cost : .usage[].cost}' | json2csv -f month,resource_name,resource_group_name,organization_name,space_name,metric,cost -p

┌───────────────┬──────────────────────────────┬──────────────────────────────────────────┬──────────────────────────────────────┬────────────────────────┬────────────────┬───────────────┐
│ "month"       │ "resource_name"              │ "resource_group_name"                    │ "organization_name"                  │ "space_name"           │ "metric"       │ "cost"        │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "AUTHORIZED_US │               │
│ "2018-11"     │ "Continuous Delivery"        │ "default"                                │ ""                                   │ ""                     │ ERS_PER_MONTH" │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "AUTHORIZED_US │               │
│ "2018-11"     │ "Continuous Delivery"        │ "default"                                │ ""                                   │ ""                     │ ERS_PER_MONTH" │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "JOB_EXECUTION │               │
│ "2018-11"     │ "Continuous Delivery"        │ "default"                                │ ""                                   │ ""                     │ S_PER_MONTH"   │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "JOB_EXECUTION │               │
│ "2018-11"     │ "Continuous Delivery"        │ "default"                                │ ""                                   │ ""                     │ S_PER_MONTH"   │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "DEVOPS_INSIGH │               │
│ "2018-11"     │ "DevOps Insights"            │ "default"                                │ ""                                   │ ""                     │ TS_ITEMS"      │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "instance_hour │               │
│ "2018-11"     │ "Kubernetes Service"         │ "default"                                │ ""                                   │ ""                     │ s"             │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "DATA_POINTS_P │               │
│ "2018-11"     │ "Monitoring"                 │ ""                                       │ "van_org"                            │ "dev"                  │ ER_MONTH"      │ 0             │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │ "IBM Bluemix Platform Runtim │                                          │                                      │                        │ "GB_HOURS_PER_ │               │
│ "2018-11"     │ e"                           │ ""                                       │ "van_org"                            │ "dev"                  │ MONTH"         │ 0.00035       │
├───────────────┼──────────────────────────────┼──────────────────────────────────────────┼──────────────────────────────────────┼────────────────────────┼────────────────┼───────────────┤
│               │                              │                                          │                                      │                        │ "GB_HOURS_PER_ │ 3.51056366597 │
│ "2018-11"     │ "IBM Bluemix Node.js"        │ ""                                       │ "van_org"                            │ "dev"                  │ MONTH"         │ 2222          │

推荐阅读