# Monitoring

- [JSON representation](https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#SCHEMA_REPRESENTATION)
- [MonitoringDestination](https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination)
  - [JSON representation](https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination.SCHEMA_REPRESENTATION)

Monitoring configuration of the service.

The example below shows how to configure monitored resources and metrics for monitoring. In the example, a monitored resource and two metrics are defined. The `library.googleapis.com/book/returned_count` metric is sent to both producer and consumer projects, whereas the `library.googleapis.com/book/num_overdue` metric is only sent to the consumer project.

    monitoredResources:
    - type: library.googleapis.com/Branch
      displayName: "Library Branch"
      description: "A branch of a library."
      launchStage: GA
      labels:
      - key: resourceContainer
        description: "The Cloud container (ie. project id) for the Branch."
      - key: location
        description: "The location of the library branch."
      - key: branch_id
        description: "The id of the branch."
    metrics:
    - name: library.googleapis.com/book/returned_count
      displayName: "Books Returned"
      description: "The count of books that have been returned."
      launchStage: GA
      metricKind: DELTA
      valueType: INT64
      unit: "1"
      labels:
      - key: customer_id
        description: "The id of the customer."
    - name: library.googleapis.com/book/num_overdue
      displayName: "Books Overdue"
      description: "The current number of overdue books."
      launchStage: GA
      metricKind: GAUGE
      valueType: INT64
      unit: "1"
      labels:
      - key: customer_id
        description: "The id of the customer."
    monitoring:
      producerDestinations:
      - monitoredResource: library.googleapis.com/Branch
        metrics:
        - library.googleapis.com/book/returned_count
      consumerDestinations:
      - monitoredResource: library.googleapis.com/Branch
        metrics:
        - library.googleapis.com/book/returned_count
        - library.googleapis.com/book/num_overdue

| JSON representation |
|---|
| ``` { "producerDestinations": [ { object (`https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination`) } ], "consumerDestinations": [ { object (`https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination`) } ] } ``` |

| Fields ||
|---|---|
| `producerDestinations[]` | ``object (`https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination`)`` Monitoring configurations for sending metrics to the producer project. There can be multiple producer destinations. A monitored resource type may appear in multiple monitoring destinations if different aggregations are needed for different sets of metrics associated with that monitored resource type. A monitored resource and metric pair may only be used once in the Monitoring configuration. |
| `consumerDestinations[]` | ``object (`https://docs.cloud.google.com/service-usage/docs/reference/rest/Shared.Types/Monitoring#MonitoringDestination`)`` Monitoring configurations for sending metrics to the consumer project. There can be multiple consumer destinations. A monitored resource type may appear in multiple monitoring destinations if different aggregations are needed for different sets of metrics associated with that monitored resource type. A monitored resource and metric pair may only be used once in the Monitoring configuration. |

## MonitoringDestination

Configuration of a specific monitoring destination (the producer project or the consumer project).

| JSON representation |
|---|
| ``` { "monitoredResource": string, "metrics": [ string ] } ``` |

| Fields ||
|---|---|
| `monitoredResource` | `string` The monitored resource type. The type must be defined in `Service.monitored_resources` section. |
| `metrics[]` | `string` Types of the metrics to report to this monitoring destination. Each type must be defined in `Service.metrics` section. |