本頁面說明如何透過服務基礎架構,讓代管服務傳送帳單使用資料,以便 Cloud Billing 向服務用戶收費。舉例來說,您可以定義名稱為 library.appspot.com/books/borrowed
的指標來計算顧客借書的次數,並定義該指標適用的 SKU (庫存單位) 和價格。
Service Control API 可接受多種指標,並且大量匯總這些指標,然後轉送至 Cloud Billing。Cloud Billing 會擷取這些指標,然後根據預先定義的計價模式產生帳單。如果沒有預先定義的價格模式,Cloud Billing 就會直接忽略帳單指標。如要定義價格模式,請與合作夥伴帳戶經理聯絡。 Google Cloud
設定計費功能
將帳單資料傳送至 Service Control API 之前,您必須先在服務設定中指定三種不同的資訊:
受控資源:您可以收集所有資源的結帳用量。受控資源需要至少一個標籤鍵
cloud.googleapis.com/location
,才能指明帳單用量的所在位置。指標:您可以回報一或多個指標,每個指標都會計算不同類型資源的使用量。帳單功能只支援提供 INT64 值的 DELTA 指標。
帳單設定:讓您指定要傳送至 Cloud Billing 的指標。
下列服務設定範例定義了一個用於計算客戶借書次數的指標。用戶端可以叫用 services.report
方法,回報指標的值。如要進一步瞭解帳單設定,請參閱 billing.proto。
# library
monitored_resources:
- type: library.appspot.com/branch
labels:
- key: cloud.googleapis.com/location
description: The cloud location.
- key: library.appspot.com/city
description: The city where the library branch is located in.
# The metrics to be used.
metrics:
- name: library.appspot.com/books/borrowed
metric_kind: DELTA
value_type: INT64
unit: '1'
# The billing configuration.
billing:
consumer_destinations:
- monitored_resource: library.appspot.com/branch
metrics:
- library.appspot.com/books/borrowed
回報帳單指標
在服務設定中設定監控功能並使用 Service Management API 推送服務設定後,就可以呼叫 Service Control API 來回報指標。下列範例使用 gcurl
指令來示範呼叫。如要瞭解相關設定方式,請參閱開始使用 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': {
'cloud.googleapis.com/location': 'us-west1',
'library.appspot.com/city': 'Kirkland',
},
'metricValueSets': [ {
'metricName': 'library.appspot.com/books/borrowed',
'metricValues': [ { 'int64Value': '10' } ]
} ]
} ]
}" https://servicecontrol.googleapis.com/v1/services/library.appspot.com:report