[英]AWS CloudWatch Alarm not triggered for SQS Metrics “NumberOfMessagesReceived”
I am trying to trigger an alarm if message is sent to SQS
. 如果消息发送到
SQS
我试图触发警报。 However, I see that the CloudWatch
metrics indicates that there was a message but no alarm is triggered. 但是,我看到
CloudWatch
指标表明有消息但没有触发警报。
The alarm is currently in INSUFFICIENT_DATA
state as well. 警报当前也处于
INSUFFICIENT_DATA
状态。 For testing, I am sending a message via boto3
client. 为了进行测试,我正在通过
boto3
客户端发送消息。
Below is my CloudFormation Template for SQS
and CloudWatch
alarm 以下是我的
SQS
和CloudWatch
警报的CloudWatch
模板
QueueMessageAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
AlarmDescription: "Alarm if queue message is greater than 0"
AlarmActions:
- !Ref SampleNotificationTopic
Namespace: "AWS/SQS"
MetricName: "NumberOfMessagesReceived"
Statistic: "Sum"
Period: "900"
EvaluationPeriods: "1"
Threshold: "0"
ComparisonOperator: "GreaterThanThreshold"
Dimensions:
- Name: "QueueName"
- Value:
Fn::GetAtt:
- "KinesisStreamFileQueue"
- "QueueName"
KinesisStreamFileQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: "StreamQueue"
Use the ApproximateNumberOfMessagesVisible metric instead of any "Received" metric. 使用roximateNumberOfMessagesVisible指标,而不是任何“已接收”指标。
The downside of using "Received" metrics is that unless you're constantly receiving messages, you're likely to get stuck in INSUFFICIENT_DATA
, resulting in alarm issues. 使用“已接收”度量标准的不利之处在于,除非您不断接收消息,否则您很可能会陷入
INSUFFICIENT_DATA
,从而导致警报问题。
I figured out the issue by changing the Dimensions
properties
for the alarm resource. 我通过更改警报资源的“
Dimensions
properties
来解决问题。 The resource needs to refer to the arn
of the queue, and it was previously getting the url
of it 该资源需要引用队列的
arn
,并且之前已获取到它的url
。
Dimensions:
- Name: QueueName
Value: { "Fn::GetAtt": [ "KinesisStreamFileQueue", "QueueName"] }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.