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 688
2 REPLIES 2

Hi @arturmkr , I'm not an expert in Cloud Monitoring, but am wondering whether the aggregation query parameter might help you "derive" a point-in-time value by specifying a very narrow time range. Consider posting this Q in the Cloud Monitoring forum or the Cloud Pub/Sub forum

Hi @arturmkr I'm a member of the Cloud Operations PM team and just discovered your message here. I hope you were able to resolve this issue but if not I did want to provide a little more info.

I created a really simple pubsub topic, and then triggered two messages that are current unacked. I could generate a 'current value' by using the following Monitoring Query Lanauge:

fetch pubsub_subscription
| metric 'pubsub.googleapis.com/subscription/num_undelivered_messages'
| filter (resource.subscription_id == 'test-sub')
| group_by 1m,
    [value_num_undelivered_messages_max: max(value.num_undelivered_messages)]
| every 1m
| group_by [],
    [value_num_undelivered_messages_max_max:
       max(value_num_undelivered_messages_max)]

It's important to note that in metrics there is ALWAYS a time series -- in this case we're just consuming it based on 1 minute intervals and giving the max value. For more on the metrics model please see this link. You can visualize this in the graph dashboard as a gauge or scorecard to see a 'current value' but keep in mind that's based on the current value from the most recent polling period. 

It may be better for you to use another method to query for outstanding messages, and you may be able to check in the Pub/Sub community for best practices there.

Hope that helps!