This page describes how to use Service Infrastructure to enable managed services to generate monitoring data to send to service producer and service consumer projects. Monitoring provides visibility into the performance, uptime, and overall health of individual managed services.
The Service Control API accepts metrics, which it batches and aggregates and forwards to Stackdriver Monitoring. Monitoring ingests these metrics and generates insights via dashboards, charts, and alerts.
Whereas Monitoring alone allows a managed service to generate monitoring data for use by you as a developer of the managed service, the Service Control API also lets you generate monitoring data which is intended for your users. This makes it possible for your users to understand and diagnose use of your managed service.
Configuring monitoring
Before you send monitoring data to the Service Control API, you need to specify three different bits of information in your service configuration:
Monitored resources: A Monitored resource represents a cloud entity that originates some monitoring data or is the subject of it. Stackdriver Monitoring provides a well-known set of monitored resource types that you can chose from.
Metrics: You can report one or more metrics. Each metric represents a single piece of state whose value is tracked over time. Stackdriver Monitoring provides a well-known set of metrics you can chose from.
Monitoring configuration: Lets you specify the metrics associated with individual monitored resources and the service producer or service consumer project where each log should be sent.
The following example of service configuration state defines a monitored
resource and a metric. A client can invoke the services.report
method to
report values on the metric. See
monitoring.proto
for details on service configuration.
# The monitored resource to be used.
monitored_resources:
- type: api
labels:
- key: cloud.googleapis.com/location
- key: serviceruntime.googleapis.com/api_version
- key: serviceruntime.googleapis.com/api_method
- key: cloud.googleapis.com/project
- key: cloud.googleapis.com/service
- key: cloud.googleapis.com/uid
# The metrics to be used.
metrics:
- name: serviceruntime.googleapis.com/api/consumer/request_count
metric_kind: DELTA
value_type: INT64
# The monitoring configuration.
monitoring:
producer_destinations:
- monitored_resource: api
metrics:
- serviceruntime.googleapis.com/api/consumer/request_count
consumer_destinations:
- monitored_resource: api
metrics:
- serviceruntime.googleapis.com/api/consumer/request_count
Reporting metrics
Once you have configured monitoring in the
service configuration
and pushed the configuration to 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.
gcurl -d "{ 'operations': [ { 'operationId': '8356d3c5-f9b5-4274-b4f9-079a3731e6e5', 'operationName': 'google.example.hello.v1.HelloService.GetHello', 'consumerId': 'project:endpointsapis-consumer', 'startTime': '`date +%FT%T%:z`', 'endTime': '`date +%FT%T%:z`', 'labels': { 'cloud.googleapis.com/location': 'global', 'serviceruntime.googleapis.com/api_version': 'v1', 'serviceruntime.googleapis.com/api_method': 'google.example.hello.v1.HelloService.GetHello', 'cloud.googleapis.com/project': 'proven-catcher-789', 'cloud.googleapis.com/service': 'endpointsapis.appspot.com', 'cloud.googleapis.com/uid': '92830528305210394' }, 'metricValueSets': [ { 'metricName': 'serviceruntime.googleapis.com/api/consumer/request_count', 'metricValues': [ { 'int64Value': '23' } ] } ] } ] }" https://servicecontrol.googleapis.com/v1/services/endpointsapis.appspot.com:report