Stay organized with collections
Save and categorize content based on your preferences.
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 library.appspot.com/books/borrowed
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
cloud.googleapis.com/location 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
services.report method to report values on the metric. See
billing.proto
for details on billing configuration.
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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Reporting Billing Metrics\n\nThis page describes how to use Service Infrastructure to enable\n[managed services](/service-infrastructure/docs/glossary#managed) to send billing usage data so that\nCloud Billing can charge against [service consumers](/service-infrastructure/docs/glossary#consumer).\nFor example, you can define a metric called `library.appspot.com/books/borrowed`\nto measure the number of books borrowed by a customer and define a stock keeping\nunit (SKU) and price for it.\n\nThe Service Control API accepts metrics, which it batches, aggregates,\nand forwards to [Cloud Billing](/billing). Cloud Billing ingests these\nmetrics and generates bills based on the predefined price model. If there is no\npredefined price model, [Cloud Billing](/billing) simply disregards the\nbilling metrics. To define the price model, please contact your Google Cloud\npartner account manager.\n\nConfiguring billing\n-------------------\n\nBefore you send billing data to the Service Control API, you need to\nspecify three different bits of information in your\n[service configuration](/service-infrastructure/docs/service-management/reference/rpc/google.api#google.api.Service):\n\n- **Monitored resources** : You can collect billing usage for each\n resource. The monitored resources need at least one label key\n `cloud.googleapis.com/location` to indicate the location of the billing usage.\n\n- **Metrics**: You can report one or more metrics. Each metric measures the\n usage of a given type of resource. Only DELTA metrics with INT64 values are\n supported for billing.\n\n- **Billing configuration**: Lets you specify the metrics to be sent to\n Cloud Billing.\n\nThe following example service configuration defines one metric that measures the\nnumber of books borrowed by a customer. A client can invoke the\n`services.report` method to report values on the metric. See\n[billing.proto](https://github.com/googleapis/googleapis/blob/master/google/api/billing.proto)\nfor details on billing configuration. \n\n # library\n monitored_resources:\n - type: library.appspot.com/branch\n labels:\n - key: cloud.googleapis.com/location\n description: The cloud location.\n - key: library.appspot.com/city\n description: The city where the library branch is located in.\n\n # The metrics to be used.\n metrics:\n - name: library.appspot.com/books/borrowed\n metric_kind: DELTA\n value_type: INT64\n unit: '1'\n\n # The billing configuration.\n billing:\n consumer_destinations:\n - monitored_resource: library.appspot.com/branch\n metrics:\n - library.appspot.com/books/borrowed\n\nReporting billing metrics\n-------------------------\n\nOnce you have configured monitoring in the\n[service configuration](/service-infrastructure/docs/service-management/reference/rpc/google.api#google.api.Service)\nand pushed the service configuration using the Service Management API, you can\ncall the Service Control API to report metrics. The following example\nuses the `gcurl` command to demonstrate the call. For information on how to set\nthis up, see\n[Getting Started with the Service Control API](/service-infrastructure/docs/service-control/getting-started). \n\n $ gcurl -d \"{\n 'operations': [ {\n 'operationId': '8356d3c5-f9b5-4274-b4f9-079a3731e6e5',\n 'consumerId': 'project:library-consumer',\n 'startTime': '`date +%FT%T%:z`',\n 'endTime': '`date +%FT%T%:z`',\n 'labels': {\n 'cloud.googleapis.com/location': 'us-west1',\n 'library.appspot.com/city': 'Kirkland',\n },\n 'metricValueSets': [ {\n 'metricName': 'library.appspot.com/books/borrowed',\n 'metricValues': [ { 'int64Value': '10' } ]\n } ]\n } ]\n }\" https://servicecontrol.googleapis.com/v1/services/library.appspot.com:report"]]