Monitor instances with Cloud Monitoring

This document describes how to use the Cloud Monitoring console to monitor your Spanner instances.

The Cloud Monitoring console provides several monitoring tools for Spanner:

If you prefer to monitor Spanner programmatically, use the Cloud Client Libraries for Cloud Monitoring to retrieve metrics.

Use the Cloud Monitoring curated dashboard

Cloud Monitoring provides you with a curated dashboard that summarizes key information about your Spanner instances, including:

  • Incidents: User-created monitoring alerts that are open, active, or resolved
  • Events: A list of Spanner audit logs (if enabled and available)
  • Instances: A high-level summary of your Spanner instances, including compute capacity, database count, and instance health
  • Aggregated charts of throughput and storage use

To view the Spanner dashboard, do the following:

  1. In the Cloud de Confiance console, select Monitoring, or use the following button:

    Go to Monitoring

  2. If Resources is shown in the navigation pane, then select Resources and then select Cloud Spanner. Otherwise, select Dashboards and then select the dashboard named Cloud Spanner.

View instance and database details

When you open the curated dashboard for Spanner, it shows aggregated data for all of your instances. You can view more details about a specific instance by clicking the instance's name under Instances.

The dashboard displays information such as instance metadata, databases in the instance, and charts of various metrics broken down by region.

From the instance dashboard page, you can also see charts for a specific database in the instance:

  1. On the right-hand side, above the instance metrics charts, click Database metrics.

  2. In the Select a breakdown drop-down list, select the database that you want to examine.

    The Cloud Monitoring console displays charts for the database.

Create custom charts for Spanner metrics

You can use Cloud Monitoring to create custom charts for Spanner metrics. You can use the Metrics Explorer to create temporary, ad-hoc charts, or you can create charts that appear on custom dashboards.

In particular, Cloud Monitoring lets you create a custom chart that shows whether two or more metrics are correlated with each other. For example, you can check for a correlation between CPU utilization and latency in a Spanner instance, which might indicate that your instance needs more compute capacity or that some of your queries are causing high CPU utilization.

To get started with this example, follow these steps:

  1. In the Cloud de Confiance console, select Monitoring, or use the following button:

    Go to Monitoring

  2. If Metrics Explorer is shown in the navigation pane, select it. Otherwise, select Resources and then select Metrics Explorer.

  3. Click the View options tab, then select the Log scale on Y-axis checkbox. This option helps you compare multiple metrics when one metric has much larger values than the others.

  4. In the drop-down list above the right pane, select Line.

  5. Click the Metrics tab. You can now add metrics to the chart.

To add latency metrics to the chart, follow these steps:

  1. In the Find resource type and metric box, enter the value spanner.googleapis.com/api/request_latencies, then click the row that appears below the box.
  2. In the Filter box, enter the value instance_id, then enter the instance ID you want to examine and click Apply.
  3. In the Aggregator drop-down list, click max.
  4. Optional: Change the latency percentile:

    1. Click Show advanced options.
    2. Click the Aligner drop-down list, then click the latency percentile that you want to view.

    In most cases, you should look at either the 50th percentile latency, to understand the typical amount of latency, or the 99th percentile latency, to understand the latency for the slowest 1% of requests.

To add CPU utilization metrics to the chart, follow these steps:

  1. Click Add metric.
  2. In the Find resource type and metric box, enter the value spanner.googleapis.com/instance/cpu/utilization, then click the row that appears below the box.
  3. In the Filter box, enter the value instance_id, then enter the instance ID you want to examine and click Apply.
  4. In the Aggregator drop-down list, click max.

You now have a chart that shows the CPU utilization and latency metrics for a Spanner instance. If both metrics are higher than expected at the same time, you can take additional steps to correct the issue.

For more information about creating custom charts, see the Cloud Monitoring documentation.

Create alerts for Spanner metrics

When you create a Spanner instance, you choose the compute capacity for the instance. As the instance's workload changes, Spanner does not automatically adjust compute capacity of the instance. As a result, you need to set up several alerts to ensure that the instance stays within the recommended maximums for CPU utilization and the recommended limit for storage.

The following examples show how to set up alerting policies for some Spanner metrics. For a full list of available metrics, see metrics list for Spanner.

High-priority CPU

To create an alerting policy that triggers when your high priority cpu utilization for Spanner is above a recommended threshold, use the following settings.

New condition
Field

Value
Resource and Metric In the Resources menu, select Spanner Instance.
In the Metric categories menu, select Instance.
In the Metrics menu, select CPU Utilization by priority.

(The metric.type is spanner.googleapis.com/instance/cpu/utilization_by_priority).
Filter instance_id = YOUR_INSTANCE_ID
priority = high
Across time series
Time series group by
location for multi-region instances;
leave it blank for regional instances.
Across time series
Time series aggregation
sum
Rolling window 10 m
Rolling window function mean
Configure alert trigger
Field

Value
Condition type Threshold
Alert trigger Any time series violates
Threshold position Above threshold
Threshold value 45% for multi-region instances;
65% for regional instances.
Retest window 10 minutes

24 hour rolling average CPU

To create an alerting policy that triggers when the 24 hour rolling average of your cpu utilization for Spanner is above a recommended threshold, use the following settings.

New condition
Field

Value
Resource and Metric In the Resources menu, select Spanner Instance.
In the Metric categories menu, select Instance.
In the Metrics menu, select Smoothed CPU utilization.

(The metric.type is spanner.googleapis.com/instance/cpu/smoothed_utilization).
Filter instance_id = YOUR_INSTANCE_ID
Across time series
Time series aggregation
sum
Rolling window 10 m
Rolling window function mean
Configure alert trigger
Field

Value
Condition type Threshold
Alert trigger Any time series violates
Threshold position Above threshold
Threshold 90%
Retest window 10 minutes

Storage

To create an alerting policy that triggers when your storage for your Spanner instance is above a recommended threshold, use the following settings.

New condition
Field

Value
Resource and Metric In the Resources menu, select Spanner Instance.
In the Metric categories menu, select Instance.
In the Metrics menu, select Storage used.

(The metric.type is spanner.googleapis.com/instance/storage/utilization).
Filter instance_id = YOUR_INSTANCE_ID
Across time series
Time series aggregation
sum
Rolling window 10 m
Rolling window function max
Configure alert trigger
Field

Value
Condition type Threshold
Condition triggers if Any time series violates
Threshold position Above threshold
Threshold value You don't need to set a specific threshold for the maximum storage per node. However, we recommended that you set up an alert for when you are approaching the maximum storage limit. To learn more, see Storage utilization metrics.
Retest window 10 minutes

Monitor metrics for geo-partitioned databases

If you use geo-partitioning, then you can monitor resources such as data placements and instance partitions.

View placement quotas, limits, and utilization metrics

You can view storage utilization and row placement utilization values on the Instance partitions page of the Cloud de Confiance console.

  1. In the Cloud de Confiance console, go to the Spanner Instances page.

    Go to Instances

  2. Select an instance.

  3. In the navigation menu, click Instance partitions. On the Instance partitions page, you can view the Storage utilization and Row placement utilization values.

View instance partition details

Spanner provides several metrics to help you monitor your instance partitions. After you've created an additional partition, you see an additional filter for Instance partitions on the System insights page in the Cloud de Confiance console. The default selection is to show metrics for all instance partitions. You can filter the metrics for a specific instance partition.

To see metrics for a specific instance partition:

  1. In the Cloud de Confiance console, go to the Spanner Instances page.

    Go to Instances

  2. Select an instance.

  3. In the navigation menu, click System insights.

  4. Select the partition.

  5. Optional: Specify metric types in the filter menu.

To view resource metrics for a specific partition, you can filter using the instance_config label in the Metrics Explorer. The following Spanner metrics support grouping by instance partition using this label:

  • instance/backup/used_bytes
  • instance/cpu/smoothed_utilization
  • instance/cpu/utilization
  • instance/cpu/utilization_by_operation_type
  • instance/cpu/utilization_by_priority
  • instance/leader_percentage_by_region
  • instance/node_count
  • instance/placement_row_limit
  • instance/placement_row_limit_per_processing_unit
  • instance/placement_rows
  • instance/processing_units
  • instance/storage/limit_bytes
  • instance/storage/limit_bytes_per_processing_unit
  • instance/storage/used_bytes
  • instance/storage/utilization

Monitor a partition with a custom query

To build a custom query to monitor your partition through Metrics Explorer:

  1. In the Cloud de Confiance console, go to the Metrics Explorer page.

    Go to Metrics Explorer

  2. Filter the metrics that you want to view:

    1. In the Metric field, choose a Spanner resource metric to query (for example, spanner.googleapis.com/instance/node_count).
    2. Specify any filters that you need using the Filter field.
    3. To group metrics by each partition in your instance, in the Aggregation field, select Sum for the instance_config value. Optionally, you can add other grouping labels.

Monitor latency for geo-partitioning

You can monitor latency for your geo-partitioned database by viewing metrics for partitions and read request latency. You can also view transaction statistics and lock statistics to investigate performance issues.

To learn about choosing the right index for latency optimization, see General guidelines for choosing an index type for optimal latency.

To identify the high-level components involved in a Spanner request and how each component can affect latency, see Latency points in a Spanner request.

You can also use Spanner trace collection with OpenTelemetry to help you understand and debug latency issues.

What's next