Is there a way to get consolidated IBM Cloud billing in one api call












2















I need to get a consolidated bill based on organizations or resource groups. Something like:



    org1   $100
org2 $200
rg1 $150


Is there a way I can get this in one api call? I can get a detailed bill using following cli command:



ibmcloud billing account-usage









share|improve this question

























  • Possible duplicate of stackoverflow.com/questions/52333121/…

    – Vidyasagar Machupalli
    Nov 20 '18 at 15:23











  • @VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

    – NoviceMe
    Nov 20 '18 at 15:39











  • I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

    – data_henrik
    Nov 20 '18 at 15:53











  • @data_henrik - preferably an api call so I can send a consolidated bill as an email.

    – NoviceMe
    Nov 20 '18 at 15:56
















2















I need to get a consolidated bill based on organizations or resource groups. Something like:



    org1   $100
org2 $200
rg1 $150


Is there a way I can get this in one api call? I can get a detailed bill using following cli command:



ibmcloud billing account-usage









share|improve this question

























  • Possible duplicate of stackoverflow.com/questions/52333121/…

    – Vidyasagar Machupalli
    Nov 20 '18 at 15:23











  • @VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

    – NoviceMe
    Nov 20 '18 at 15:39











  • I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

    – data_henrik
    Nov 20 '18 at 15:53











  • @data_henrik - preferably an api call so I can send a consolidated bill as an email.

    – NoviceMe
    Nov 20 '18 at 15:56














2












2








2








I need to get a consolidated bill based on organizations or resource groups. Something like:



    org1   $100
org2 $200
rg1 $150


Is there a way I can get this in one api call? I can get a detailed bill using following cli command:



ibmcloud billing account-usage









share|improve this question
















I need to get a consolidated bill based on organizations or resource groups. Something like:



    org1   $100
org2 $200
rg1 $150


Is there a way I can get this in one api call? I can get a detailed bill using following cli command:



ibmcloud billing account-usage






ibm-cloud billing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 18 '18 at 20:39









Jim Kennedy

156




156










asked Nov 20 '18 at 14:00









NoviceMeNoviceMe

71383783




71383783













  • Possible duplicate of stackoverflow.com/questions/52333121/…

    – Vidyasagar Machupalli
    Nov 20 '18 at 15:23











  • @VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

    – NoviceMe
    Nov 20 '18 at 15:39











  • I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

    – data_henrik
    Nov 20 '18 at 15:53











  • @data_henrik - preferably an api call so I can send a consolidated bill as an email.

    – NoviceMe
    Nov 20 '18 at 15:56



















  • Possible duplicate of stackoverflow.com/questions/52333121/…

    – Vidyasagar Machupalli
    Nov 20 '18 at 15:23











  • @VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

    – NoviceMe
    Nov 20 '18 at 15:39











  • I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

    – data_henrik
    Nov 20 '18 at 15:53











  • @data_henrik - preferably an api call so I can send a consolidated bill as an email.

    – NoviceMe
    Nov 20 '18 at 15:56

















Possible duplicate of stackoverflow.com/questions/52333121/…

– Vidyasagar Machupalli
Nov 20 '18 at 15:23





Possible duplicate of stackoverflow.com/questions/52333121/…

– Vidyasagar Machupalli
Nov 20 '18 at 15:23













@VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

– NoviceMe
Nov 20 '18 at 15:39





@VidyasagarMachupalli - That is a very old question, things have changed a lot since then.

– NoviceMe
Nov 20 '18 at 15:39













I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

– data_henrik
Nov 20 '18 at 15:53





I recommend this tutorial to get an overview: console.bluemix.net/docs/tutorials/cloud-usage.html It does not provide a single command. Are you looking for an API or a command?

– data_henrik
Nov 20 '18 at 15:53













@data_henrik - preferably an api call so I can send a consolidated bill as an email.

– NoviceMe
Nov 20 '18 at 15:56





@data_henrik - preferably an api call so I can send a consolidated bill as an email.

– NoviceMe
Nov 20 '18 at 15:56












3 Answers
3






active

oldest

votes


















1














There is no single API call which gives usage per org. But there is API call ibmcloud billing org-usage $org which retrieves usage for a single ORG. You can write a small shell script to call the API in a loop over a list of org.



#!/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





