File tree Expand file tree Collapse file tree 3 files changed +15
-7
lines changed
Expand file tree Collapse file tree 3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 1616programmatically scale a Google Cloud Bigtable cluster."""
1717
1818import argparse
19+ import os
1920import time
2021
2122from google .cloud import bigtable
22- from google .cloud import monitoring
23+ from google .cloud import monitoring_v3
24+ from google .cloud .monitoring_v3 import query
25+
26+ PROJECT = os .environ ['GCLOUD_PROJECT' ]
2327
2428
2529def get_cpu_load ():
@@ -29,11 +33,15 @@ def get_cpu_load():
2933 float: The most recent Cloud Bigtable CPU usage metric
3034 """
3135 # [START bigtable_cpu]
32- client = monitoring .Client ()
33- query = client .query ('bigtable.googleapis.com/cluster/cpu_load' , minutes = 5 )
34- time_series = list (query )
36+ client = monitoring_v3 .MetricServiceClient ()
37+ cpu_query = query .Query (client ,
38+ project = PROJECT ,
39+ metric_type = 'bigtable.googleapis.com/'
40+ 'cluster/cpu_load' ,
41+ minutes = 5 )
42+ time_series = list (cpu_query )
3543 recent_time_series = time_series [0 ]
36- return recent_time_series .points [0 ].value
44+ return recent_time_series .points [0 ].value . double_value
3745 # [END bigtable_cpu]
3846
3947
Original file line number Diff line number Diff line change 3232
3333
3434def test_get_cpu_load ():
35- assert get_cpu_load () > 0.0
35+ assert float ( get_cpu_load () ) > 0.0
3636
3737
3838def test_scale_bigtable ():
Original file line number Diff line number Diff line change 11google-cloud-bigtable == 0.29.0
2- google-cloud-monitoring == 0.28 .1
2+ google-cloud-monitoring == 0.30 .1
You can’t perform that action at this time.
0 commit comments