Gil*_*rim 17 google-cloud-platform google-cloud-pubsub
我查看了Google PubSub的文档,并尝试查看Google Cloud Monitoring,但找不到任何方法来确定我的主题中的队列大小.
由于我计划使用PubSub进行分析,因此监控队列数非常重要,因此我可以扩大/减少用户数.
我错过了什么?
Kam*_*osn 20
您要查看的指标是"未送达的邮件".您应该能够在"发布/订阅"资源类型下设置在Google云监控中监控此指标的警报或图表.订阅者尚未确认的消息数(即队列大小)是每订阅度量标准,而不是每主题度量标准.有关度量的信息,请参阅pubsub.googleapis.com/subscription/num_undelivered_messages在GCP指标清单(以及其他所有可用的发布/订阅指标).
Ste*_*eve 11
如果您正在寻找一种编程方式来实现这一点,这可能会有所帮助:
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])
Run Code Online (Sandbox Code Playgroud)
您的问题的答案是"否",PubSub没有显示这些计数的功能.你必须这样做是通过使用Stackdriver的日志事件监控(我花了一些时间来找到它).
对此的口语答案是逐步完成以下操作:
MonitoringDashboards>Create DashboardAdd Chart仪表板屏幕右上角的按钮num_undelivered_messages然后SAVE根据@steeve 的回答更新版本。(无pandas依赖性)
请注意,您必须指定end_time而不是使用默认值utcnow()。
import datetime
from google.cloud import monitoring_v3
from google.cloud.monitoring_v3 import query
project = 'my-project'
sub_name = 'my-sub'
client = monitoring_v3.MetricServiceClient()
result = query.Query(
client,
project,
'pubsub.googleapis.com/subscription/num_undelivered_messages',
end_time=datetime.datetime.now(),
minutes=1,
).select_resources(subscription_id=sub_name)
for content in result:
print(content.points[0].value.int64_value)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10825 次 |
| 最近记录: |