Skip to content

Commit

Permalink
Merge pull request #117 from medb/patch-1
Browse files Browse the repository at this point in the history
Migrate to google-cloud-monitoring 2.0
  • Loading branch information
tswast authored Jan 25, 2021
2 parents c30fbcd + 2657aee commit ffd8893
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dlvm/gcp-gpu-utilization-metrics/create_gpu_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def add_new_metric(project_id, metric_type, desc):
descriptor.description = desc
# Create Metric Descriptor.
client = monitoring_v3.MetricServiceClient()
project_name = client.project_path(project_id)
project_name = client.common_project_path(project_id)
descriptor = client.create_metric_descriptor(project_name, descriptor)
print('Created {}.'.format(descriptor.name))

Expand Down
16 changes: 9 additions & 7 deletions dlvm/gcp-gpu-utilization-metrics/report_gpu_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,23 @@ def report_metric(value, metric_type, resource_values):
instance_id = resource_values.get('instance_id')
zone = resource_values.get('zone')

project_name = client.project_path(project_id)
project_name = client.common_project_path(project_id)
# TimeSeries definition.
series = monitoring_v3.types.TimeSeries()
series.metric.type = 'custom.googleapis.com/{type}'.format(type=metric_type)
series.resource.type = 'gce_instance'
series.resource.labels['instance_id'] = instance_id
series.resource.labels['zone'] = zone
series.resource.labels['project_id'] = project_id
point = series.points.add()
point.value.int64_value = value
now = time.time()
point.interval.end_time.seconds = int(now)
point.interval.end_time.nanos = int(
(now - point.interval.end_time.seconds) * 10 ** 9)
client.create_time_series(project_name, [series])
seconds = int(now)
nanos = int((now - seconds) * 10 ** 9)
interval = monitoring_v3.TimeInterval(
{"end_time": {"seconds": seconds, "nanos": nanos}}
)
point = monitoring_v3.Point({"interval": interval, "value": {"int64_value": value}})
series.points = [point]
client.create_time_series(name=project_name, time_series=[series])


def get_nvidia_smi_utilization(gpu_query_metric):
Expand Down
2 changes: 1 addition & 1 deletion dlvm/gcp-gpu-utilization-metrics/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-monitoring>=0.30.1
google-cloud-monitoring==2.0

0 comments on commit ffd8893

Please sign in to comment.