Using GCP and having following data in Metrics explorer:
I need using Java client to get a current number of undelivered_messages in the specific subscription_id.
Found following example: 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);
Which brings error:
Caused by: io.grpc.StatusRuntimeException: NOT_FOUND: The metric referenced by the provided filter is unknown. Check the metric name and labels.
But it's not clear:
For your first question replace metric.label.subscription_id
by resource.label.\"subscription_id\"
in the setFilter
For your second question, you can play with the documentation example here : make sure to have a time interval of at least 60s (61 seconds worked for me). Any way get the last value sorted by end time