Last active
January 20, 2024 14:09
-
-
Save winter-code/7d5b49a72fd944430ad6e6af7c0e0f44 to your computer and use it in GitHub Desktop.
creating a custom monitoring metric on gcp
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
from google.api import label_pb2 as ga_label | |
from google.api import metric_pb2 as ga_metric | |
from google.cloud import monitoring_v3 | |
client = monitoring_v3.MetricServiceClient() | |
project_name = f"projects/arpanas-project" | |
descriptor = ga_metric.MetricDescriptor() | |
descriptor.type = "custom.googleapis.com/my_metric" | |
descriptor.metric_kind = ga_metric.MetricDescriptor.MetricKind.GAUGE | |
descriptor.value_type = ga_metric.MetricDescriptor.ValueType.DOUBLE | |
descriptor.description = "This is a simple example of a custom metric." | |
labels = ga_label.LabelDescriptor() | |
labels.key = "TestLabel" | |
labels.value_type = ga_label.LabelDescriptor.ValueType.STRING | |
labels.description = "This is a test label for my medium blog" | |
descriptor.labels.append(labels) | |
descriptor = client.create_metric_descriptor( | |
name=project_name, metric_descriptor=descriptor | |
) | |
print("Created {}.".format(descriptor.name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment