CPU load measurement

Returns the most recent Cloud Bigtable CPU load measurement.

Code sample

Java

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

Timestamp now = timeXMinutesAgo(0);
Timestamp fiveMinutesAgo = timeXMinutesAgo(5);
TimeInterval interval =
    TimeInterval.newBuilder().setStartTime(fiveMinutesAgo).setEndTime(now).build();
String filter = "metric.type=\"" + CPU_METRIC + "\"";
ListTimeSeriesPagedResponse response =
    metricServiceClient.listTimeSeries(projectName, filter, interval, TimeSeriesView.FULL);
return response.getPage().getValues().iterator().next().getPointsList().get(0);

Python

To learn how to install and use the client library for Bigtable, see Bigtable client libraries.

To authenticate to Bigtable, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

client = monitoring_v3.MetricServiceClient()
cpu_query = query.Query(
    client,
    project=PROJECT,
    metric_type="bigtable.googleapis.com/" "cluster/cpu_load",
    minutes=5,
)
cpu_query = cpu_query.select_resources(
    instance=bigtable_instance, cluster=bigtable_cluster
)
cpu = next(cpu_query.iter())
return cpu.points[0].value.double_value

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.