Created
February 17, 2020 16:33
-
-
Save bgweber/8e6c2823ed3e7f7c66045480d26de3ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# connect to the monitoring service | |
from google.cloud import monitoring_v3 | |
from google.oauth2 import service_account | |
import time | |
credentials = service_account.Credentials.from_service_account_file('serving.json') | |
client = monitoring_v3.MetricServiceClient(credentials = credentials) | |
project_name = client.project_path('serving-268422') | |
# create a custom metric | |
descriptor = monitoring_v3.types.MetricDescriptor() | |
descriptor.type = 'custom.googleapis.com/serving/requests' | |
descriptor.metric_kind = (monitoring_v3.enums.MetricDescriptor.MetricKind.GAUGE) | |
descriptor.value_type = (monitoring_v3.enums.MetricDescriptor.ValueType.DOUBLE) | |
descriptor.description = 'Model serving requests.' | |
# record a data point to the custom metric | |
series = monitoring_v3.types.TimeSeries() | |
series.metric.type = 'custom.googleapis.com/serving/requests' | |
series.metric.labels['ip'] = "1.2.3.4" | |
point = series.points.add() | |
point.value.double_value = 50 | |
now = time.time() | |
point.interval.end_time.seconds = int(now) | |
client.create_time_series(project_name, [series]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment