Count number of unacknowledged messages in a Pubsub topic

Deadly 提交于 2019-12-06 15:21:32

A Cloud Pub/Sub Topic has no concept of an unacknowledged message. This is purely a property of an individual Subscription, how many messages have not yet been acknowledged.

You can use Stackdriver Alerting to alert you if the unacknowledged message age in any subscription gets too high. Set Resource Type to “Cloud Pub/Sub Subscription” and Metric to “Oldest Unacked Message”, and alert if any time series violates some threshold.

This might help if you're looking into a programmatic way to achieve this:

from google.cloud import monitoring_v3
from google.cloud.monitoring_v3 import query

project = "my-project"
client = monitoring_v3.MetricServiceClient()
result = query.Query(
         client,
         project,
         'pubsub.googleapis.com/subscription/num_undelivered_messages', 
         minutes=60).as_dataframe()

print(result['pubsub_subscription'][project]['subscription_name1'][0])
print(result['pubsub_subscription'][project]['subscription_name2'][0])

Try using the metric subscription/num_undelivered_messages instead. Unlike subscription/num_unacked_messages_by_\region, it is in GA and does not require a region to be specified.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!