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

Development Tutorial

Hristo Iliev edited this page Jan 4, 2018 · 20 revisions

Quick start

Available videos:

  • A demo video showing how to update your metering plan in the dashboard.
  • A demo video showing how to create and update your metering service instance plan definition via the command line.

Example applications:

  • Java project on how to send usage data to Abacus and how to get report back.
  • Node.js example application that can re-send metering data

Step-by-step

1. Create and Bind Service Instance

Run the following commands:

# List all the services available to your organization and space
cf marketplace

# Create three sample empty plans
cf create-service metering standard <metering-service>

# Bind the metering service to your application
cf bind-service <myapp> <metering-service>

# Update app environment to access the metering service instance
cf restart <myapp>

2. Edit your metering plans

Using CF CLI

Execute cf update-service <myservice> -c <metering plan configuration> 1

Abacus Broker Dashboard

🚨 To use the service dashboard first bind an application to your Abacus service instance. 🚨

Get the dashboard URL:

cf service <metering-service>

Showing info of service <metering-service> in org <org> / space <space> as <user> ...

name:            <metering-service>
service:         metering
bound apps:      <myapp>
tags:
plan:            standard
description:     Resource consumption service based on cf-abacus
documentation:
dashboard:       <url>

Log on using the dashboard url above.

The dashboard shows the metering plan for the resource provider application that is bound to the service instance. The metering plan has a sample Measure and a sample Metric. It allows you to:

  • (Navigate to metering plan) maintain the Measures and Metrics of the metering plan
  • (Measures tab) add/edit/delete the Measures for the metering plan
  • (Metrics tab) add/edit/delete the Metrics for the metering plan
  • (Navigate to a metric) maintain the details of the metric and its relevant functions - meter, accumulate, aggregate, and summarize.

Note: The abacus wiki provides sample plans. If you decide to use them keep in mind that you don't need to convert the plan toString() as this is done implicitly by the dashboard for you.

3. Submit Your Usage

See Submitting Usage

4. Develop application/service to send usage data

Examples:

  • Java project on how to send usage data to Abacus and how to get report back.
  • Node.js example application that can re-send metering data

5. Get your Usage summary report

You can get your usage summary report by using a GET method and the same credentials, used for sending metering data. See Usage Reports.

Automation

Metering plan configuration can be provided inline command line, or in a file on your local file system. Only one metering plan is supported.

You can use the configuration in create-service and update-service commands. For example: cf create-service metering standard <myservice> -c <metering plan configuration> 1

Plan Configuration

The default plan schema can be embedded in plan config:

 {
   "plans": [
     {
       "plan": {
         "plan_id": "standard-object-storage",
         "measures": [
           {
             "name": "storage",
             "unit": "BYTE"
           }
         ],
         "metrics": [
           {
             "name": "storage",
             "unit": "GIGABYTE",
             "type": "discrete",
             "meter": "(m) => new BigNumber(m.storage).div(1073741824).toNumber()",
             "accumulate": "(a, qty, start, end, from, to, twCell) => end < from || end >= to ? null : Math.max(a, qty)"
           }
         ]
       },
       "resource_provider": {
         "service_name": "<name_of_your_service>",
         "service_plan_name": "<name_of_your_service_plan>"
       }
     }
   ]
 }