Reporting Billing Metrics

This page describes how to use Service Infrastructure to enable managed services to send billing usage data so that Cloud Billing can charge against service consumers. For example, you can define a metric called to measure the number of books borrowed by a customer and define a stock keeping unit (SKU) and price for it.

The Service Control API accepts metrics, which it batches, aggregates, and forwards to Cloud Billing. Cloud Billing ingests these metrics and generates bills based on the predefined price model. If there is no predefined price model, Cloud Billing simply disregards the billing metrics. To define the price model, please contact your Google Cloud partner account manager.

Configuring billing

Before you send billing data to the Service Control API, you need to specify three different bits of information in your service configuration:

  • Monitored resources: You can collect billing usage for each resource. The monitored resources need at least one label key to indicate the location of the billing usage.

  • Metrics: You can report one or more metrics. Each metric measures the usage of a given type of resource. Only DELTA metrics with INT64 values are supported for billing.

  • Billing configuration: Lets you specify the metrics to be sent to Cloud Billing.

The following example service configuration defines one metric that measures the number of books borrowed by a customer. A client can invoke the method to report values on the metric. See billing.proto for details on billing configuration.

# library
 - type:
   - key:
     description: The cloud location.
   - key:
     description: The city where the library branch is located in.

# The metrics to be used.
- name:
  metric_kind: DELTA
  value_type: INT64
  unit: '1'

# The billing configuration.
  - monitored_resource:

Reporting billing metrics

Once you have configured monitoring in the service configuration and pushed the service configuration using the Service Management API, you can call the Service Control API to report metrics. The following example uses the gcurl command to demonstrate the call. For information on how to set this up, see Getting Started with the Service Control API.

$ gcurl -d "{
  'operations': [ {
    'operationId': '8356d3c5-f9b5-4274-b4f9-079a3731e6e5',
    'consumerId': 'project:library-consumer',
    'startTime': '`date +%FT%T%:z`',
    'endTime': '`date +%FT%T%:z`',
    'labels': {
      '': 'us-west1',
      '': 'Kirkland',
    'metricValueSets': [ {
      'metricName': '',
      'metricValues': [ { 'int64Value': '10' } ]
    } ]
  } ]