Reporting Metrics

This page describes how to use Google Service Control to enable services to produce monitoring data to send to service producers and service consumers. Monitoring provides visibility into the performance, uptime, and overall health of individual services.

Service Control accepts metrics, which it batches and aggregates and forwards to Stackdriver Monitoring. Stackdriver Monitoring ingests these metrics and generates insights via dashboards, charts, and alerts.

Whereas Stackdriver Monitoring alone allows a service to produce monitoring data for the sake of the service's producer, Service Control makes it possible to also produce monitoring data which is intended for the service's consumers. This makes it possible for service consumers to understand and diagnose use of the service.

Configuring metrics

Before you send monitoring data to Service Control, you need to specify three different bits of information in your service configuration:

  • Metric names: 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.

  • 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.

  • Monitoring configuration: Lets you specify the metrics associated with individual monitored resources and the destination (producer or consumer) where the monitoring data should be sent.

In the following example of service configuration state, we defined a monitored resource and a metric. A client can invoke the services.report method to report values on the metric. See service.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 metrics in the service configuration and pushed the configuration to Google Service Management, you can call the Service Control API to report metrics. The following example uses the gcurl command to demonstrate the call; see Getting Started for how to set this up.

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

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.