Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Generate Usage Reports

denicaM edited this page Jul 2, 2018 · 5 revisions

By using get methods a Report Consumer can obtain the following:

  • Usage Summary Report - this report provides a summary of aggregated cloud resource consumption, specific to an organization at a specific time period. On secured Abacus the scope of the OAuth token determines the response. If a system token is used, an aggregated report containing all consumed resources for the specified organization will be returned. When resource token is used than the report will contain only the resource that is part from the token scope.
  • Resource Instance Report - this report provides a summary of aggregated cloud resource usage incurred by a specific resource instance within an organization and specific plans at a particular time.
  • Aggregated Usage Report - this report provides a summary of cloud resource usage. This information can be queried by using GraphQL query language.

All reports are requested from the Reporting micro-service, with a URL in the following format https://abacus-usage-reporting.<cf domain>. Contact your Abacus Integrator for the exact URL.

GraphQL

GraphQL is a query language used by Abacus to allow users to navigate and query the graph of aggregated usage.

There are several examples in the Abacus API documentation on how to use GraphQL. GraphiQL IDE can help when designing new queries.

Examples

Abacus provides several examples on how to obtain usage report:

Usage report
npm start
npm run demo
curl -H 'Content-Type: application/json' http://localhost:9088/v1/metering/organizations/us-south:a3d7fe4d-3cb1-4cc3-a831-ffe98e20cf27/aggregated/usage
Cloud usage report

The Usage report script obtains summary usage report for an organization.

Run the report script with:

export CLIENT_ID=<uaa client id> 
export CLIENT_SECRET=<client secret>
export DOMAIN=<Cloud Foundry domain>
export RESOURCE_ID=<usage resource id> # not required if system client is used

cd ~/workspace/cf-abacus/demo/scripts
./abacus-get-report.sh <organization id>

The RESOURCE_ID should be the same that was used to submit usage except if using a system token.

The organization id can be obtained using the CF CLI:

cf org <org name> --guid

Another example (written in nodejs) can be found in the demo application.

Resource instance usage report
  1. Get org usage report

  2. Traverse the org report

  3. Gather parameters

    • space_id
    • resource_id
    • resource_instance_id
    • consumer_id
    • plan_id
    • metering_plan_id
    • rating_plan_id
    • pricing_plan_id
    • t - the time for which the usage was submitted (end field of the usage report). In org report this can be found under resource_instances:
                  "resource_instances": [
                    {
                      "id": "0b39fa70-a65f-4183-bae8-385633ca5c87",
                      "t": "0001509008400000",
                      "p": 1509010714980
                    }
                  ],
    • time - provides Abacus with the month for which we return the report. To be sure you'll get the data for the whole of September you might specify the end of the month for time:
      node -p "new Date('Oct 2017').valueOf() - 1"
      1506805199999
  4. Get instance usage report for each consumer

GraphQL

Using GraphQL to get usage from a non-secured Abacus.

Run the GraphQL example with:

cd ~/workspace/cf-abacus
npm restart
cd node_modules/abacus-demo-client && node src/test/graphql.js
Demo client

The Demo client simulates a Service Provider and a Usage Consumer. It submits usage and verifies the submission by retrieving a usage report. The client works with a secured Abacus.

To run the demo client:

cd ~/workspace/cf-abacus
npm restart
npm run demo

Possible Response Codes When Retrieving Reports:

Code Description
200 Report has been successfully obtained. The response body will have a JSON object containing details of the report as mentioned in the Abacus documentation
206 Report contains partial content. For example missing consumer or space data for particular time of report
403 Insufficient scope error encountered when the resource_id value is invalid
404 Usage is not found
429 Too many requests in parallel
500 Internal server error
<< Submit Usage Process Usage Reports >>
Clone this wiki locally