Google Cloud Monitoring Ruby客户端权限问题

时间:2019-12-30 05:12:45

标签: metrics google-cloud-stackdriver

我正在按照Ruby代码示例向堆栈驱动器添加自定义指标,但是,我一直收到权限拒绝错误。

client = Google::Cloud::Monitoring::Metric.new
project_name = Google::Cloud::Monitoring::V3::MetricServiceClient.project_path project_id

descriptor = Google::Api::MetricDescriptor.new(
  type:        "custom.googleapis.com/my_metric#{random_suffix}",
  metric_kind: Google::Api::MetricDescriptor::MetricKind::GAUGE,
  value_type:  Google::Api::MetricDescriptor::ValueType::DOUBLE,
  description: "This is a simple example of a custom metric."
)

result = client.create_metric_descriptor project_name, descriptor

我得到的错误是“ Google :: Gax :: PermissionDeniedError(GaxError RPC失败,原因是7:Permission monitoring.metricDescriptors.create被拒绝(或资源可能不存在。)

设置了环境变量GOOGLE_APPLICATION_CREDENTIALS,它对于下面的Google Cloud Storage代码正常工作

storage = Google::Cloud::Storage.new project: project_id

# Make an authenticated API request
storage.buckets.each do |bucket|
  puts bucket.name
end

在这一点上,我不知道出了什么问题。我需要为云监控设置其他凭据吗?

0 个答案:

没有答案
相关问题