简体   繁体   English

在多个 SQS 队列上创建 CloudWatch 警报

[英]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.

相关问题 如果一个小时内没有消息发送消息,Cloudwatch会设置警报 - Cloudwatch set alarm if no message in sqs for an hour 没有为SQS指标“ NumberOfMessagesReceived”触发AWS CloudWatch警报 - AWS CloudWatch Alarm not triggered for SQS Metrics “NumberOfMessagesReceived” 适用于SQS的AWS CloudWatch警报消息数量可见 - AWS CloudWatch alarm for SQS Number of Messages Visible AWS Cloudwatch - 当我尝试为SQS创建警报时,自动调节组未显示 - AWS Cloudwatch - Autoscaling groups are not showing up when I try to create an alarm for SQS 是否可以使用 Terraform 为 AutoScaling 组的同一 CloudWatch 警报创建多个条件? - It is possible to create multiple conditions for the same CloudWatch alarm for AutoScaling group with Terraform? 为多个实例设置CloudWatch Alarm - Setting CloudWatch Alarm for multiple instances 为什么我在CloudWatch中看不到所有SQS队列的指标 - Why I don't see metrics for all SQS queues in CloudWatch AWS多个SQS队列和工作人员优化设计 - AWS multiple SQS queues and workers optimal design 一个 SQS 轮询器能否处理多个 SQS 队列并确定其优先级? - Can one SQS poller, handle multiple SQS queues and prioritize it? 跟踪多个 AWS SQS 队列上的消息 - Tracking a message on multiple AWS SQS queues
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM