Service Control API 可接受多種指標,並且大量匯總這些指標,然後轉送至 Cloud Billing。Cloud Billing 會擷取這些指標,然後根據預先定義的計價模式產生帳單。如果沒有預先定義的價格模式,Cloud Billing 就會直接忽略帳單指標。如要定義價格模式,請與合作夥伴帳戶經理聯絡。 Google Cloud
設定計費功能
將帳單資料傳送至 Service Control API 之前,您必須先在服務設定中指定三種不同的資訊:
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],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"]]