File tree 3 files changed +15
-7
lines changed
3 files changed +15
-7
lines changed Original file line number Diff line number Diff line change 16
16
programmatically scale a Google Cloud Bigtable cluster."""
17
17
18
18
import argparse
19
+ import os
19
20
import time
20
21
21
22
from 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' ]
23
27
24
28
25
29
def get_cpu_load ():
@@ -29,11 +33,15 @@ def get_cpu_load():
29
33
float: The most recent Cloud Bigtable CPU usage metric
30
34
"""
31
35
# [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 )
35
43
recent_time_series = time_series [0 ]
36
- return recent_time_series .points [0 ].value
44
+ return recent_time_series .points [0 ].value . double_value
37
45
# [END bigtable_cpu]
38
46
39
47
Original file line number Diff line number Diff line change 32
32
33
33
34
34
def test_get_cpu_load ():
35
- assert get_cpu_load () > 0.0
35
+ assert float ( get_cpu_load () ) > 0.0
36
36
37
37
38
38
def test_scale_bigtable ():
Original file line number Diff line number Diff line change 1
1
google-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