首页 > 解决方案 > Google Cloud:自定义堆栈驱动程序指标

问题描述

我正在运行一个自定义 Python 应用程序。代码中的日志记录被写入 Stackdriverm,很好。但是对于特定的代码块,我正在考虑在 Stackdriver 中创建自定义指标。但这是我的问题。有一些官方文档:

他们都使用这样开头的代码:

from google.cloud import monitoring

client = monitoring.Client()
descriptor = client.metric_descriptor(
    'custom.googleapis.com/my_metric',
    metric_kind=monitoring.MetricKind.GAUGE,
    value_type=monitoring.ValueType.DOUBLE,
    description='This is a simple example of a custom metric.')

我的问题是,我无法重现此代码。我已经安装了以下库:

谷歌云监控

但是当我尝试代码时,它说包中Client没有google-cloud-monitoring。相反,有一个MetricServiceClient,但我找不到任何关于如何使用它的好文档。

源代码

PS:我的 IDE 是 PyCharm。

和想法?

标签: pythongoogle-cloud-platformmetricsgoogle-cloud-stackdriver

解决方案


现在,使用客户端库的 0.28.1 版本。我将很快更新官方文档,以便它们可以工作 0.29。

https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/monitoring/api/v3/cloud-client/requirements.txt


推荐阅读