是否可以从google-cloud-python访问列出的subscription/num_outstanding_messages
指标https://cloud.google.com/monitoring/api/metrics#gcp-pubsub?我已经使用类似的代码来成功访问num_undelivered_messages
指标,但迭代以下查询的结果(成功)总会产生一个空列表。
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
相关的google-cloud-python库版本:
~: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
答案 0 :(得分:3)
num_outstanding_messages
表示发送给尚未确认的订阅者的消息数,仅适用于推送订阅者。请注意,尽管API没有明确区分这一区别,但在Stackdriver中,该指标显示为“推送未完成的消息”。 Subscriber Guide讨论了推送用户和拉用户之间的区别。