Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Get specific Metric data by metric.type and subscription_id

Hello,

Having following in Metrics explorer:

Screenshot 2021-07-27 at 16.02.32.png

 

I need using Java client to get a current amount of undelivered_messages in the specific subscription_id. It's not clear how to do this.

Found following article:

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);

But it's not clear:

- how to filter data by subscription_id

- how to get not TimeSeries data, but current value

0 2 820