有没有一种方法可以通过一个api调用获得整合的IBM Cloud账单

时间:2018-11-20 14:00:22

标签: ibm-cloud billing

我需要获取基于组织或资源组的合并账单。像这样:

    org1   $100
    org2   $200
    rg1    $150

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

ibmcloud billing account-usage

3 个答案:

答案 0 :(得分:1)

没有单个API调用可提供每个组织的使用情况。但是有API调用ibmcloud billing org-usage $org可以检索单个ORG的用法。您可以编写一个小的Shell脚本来在组织列表中循环调用API。

#!/bin/bash
ibmcloud login --apikey @ibmcloud_key
ibmcloud target  -o ORGNAME1 -s SPACENAME 
org_list=(ORGNAME1 ORGNAME2)
echo "Get usage for each org...." 
for org in "$org_list[@]"
do
    ibmcloud billing org-usage $org >> billing.txt
done

答案 1 :(得分:1)

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

您可以使用电子表格(例如数据透视表)进行最后一步,并汇总整个组织或资源组的数据。提到的教程this section-使用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          │

答案 2 :(得分:0)

IBM Cloud提供了usage meteringusage reports的API。集成的API overview page in the IBM Cloud docs在“平台服务”下列出了它们。

我也推荐此IBM Cloud solution tutorial on reviewing cloud usage进行介绍。我刚刚检查了一下,它还没有新的API,但是仍然值得阅读。