18
18
19
19
20
20
def create_metric_descriptor ():
21
- # [START create_metric_descriptor ]
21
+ # [START monitoring_create_metric ]
22
22
client = monitoring .Client ()
23
23
descriptor = client .metric_descriptor (
24
24
'custom.googleapis.com/my_metric' ,
25
25
metric_kind = monitoring .MetricKind .GAUGE ,
26
26
value_type = monitoring .ValueType .DOUBLE ,
27
27
description = 'This is a simple example of a custom metric.' )
28
28
descriptor .create ()
29
- # [END create_metric_descriptor ]
29
+ # [END monitoring_create_metric ]
30
30
31
31
32
32
def delete_metric_descriptor (descriptor_name ):
33
- # [START delete_metric_descriptor ]
33
+ # [START monitoring_delete_metric ]
34
34
client = monitoring .Client ()
35
35
36
36
descriptor = client .metric_descriptor (descriptor_name )
37
37
descriptor .delete ()
38
38
39
39
print ('Deleted metric descriptor {}.' .format (descriptor_name ))
40
- # [END delete_metric_descriptor ]
40
+ # [END monitoring_delete_metric ]
41
41
42
42
43
43
def write_time_series ():
44
- # [START write_time_series ]
44
+ # [START monitoring_write_timeseries ]
45
45
client = monitoring .Client ()
46
46
resource = client .resource (
47
47
'gce_instance' ,
@@ -57,80 +57,80 @@ def write_time_series():
57
57
}
58
58
)
59
59
client .write_point (metric , resource , 3.14 )
60
- # [END write_time_series ]
60
+ # [END monitoring_write_timeseries ]
61
61
62
62
63
63
def list_time_series ():
64
- # [START list_time_series ]
64
+ # [START monitoring_read_timeseries_simple ]
65
65
client = monitoring .Client ()
66
66
metric = 'compute.googleapis.com/instance/cpu/utilization'
67
67
query_results = client .query (metric , minutes = 5 )
68
68
for result in query_results :
69
69
print (result )
70
- # [END list_time_series ]
70
+ # [END monitoring_read_timeseries_simple ]
71
71
72
72
73
73
def list_time_series_header ():
74
- # [START list_time_series_header ]
74
+ # [START monitoring_read_timeseries_fields ]
75
75
client = monitoring .Client ()
76
76
metric = 'compute.googleapis.com/instance/cpu/utilization'
77
77
query_results = client .query (metric , minutes = 5 ).iter (headers_only = True )
78
78
for result in query_results :
79
79
print (result )
80
- # [END list_time_series_header ]
80
+ # [END monitoring_read_timeseries_fields ]
81
81
82
82
83
83
def list_time_series_aggregate ():
84
- # [START list_time_series_aggregate ]
84
+ # [START monitoring_read_timeseries_align ]
85
85
client = monitoring .Client ()
86
86
metric = 'compute.googleapis.com/instance/cpu/utilization'
87
87
query_results = client .query (metric , hours = 1 ).align (
88
88
monitoring .Aligner .ALIGN_MEAN , minutes = 5 )
89
89
for result in query_results :
90
90
print (result )
91
- # [END list_time_series_aggregate ]
91
+ # [END monitoring_read_timeseries_align ]
92
92
93
93
94
94
def list_time_series_reduce ():
95
- # [START list_time_series_reduce ]
95
+ # [START monitoring_read_timeseries_reduce ]
96
96
client = monitoring .Client ()
97
97
metric = 'compute.googleapis.com/instance/cpu/utilization'
98
98
query_results = client .query (metric , hours = 1 ).align (
99
99
monitoring .Aligner .ALIGN_MEAN , minutes = 5 ).reduce (
100
100
monitoring .Reducer .REDUCE_MEAN , 'resource.zone' )
101
101
for result in query_results :
102
102
print (result )
103
- # [END list_time_series_reduce ]
103
+ # [END monitoring_read_timeseries_reduce ]
104
104
105
105
106
106
def list_metric_descriptors ():
107
- # [START list_metric_descriptors ]
107
+ # [START monitoring_list_descriptors ]
108
108
client = monitoring .Client ()
109
109
for descriptor in client .list_metric_descriptors ():
110
110
print (descriptor .type )
111
- # [END list_metric_descriptors ]
111
+ # [END monitoring_list_descriptors ]
112
112
113
113
114
114
def list_monitored_resources ():
115
- # [START list_monitored_resources ]
115
+ # [START monitoring_list_resources ]
116
116
client = monitoring .Client ()
117
117
for descriptor in client .list_resource_descriptors ():
118
118
print (descriptor .type )
119
- # [END list_monitored_resources ]
119
+ # [END monitoring_list_resources ]
120
120
121
121
122
122
def get_monitored_resource_descriptor (resource_type_name ):
123
- # [START get_monitored_resources ]
123
+ # [START monitoring_get_resource ]
124
124
client = monitoring .Client ()
125
125
print (client .fetch_resource_descriptor (resource_type_name ))
126
- # [END get_monitored_resources ]
126
+ # [END monitoring_get_resource ]
127
127
128
128
129
129
def get_metric_descriptor (metric_type_name ):
130
- # [START get_metric_descriptor ]
130
+ # [START monitoring_get_descriptor ]
131
131
client = monitoring .Client ()
132
132
print (client .fetch_metric_descriptor (metric_type_name ))
133
- # [END get_metric_descriptor ]
133
+ # [END monitoring_get_descriptor ]
134
134
135
135
136
136
if __name__ == '__main__' :
0 commit comments