登录
首页 >  Golang >  Go问答

如何指定主题名称何时在 gcp 中列出指标描述符

来源:stackoverflow

时间:2024-02-28 13:39:20 241浏览 收藏

欢迎各位小伙伴来到golang学习网,相聚于此都是缘哈哈哈!今天我给大家带来《如何指定主题名称何时在 gcp 中列出指标描述符》,这篇文章主要讲到等等知识,如果你对Golang相关的知识非常感兴趣或者正在自学,都可以关注我,我会持续更新相关文章!当然,有什么建议也欢迎在评论留言提出!一起学习!

问题内容

我正在使用监控“cloud.google.com/go/monitoring/apiv3”和“google.golang.org/genproto/googleapis/monitoring/v3”,请求为

req := &monitoringpb.ListMetricDescriptorsRequest{
        Name:   fmt.Sprintf("projects/%s", t.projectId),
        Filter: "?",
}

正确答案


是的,我们可以指定过滤器。对于 pub sub 主题名称,我使用了以下内容并且它有效。

"filter": 'metric.type = "pubsub.googleapis.com/topic/send_message_operation_count" and resource.type = "pubsub_topic" and resource.labels.topic_id = ""'
filter: `metric.type="pubsub.googleapis.com/topic/send_message_operation_count" and resource.type = "pubsub_topic" and resource.labels.topic_id = ""`

这里有一些文档链接,可以为 Metric details related to pub sublisting its descriptors 提供帮助,或者您也可以尝试使用 API Explorer 来检查 undelivered messages 所需的过滤器

在python中尝试使用以下脚本,它给了我结果(项目名称和主题名称,根据您的要求更改的间隔):

import argparse
import os
import pprint
import time
import uuid

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 = "projects/"
interval = monitoring_v3.TimeInterval()

now = time.time()
seconds = int(now)
nanos = int((now - seconds) * 10 ** 9)
interval = monitoring_v3.TimeInterval(
    {
        "end_time": {"seconds": seconds, "nanos": nanos},
        "start_time": {"seconds": (seconds - 36000000), "nanos": nanos},
    }
)
results = client.list_time_series(
    request={
        "name": project_name,
        "filter": 'metric.type = "pubsub.googleapis.com/topic/send_message_operation_count" AND resource.type = "pubsub_topic" AND resource.labels.topic_id = ""',
        "interval": interval,
        "view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL,
    }
)
for result in results:
    print(result)

理论要掌握,实操不能落!以上关于《如何指定主题名称何时在 gcp 中列出指标描述符》的详细介绍,大家都掌握了吧!如果想要继续提升自己的能力,那么就来关注golang学习网公众号吧!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>