Reporting Billing Metrics

This page describes how to use Google Service Control to enable 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 SKU and price for it.

Service Control 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 pre-defined price model, Cloud Billing simply disregards the billing metrics. To define the price model, please contact your GCP partner account manager.

Configuring billing

Before you send billing data to Service Control, 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.

In the following example of service configuration, we defined one metric measuring 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 configuration to Google Service Management, you can call the Service Control API to report metrics. The following example uses the gcurl command to demonstrate the call. See Getting Started for how to set this up.

$ 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' } ]
    } ]
  } ]
Was this page helpful? Let us know how we did: