python - IBM云: How to access the API for billing and usage?

标签 python ibm-cloud billing

如何使用 REST API 检索我的 IBM Cloud 帐户的使用情况和成本数据?我发现有billing related commands and I can export some data as JSON 。是否有我可以使用的 API 或 SDK,最好是 Python?

以下是一些 IBM Cloud billing commands我使用:

ibmcloud billing resource-instances-usage --json

ibmcloud billing  account-usage --json

是否有等效的 API?

最佳答案

更新: API 现在记录在此处:https://cloud.ibm.com/apidocs/metering-reporting


旧版:

我找不到记录的 API,但使用跟踪来查看上述命令是如何执行的。使用有效的access_token,程序可以调用计量主机并获取帐户、资源组或所有资源实例的使用数据:

对以下 URL 执行 GET 操作,其中包含帐户 ID 和 YYYY-MM 月份,会返回一个 JSON 对象,其中包含所有资源使用情况和相关成本:

https://metering-reporting.ng.bluemix.net/v4/accounts/account_id/resource_instances/usage/?_limit=100&_names=true

我编码了一个小Python script that dumps that data or prints it as CSV .

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()

关于python - IBM云: How to access the API for billing and usage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52333121/

相关文章:

docker - Bluemix 安全网关 Docker 客户端的高可用性

google-app-engine - Google应用程序引擎配额已过期,如何紧急配置新实例

payment - 在您刚开始学习的平台上完成的工作计费的道德规范

python - 尝试下载 nltk 数据时出现 405 错误

python - 使用 Python 的 MySQLdb 更新 MySQL 表的问题

python - Numpy:制作四元数乘法的批处理版本

ios - 无法将通知推送到 iOS9 设备

python - 使用 set_fig(width/height) 调整 matplotlib 图的大小不起作用

ssl - 自定义 SSL 证书上传失败

database - Heroku billing dynos 是如何工作的?