在 gcp 中列出指标描述符时如何指定主题名称
how to specify topic name when to list metric descriptor in gcp
我正在使用监控“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 Topic Name,我使用了以下内容并且有效。
"filter": 'metric.type = "pubsub.googleapis.com/topic/send_message_operation_count" AND resource.type = "pubsub_topic" AND resource.labels.topic_id = "<topic name>"'
Filter: `metric.type="pubsub.googleapis.com/topic/send_message_operation_count" AND resource.type = "pubsub_topic" AND resource.labels.topic_id = "<topic_name>"`
这里有一些文档链接,可以帮助 Metric details related to pub sub, listing its descriptors or you may also try out with API Explorer to check with the required filter for 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/<project name>"
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 = "<topicname>"',
"interval": interval,
"view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL,
}
)
for result in results:
print(result)
我正在使用监控“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 Topic Name,我使用了以下内容并且有效。
"filter": 'metric.type = "pubsub.googleapis.com/topic/send_message_operation_count" AND resource.type = "pubsub_topic" AND resource.labels.topic_id = "<topic name>"'
Filter: `metric.type="pubsub.googleapis.com/topic/send_message_operation_count" AND resource.type = "pubsub_topic" AND resource.labels.topic_id = "<topic_name>"`
这里有一些文档链接,可以帮助 Metric details related to pub sub, listing its descriptors or you may also try out with API Explorer to check with the required filter for 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/<project name>"
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 = "<topicname>"',
"interval": interval,
"view": monitoring_v3.ListTimeSeriesRequest.TimeSeriesView.FULL,
}
)
for result in results:
print(result)