简体   繁体   English

Cloudwatch:基于 MessageAttribute 监控 SNS?

[英]Cloudwatch: Monitoring SNS based on MessageAttribute?

I have several backend services which publish to a single SNS topic.我有几个发布到单个 SNS 主题的后端服务。 The specific publishing service is designated as a field in MessageAttributes .特定的发布服务被指定为MessageAttributes中的一个字段。 Conversely, I have a single consumer subscribed to all messages from this topic.相反,我有一个消费者订阅了来自该主题的所有消息。

I'd like to monitor this SNS topic in Cloudwatch to determine if the number of messages being published per backend service is as expected.我想在 Cloudwatch 中监控这个 SNS 主题,以确定每个后端服务发布的消息数量是否符合预期。 Is there a way for me to partition this information in cloudwatch based on a value in message attributes?有没有办法让我根据消息属性中的值在 cloudwatch 中对这些信息进行分区?

Note: I am aware that Cloudwatch can monitor number of messages based on SNS Filter Policies .注意:我知道 Cloudwatch 可以根据SNS Filter Policies监控消息数量。 My concern is that I have a single consumer – would creating additional filter policies be expensive/wasteful?我担心我只有一个消费者——创建额外的过滤策略会很昂贵/浪费吗?

The filter policy metrics sadly do not support the granularity you are looking for at a policy level.遗憾的是,过滤策略指标不支持您在策略级别上寻找的粒度。 In order to keep the metrics within Cloudwatch you could use a Lambda that processes the messages on the topic and generates custom metrics into Cloudwatch based on the Attribute you are interested in making it possible to use in dashboards and alarms.为了将指标保留在 Cloudwatch 中,您可以使用 Lambda 来处理有关主题的消息,并根据您感兴趣的属性将自定义指标生成到 Cloudwatch 中,以便在仪表板和警报中使用。

At a high-level the flow would be SNS -> Lambda -> Cloudwatch.概括地说,流程是 SNS -> Lambda -> Cloudwatch。 Rather than using the CloudWatch API to push the metrics you could make use of the Cloudwatch embedded metric format.与其使用 CloudWatch API 来推送指标,不如使用 Cloudwatch 嵌入式指标格式。

Depending on your setup you could instead add metrics into the backend services that are making the PublishMessage calls.根据您的设置,您可以改为将指标添加到进行 PublishMessage 调用的后端服务中。 At least this way no new components would be needed to capture the metrics.至少这种方式不需要新的组件来捕获指标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM