如何使用REST检索IBM帐户的使用情况和成本数据?我发现有与计费相关的命令,我可以将一些数据导出为JSON。我是否可以使用API或SDK,最好是Python?
下面是我使用的一些IBM计费命令:
ibmcloud billing resource-instances-usage --json
ibmcloud billing account-usage --json
是否有相应的API?
发布于 2018-09-14 05:40:34
更新: API现在记录在这里:https://cloud.ibm.com/apidocs/metering-reporting
老:
我找不到有文档的API,但使用跟踪来查看上面的命令是如何执行的。使用有效的access_token,程序可以调用计量主机并获取帐户、资源组或所有资源实例的使用数据:
具有帐户ID和月份的GET作为YYYY返回包含所有资源使用和相关成本的JSON对象:
https://metering-reporting.ng.bluemix.net/v4/accounts/account_id/resource_instances/usage/?_limit=100&_names=true
我编写了一个小将数据转储或打印为CSV的Python脚本。
def processResourceInstanceUsage(account_id, billMonth):
METERING_HOST="https://metering-reporting.ng.bluemix.net"
USAGE_URL="/v4/accounts/"+account_id+"/resource_instances/usage/"+billMonth+"?_limit=100&_names=true"
url=METERING_HOST+USAGE_URL
headers = {
"Authorization": "{}".format(iam_token),
"Accept": "application/json",
"Content-Type": "application/json"
}
response=requests.get(url, headers=headers)
print ("\n\nResource instance usage for first 100 items")
return response.json()
发布于 2018-09-14 07:11:14
GitHub回购开式打蛋器.云使用.样品使用一种无服务器的方法通过API获取数据。在回购中包括了一些例子。它是用Javascript编写的,但是它使用开式打蛋器的包被设计成可以声明YAML中的URL和参数(而不是编写代码)来请求和转换JSON。
https://stackoverflow.com/questions/52333121
复制