Google PubSub - Counting messages in topic

前端 未结 3 1884
滥情空心
滥情空心 2020-12-06 00:33

I\'ve looked over the documentation for Google\'s PubSub, and also tried looking in Google Cloud Monitoring, but couldn\'t find any means of figuring out what\'s the queue s

相关标签:
3条回答
  • 2020-12-06 00:56

    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_name'][0])
    
    0 讨论(0)
  • 2020-12-06 01:07

    The metric you want to look at is "undelivered messages." You should be able to set up alerts or charts that monitor this metric in Google Cloud Monitoring under the "Pub/Sub Subscription" resource type. The number of messages that have not yet been acknowledged by subscribers, i.e., queue size, is a per-subscription metric as opposed to a per-topic metric. For info on the metric, see pubsub.googleapis.com/subscription/num_undelivered_messages in the GCP Metrics List (and others for all of the Pub/Sub metrics available).

    0 讨论(0)
  • 2020-12-06 01:17

    The answer to your question is "no", there is no feature for PubSub that shows these counts. The way you have to do it is via log event monitoring using Stackdriver (it took me some time to find that out too).

    The colloquial answer to this is do the following, step-by-step:

    1. Navigate from GCloud Admin Console to: Monitoring

    1. This opens a new window with separate Stackdriver console
    2. Navigate in Stackdriver: Dashboards > Create Dashboard

    1. Click the Add Chart button top-right of dashboard screen

    1. In the input box, type num_undelivered_messages and then SAVE

    0 讨论(0)
提交回复
热议问题