share|improve this answer
























  • I am unable to call this script from a function.

    – NoviceMe
    Nov 21 '18 at 14:00











  • What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

    – Manoj Singh
    Nov 21 '18 at 17:36











  • I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

    – NoviceMe
    Dec 13 '18 at 15:43



















1














The answers by @VidyasagarMachupalli and @data_henrik are appropriate. While there is no single API call, the ibmcloud billing resource-instances-usage provides the closest solution as it segments data based on org, space, and resource group.



You can use a spreadsheet (i.e. pivot table) to take the last step and sum the data for an entire org or resource group. The tutorial mentioned - this section - does exactly this approach using the IBM Cloud CLI, jq, and 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 │





share|improve this answer


























  • I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

    – NoviceMe
    Nov 20 '18 at 18:29











  • The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

    – Van Staub
    Nov 21 '18 at 13:32





















0














IBM Cloud offers APIs for usage metering and usage reports. The integrated API overview page in the IBM Cloud docs lists them under Platform Services.



I also recommend this IBM Cloud solution tutorial on reviewing cloud usage for an introduction. I just checked and it does not yet have the new APIs, but it's worth reading nonetheless.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394677%2fis-there-a-way-to-get-consolidated-ibm-cloud-billing-in-one-api-call%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    There is no single API call which gives usage per org. But there is API call ibmcloud billing org-usage $org which retrieves usage for a single ORG. You can write a small shell script to call the API in a loop over a list of org.



    #!/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





    share|improve this answer
























    • I am unable to call this script from a function.

      – NoviceMe
      Nov 21 '18 at 14:00











    • What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

      – Manoj Singh
      Nov 21 '18 at 17:36











    • I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

      – NoviceMe
      Dec 13 '18 at 15:43
















    1














    There is no single API call which gives usage per org. But there is API call ibmcloud billing org-usage $org which retrieves usage for a single ORG. You can write a small shell script to call the API in a loop over a list of org.



    #!/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





    share|improve this answer
























    • I am unable to call this script from a function.

      – NoviceMe
      Nov 21 '18 at 14:00











    • What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

      – Manoj Singh
      Nov 21 '18 at 17:36











    • I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

      – NoviceMe
      Dec 13 '18 at 15:43














    1












    1








    1







    There is no single API call which gives usage per org. But there is API call ibmcloud billing org-usage $org which retrieves usage for a single ORG. You can write a small shell script to call the API in a loop over a list of org.



    #!/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





    share|improve this answer













    There is no single API call which gives usage per org. But there is API call ibmcloud billing org-usage $org which retrieves usage for a single ORG. You can write a small shell script to call the API in a loop over a list of org.



    #!/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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 20 '18 at 16:42









    Manoj SinghManoj Singh

    1,032316




    1,032316













    • I am unable to call this script from a function.

      – NoviceMe
      Nov 21 '18 at 14:00











    • What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

      – Manoj Singh
      Nov 21 '18 at 17:36











    • I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

      – NoviceMe
      Dec 13 '18 at 15:43



















    • I am unable to call this script from a function.

      – NoviceMe
      Nov 21 '18 at 14:00











    • What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

      – Manoj Singh
      Nov 21 '18 at 17:36











    • I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

      – NoviceMe
      Dec 13 '18 at 15:43

















    I am unable to call this script from a function.

    – NoviceMe
    Nov 21 '18 at 14:00





    I am unable to call this script from a function.

    – NoviceMe
    Nov 21 '18 at 14:00













    What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

    – Manoj Singh
    Nov 21 '18 at 17:36





    What programming language are you using to create your function? The above script is a bash script. You can refactor that into a function if you need to.

    – Manoj Singh
    Nov 21 '18 at 17:36













    I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

    – NoviceMe
    Dec 13 '18 at 15:43





    I am using python, but where will billing.txt be saved? When you run it as a function on bluemix?

    – NoviceMe
    Dec 13 '18 at 15:43













    1














    The answers by @VidyasagarMachupalli and @data_henrik are appropriate. While there is no single API call, the ibmcloud billing resource-instances-usage provides the closest solution as it segments data based on org, space, and resource group.



    You can use a spreadsheet (i.e. pivot table) to take the last step and sum the data for an entire org or resource group. The tutorial mentioned - this section - does exactly this approach using the IBM Cloud CLI, jq, and 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 │





    share|improve this answer


























    • I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

      – NoviceMe
      Nov 20 '18 at 18:29











    • The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

      – Van Staub
      Nov 21 '18 at 13:32


















    1














    The answers by @VidyasagarMachupalli and @data_henrik are appropriate. While there is no single API call, the ibmcloud billing resource-instances-usage provides the closest solution as it segments data based on org, space, and resource group.



    You can use a spreadsheet (i.e. pivot table) to take the last step and sum the data for an entire org or resource group. The tutorial mentioned - this section - does exactly this approach using the IBM Cloud CLI, jq, and 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 │





    share|improve this answer


























    • I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

      – NoviceMe
      Nov 20 '18 at 18:29











    • The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

      – Van Staub
      Nov 21 '18 at 13:32
















    1












    1








    1







    The answers by @VidyasagarMachupalli and @data_henrik are appropriate. While there is no single API call, the ibmcloud billing resource-instances-usage provides the closest solution as it segments data based on org, space, and resource group.



    You can use a spreadsheet (i.e. pivot table) to take the last step and sum the data for an entire org or resource group. The tutorial mentioned - this section - does exactly this approach using the IBM Cloud CLI, jq, and 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 │





    share|improve this answer















    The answers by @VidyasagarMachupalli and @data_henrik are appropriate. While there is no single API call, the ibmcloud billing resource-instances-usage provides the closest solution as it segments data based on org, space, and resource group.



    You can use a spreadsheet (i.e. pivot table) to take the last step and sum the data for an entire org or resource group. The tutorial mentioned - this section - does exactly this approach using the IBM Cloud CLI, jq, and 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 │






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 20 '18 at 17:34

























    answered Nov 20 '18 at 17:09









    Van StaubVan Staub

    713




    713













    • I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

      – NoviceMe
      Nov 20 '18 at 18:29











    • The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

      – Van Staub
      Nov 21 '18 at 13:32





















    • I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

      – NoviceMe
      Nov 20 '18 at 18:29











    • The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

      – Van Staub
      Nov 21 '18 at 13:32



















    I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

    – NoviceMe
    Nov 20 '18 at 18:29





    I tried this but this is not the solution I can use inside a function or lambda to run. Is there a better way of doing this?

    – NoviceMe
    Nov 20 '18 at 18:29













    The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

    – Van Staub
    Nov 21 '18 at 13:32







    The CLI communicates with an API; you'd mimic the same approach in a Function. Set the IBMCLOUD_TRACE=true env var and run the command, you'll then see the RESTful call that the CLI is doing. The Cloud Usage sample application referenced from the tutorial uses Cloud Functions to retrieve billing data.

    – Van Staub
    Nov 21 '18 at 13:32













    0














    IBM Cloud offers APIs for usage metering and usage reports. The integrated API overview page in the IBM Cloud docs lists them under Platform Services.



    I also recommend this IBM Cloud solution tutorial on reviewing cloud usage for an introduction. I just checked and it does not yet have the new APIs, but it's worth reading nonetheless.






    share|improve this answer




























      0














      IBM Cloud offers APIs for usage metering and usage reports. The integrated API overview page in the IBM Cloud docs lists them under Platform Services.



      I also recommend this IBM Cloud solution tutorial on reviewing cloud usage for an introduction. I just checked and it does not yet have the new APIs, but it's worth reading nonetheless.






      share|improve this answer


























        0












        0








        0







        IBM Cloud offers APIs for usage metering and usage reports. The integrated API overview page in the IBM Cloud docs lists them under Platform Services.



        I also recommend this IBM Cloud solution tutorial on reviewing cloud usage for an introduction. I just checked and it does not yet have the new APIs, but it's worth reading nonetheless.






        share|improve this answer













        IBM Cloud offers APIs for usage metering and usage reports. The integrated API overview page in the IBM Cloud docs lists them under Platform Services.



        I also recommend this IBM Cloud solution tutorial on reviewing cloud usage for an introduction. I just checked and it does not yet have the new APIs, but it's worth reading nonetheless.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 16:16









        data_henrikdata_henrik

        9,29121031




        9,29121031






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394677%2fis-there-a-way-to-get-consolidated-ibm-cloud-billing-in-one-api-call%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?