Skip to content

Commit 7c6f4c7

Browse files
daniel-sanchedandhlee
authored andcommitted
chore(smaples): added imports into snippet (#216)
1 parent 1d083c1 commit 7c6f4c7

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

monitoring/snippets/v3/cloud-client/snippets.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@
1818
import time
1919
import uuid
2020

21-
from google.api import label_pb2 as ga_label
22-
from google.api import metric_pb2 as ga_metric
23-
from google.cloud import monitoring_v3
24-
25-
2621
PROJECT_ID = os.environ["GOOGLE_CLOUD_PROJECT"]
2722

2823

2924
def create_metric_descriptor(project_id):
3025
# [START monitoring_create_metric]
26+
from google.api import label_pb2 as ga_label
27+
from google.api import metric_pb2 as ga_metric
28+
from google.cloud import monitoring_v3
29+
3130
client = monitoring_v3.MetricServiceClient()
3231
project_name = f"projects/{project_id}"
3332
descriptor = ga_metric.MetricDescriptor()
@@ -51,6 +50,8 @@ def create_metric_descriptor(project_id):
5150

5251
def delete_metric_descriptor(descriptor_name):
5352
# [START monitoring_delete_metric]
53+
from google.cloud import monitoring_v3
54+
5455
client = monitoring_v3.MetricServiceClient()
5556
client.delete_metric_descriptor(name=descriptor_name)
5657
print("Deleted metric descriptor {}.".format(descriptor_name))
@@ -59,6 +60,8 @@ def delete_metric_descriptor(descriptor_name):
5960

6061
def write_time_series(project_id):
6162
# [START monitoring_write_timeseries]
63+
from google.cloud import monitoring_v3
64+
6265
client = monitoring_v3.MetricServiceClient()
6366
project_name = f"projects/{project_id}"
6467

@@ -82,6 +85,8 @@ def write_time_series(project_id):
8285

8386
def list_time_series(project_id):
8487
# [START monitoring_read_timeseries_simple]
88+
from google.cloud import monitoring_v3
89+
8590
client = monitoring_v3.MetricServiceClient()
8691
project_name = f"projects/{project_id}"
8792
interval = monitoring_v3.TimeInterval()
@@ -111,6 +116,8 @@ def list_time_series(project_id):
111116

112117
def list_time_series_header(project_id):
113118
# [START monitoring_read_timeseries_fields]
119+
from google.cloud import monitoring_v3
120+
114121
client = monitoring_v3.MetricServiceClient()
115122
project_name = f"projects/{project_id}"
116123
now = time.time()
@@ -137,6 +144,8 @@ def list_time_series_header(project_id):
137144

138145
def list_time_series_aggregate(project_id):
139146
# [START monitoring_read_timeseries_align]
147+
from google.cloud import monitoring_v3
148+
140149
client = monitoring_v3.MetricServiceClient()
141150
project_name = f"projects/{project_id}"
142151

@@ -172,6 +181,8 @@ def list_time_series_aggregate(project_id):
172181

173182
def list_time_series_reduce(project_id):
174183
# [START monitoring_read_timeseries_reduce]
184+
from google.cloud import monitoring_v3
185+
175186
client = monitoring_v3.MetricServiceClient()
176187
project_name = f"projects/{project_id}"
177188

@@ -209,6 +220,8 @@ def list_time_series_reduce(project_id):
209220

210221
def list_metric_descriptors(project_id):
211222
# [START monitoring_list_descriptors]
223+
from google.cloud import monitoring_v3
224+
212225
client = monitoring_v3.MetricServiceClient()
213226
project_name = f"projects/{project_id}"
214227
for descriptor in client.list_metric_descriptors(name=project_name):
@@ -218,6 +231,8 @@ def list_metric_descriptors(project_id):
218231

219232
def list_monitored_resources(project_id):
220233
# [START monitoring_list_resources]
234+
from google.cloud import monitoring_v3
235+
221236
client = monitoring_v3.MetricServiceClient()
222237
project_name = f"projects/{project_id}"
223238
resource_descriptors = client.list_monitored_resource_descriptors(name=project_name)
@@ -228,6 +243,8 @@ def list_monitored_resources(project_id):
228243

229244
def get_monitored_resource_descriptor(project_id, resource_type_name):
230245
# [START monitoring_get_resource]
246+
from google.cloud import monitoring_v3
247+
231248
client = monitoring_v3.MetricServiceClient()
232249
resource_path = (
233250
f"projects/{project_id}/monitoredResourceDescriptors/{resource_type_name}"
@@ -238,6 +255,8 @@ def get_monitored_resource_descriptor(project_id, resource_type_name):
238255

239256
def get_metric_descriptor(metric_name):
240257
# [START monitoring_get_descriptor]
258+
from google.cloud import monitoring_v3
259+
241260
client = monitoring_v3.MetricServiceClient()
242261
descriptor = client.get_metric_descriptor(name=metric_name)
243262
pprint.pprint(descriptor)

0 commit comments

Comments
 (0)