Accessing the subscription/num_oustanding_messages metric in Google PubSub from Python

1.6k views Asked by At

Is it possible to access the subscription/num_outstanding_messages metric listed https://cloud.google.com/monitoring/api/metrics#gcp-pubsub from google-cloud-python? I've used similar code to successfully access the num_undelivered_messages metric, but iterating over the results of the following query (which succeeds) always yields an empty list.

Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.cloud import monitoring
>>> client = monitoring.Client()
>>> q = client.query(
...     "pubsub.googleapis.com/subscription/num_undelivered_messages",
...     minutes=90
... )
>>> len(list(q)) > 0
True
>>> q = client.query(
...     "pubsub.googleapis.com/subscription/num_outstanding_messages",
...     minutes=90
... )
>>> len(list(q)) > 0
False

Relevant google-cloud-python library versions:

~:pip freeze | grep google
gapic-google-logging-v2==0.10.1
gapic-google-pubsub-v1==0.10.1
google-cloud==0.21.0
google-cloud-bigquery==0.21.0
google-cloud-bigtable==0.21.0
google-cloud-core==0.21.0
google-cloud-datastore==0.21.0
google-cloud-dns==0.21.0
google-cloud-error-reporting==0.21.0
google-cloud-happybase==0.20.0
google-cloud-language==0.21.0
google-cloud-logging==0.21.0
google-cloud-monitoring==0.21.0
google-cloud-pubsub==0.21.0
google-cloud-resource-manager==0.21.0
google-cloud-runtimeconfig==0.21.0
google-cloud-storage==0.21.0
google-cloud-translate==0.21.0
google-cloud-vision==0.21.0
google-gax==0.14.1
googleapis-common-protos==1.5.0
grpc-google-iam-v1==0.10.1
grpc-google-logging-v2==0.10.1
grpc-google-pubsub-v1==0.10.1
1

There are 1 answers

0
Kamal Aboul-Hosn On BEST ANSWER

The num_outstanding_messages, which represents the number of messages sent to a subscriber that have not yet been acknowledged, is only available for push subscribers. Note that although the API does not make this distinction explicit, in Stackdriver, the metric shows up as "push outstanding messages." The Subscriber Guide talks about the difference between a push subscriber and a pull subscriber.