[英]Create CloudWatch alarm on multiple SQS queues
Suppose I have N EC2 instances in auto-scaling group, each of them is polling M SQS queues.假设我在自动扩展组中有N个 EC2 实例,每个实例都在轮询M个 SQS 队列。 How would I create an alarm on cumulative
ApproximateNumberOfMessagesVisible
across all SQS queues if possible?如果可能,我将如何在所有 SQS 队列中的累积
ApproximateNumberOfMessagesVisible
上创建警报?
There is no cumulative count of the visible messages metric available as of now. 到目前为止,没有可用的可见消息量度累积计数。
Here is how you can solve it, 这是解决问题的方法,
Create a Lambda/ cron job that can poll the queues, get ApproximateNumberOfMessages
on each queue and update the total messages to a custom Cloudwatch Metric. 创建一个Lambda / cron作业,该作业可以轮询队列,在每个队列上获取
ApproximateNumberOfMessages
,并将总消息更新为自定义Cloudwatch指标。
QueueAttributes: QueueAttributes:
http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueAttributes.html http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueAttributes.html
Custom Cloudwatch Metric: 自定义Cloudwatch指标:
http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html
You can either create a lambda (serverless) or if you want to server based, you can poll and update total count into a custom cloudwatch metric with cli to AWS cloudwatch. 您可以创建一个lambda(无服务器),或者如果您希望基于服务器,则可以使用cli将总计数轮询并更新到自定义cloudwatch指标中,并将其更新为AWS cloudwatch。
Once you have have the cloudwatch metric, you can create an alarm based on those numbers. 有了cloudwatch指标后,您可以基于这些数字创建警报。
Hope it helps. 希望能帮助到你。
You can define a Alarm with cloud formation.您可以定义带有云层的警报。 The key is define a custom
关键是定义一个自定义
Expression where each expression has a one or multiples metrics by queue.表达式,其中每个表达式按队列具有一个或多个指标。 The Dimesions allow associate metric with queue.
Dimesions 允许将度量与队列相关联。
MyDeadLetterQueueAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: my-dlq-alarm
AlarmDescription: 'Alarm when any Dead letter queue has items.'
Metrics:
- Id: summary
Label: Dead Letter Queues Alarm
Expression: IF(dlq1 > 1, 1, 0) OR IF(dlq2 > 1, 1, 0)
ReturnData: true
- Id: dlq1
MetricStat:
Metric:
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt
- MyDeadLetterQueue1
- QueueName
Stat: Sum
Period: 300
ReturnData: false
- Id: dlq2
MetricStat:
Metric:
Namespace: AWS/SQS
MetricName: ApproximateNumberOfMessagesVisible
Dimensions:
- Name: QueueName
Value: !GetAtt
- MyDeadLetterQueue2
- QueueName
Stat: Sum
Period: 300
ReturnData: false
EvaluationPeriods: 1
DatapointsToAlarm: 1
Threshold: 0
ComparisonOperator: GreaterThanThreshold
TreatMissingData: notBreaching
AlarmActions:
- !Ref MyTopicArn
I think you should sum the expression to has the acumulative value.我认为您应该将表达式求和以具有累积值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.