使用 GCP 并在 Metrics explorer 中有以下数据:
我需要使用 Java 客户端来获取特定订阅 ID 中的当前未交付消息数。
找到以下示例: https ://cloud.google.com/monitoring/custom-metrics/reading-metrics
ListTimeSeriesRequest.Builder requestBuilder =
ListTimeSeriesRequest.newBuilder()
.setName(name.toString())
.setFilter(
"metric.type=\"pubsub.googleapis.com/subscription/num_undelivered_messages\" AND metric.label.subscription_id = \"myexporter\"")
.setInterval(interval)
.setView(ListTimeSeriesRequest.TimeSeriesView.HEADERS);
这带来了错误:
Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: The metric referenced by the provided filter is unknown. Check the metric name and labels.
但不清楚:
- 如何通过 subscription_id 过滤数据
- 如何获取不是 TimeSeries 数据,而是当前值