[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Reporting Monitoring Metrics\n\nThis page describes how to use Service Infrastructure to enable\n[managed services](/service-infrastructure/docs/glossary#managed) to generate monitoring\ndata to send to [service producer](/service-infrastructure/docs/glossary#producer)\nand [service consumer](/service-infrastructure/docs/glossary#consumer) projects. Monitoring provides\nvisibility into the performance, uptime, and overall health of individual\nmanaged services.\n\nThe Service Control API accepts metrics, which it batches\nand forwards to [Cloud Monitoring](/monitoring).\nMonitoring ingests these metrics and generates insights via\ndashboards, charts, and alerts.\n\nWhereas Monitoring alone allows a managed service to generate\nmonitoring data for use by you as a developer of the managed service,\nthe Service Control API also lets you generate monitoring data which is\nintended for your users. This makes it possible for your users to understand and\ndiagnose use of your managed service.\n\nNote, this guide is for\nmonitoring metrics defined by [managed services](/service-infrastructure/docs/glossary#managed).\nMonitoring Custom Metrics cannot be reported via\nService Control API. To report Custom Metrics, you need to follow\nthe Monitoring [guide](/monitoring/custom-metrics).\n\nConfiguring monitoring\n----------------------\n\nBefore you send monitoring 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** : A\n [monitored resource](/monitoring/api/v3/metrics#intro-resources)\n represents a cloud entity that produces some monitoring data. To define a\n monitored resource in the service configuration, see\n [monitored_resource.proto](https://github.com/googleapis/googleapis/blob/master/google/api/monitored_resource.proto)\n for the technical specification.\n We strongly recommend you to use the same monitored resource for both\n monitoring and [logging](/service-infrastructure/docs/report-logs).\n\n- **Metrics** : You can report one or more metrics. Each metric represents\n a single piece of state whose value is tracked over time. See\n [metric.proto](https://github.com/googleapis/googleapis/blob/master/google/api/metric.proto)\n for the technical specification to define a metric.\n\n- **Monitoring configuration** : Lets you specify the metrics associated with\n individual monitored resources and the service producer or service consumer\n project where each metric should be sent. See\n [monitoring.proto](https://github.com/googleapis/googleapis/blob/master/google/api/monitoring.proto)\n for details.\n\nThe following example of service configuration defines a monitored\nresource and a metric. \n\n # The definition of the monitored resource to be used.\n monitored_resources:\n - type: library.appspot.com/Branch\n description: A library branch.\n display_name: Library Branch\n launch_stage: ALPHA\n labels:\n - key: resource_container\n description: The Google Cloud resource container (ie. project id) for\n the branch.\n - key: location\n description: The Google Cloud region the branch is located.\n - key: branch_id\n description: The ID of the branch.\n\n # The definition of the metrics to be used.\n metrics:\n - name: library.appspot.com/book/num_overdue\n display_name: Books Overdue\n description: The current number of overdue books.\n launch_stage: ALPHA\n metric_kind: GAUGE\n value_type: INT64\n unit: 1\n - name: library.googleapis.com/book/returned_count\n display_name: Books Returned\n description: The count of books that have been returned.\n launch_stage: ALPHA\n metric_kind: DELTA\n value_type: INT64\n unit: 1\n\n # The monitoring configuration.\n monitoring:\n producer_destinations:\n - monitored_resource: library.appspot.com/Branch\n metrics:\n - library.googleapis.com/book/returned_count\n consumer_destinations:\n - monitored_resource: library.appspot.com/Branch\n metrics:\n - library.appspot.com/book/num_overdue\n\nAfter you have authored such configuration, you will need to follow\n[Managing Service Configurations](/service-infrastructure/docs/manage-config)\nand\n[Managing Service Rollouts](/service-infrastructure/docs/rollout) to push\nthe service configuration to Service Management API, which will configure the\nmonitored resource and metric definitions in [Cloud Monitoring](/monitoring).\n\nReporting metrics\n-----------------\n\nAfter the service configuration push finishes, you can call the\nService Control API to report metrics. The following example uses the\n`gcurl` command to demonstrate the call. For information on how to set this up,\nsee\n[Getting Started with the Service Control API](/service-infrastructure/docs/service-control/getting-started). \n\n```\ngcurl -d \"{\n 'operations': [ {\n 'operationId': '8356d3c5-f9b5-4274-b4f9-079a3731e6e5',\n 'operationName': 'Return books',\n 'consumerId': 'projects/library-consumer',\n 'startTime': '`date +%FT%T%:z`',\n 'endTime': '`date +%FT%T%:z --date=\"5 seconds\"`',\n 'labels': {\n 'location': 'us-east1',\n 'branch_id': 'my-test-library-branch'\n },\n 'metricValueSets': [ {\n 'metricName': 'library.googleapis.com/book/returned_count',\n 'metricValues': [ { 'int64Value': '23' } ]\n } ]\n } ]\n}\" https://servicecontrol.googleapis.com/v1/services/endpointsapis.appspot.com:report\n```"]]