AttributeError:模块“google.cloud.monitoring_v3.types”没有属性“MetricDescriptor”

Ama*_*kar 3 monitoring gpu python-3.x google-compute-engine google-cloud-platform

我正在运行一个脚本来在 gcp 上创建 GPU 指标并收到以下错误:

AttributeError: 'MetricServiceClient' object has no attribute 'project_path'

AttributeError: module 'google.cloud.monitoring_v3.types' has no attribute 'MetricDescriptor'
Run Code Online (Sandbox Code Playgroud)

jus*_*ind 6

项目路径

google-cloud-monitoring库的 2.0 版本包含一项重大更改,该更改未记录在更改日志中,但在升级指南中进行了介绍。该project_path函数已重命名为common_project_path.

Versions < 2.0.0

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()
project_path = client.project_path("project_id")
Run Code Online (Sandbox Code Playgroud)

Versions >= 2.0.0

from google.cloud import monitoring_v3

client = monitoring_v3.MetricServiceClient()
project_path = client.common_project_path("project_id")
Run Code Online (Sandbox Code Playgroud)

度量描述符

MetricDescriptor 类型似乎2.0.0也在版本中发生了变化。升级指南中也介绍了它(带有不完整的片段)。

Versions < 2.0.0

from google.cloud import monitoring_v3

descriptor = monitoring_v3.types.MetricDescriptor()
Run Code Online (Sandbox Code Playgroud)

Versions >= 2.0.0

from google.api import metric_pb2 as ga_metric

descriptor = ga_metric.MetricDescriptor()
Run Code Online (Sandbox Code Playgroud)