HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Is it possible to set CloudWatch alarm for a combination of metrics?

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
cloudwatchcombinationalarmpossiblemetricsforset

Problem

For example, I want to trigger a CloudWatch alarm for the following:

Number of messages sent - Number of messages deleted >= 6

The above is for AWS SQS metrics. And I want that metric to trigger AWS Lambda if that alarm is set off.

Is there any way I can do it? If not, then is there any work-around [Aiming for a serverless paradigm]

[I want to do that, cause there's no metric which tells me the number of messages currently (available) in the queue].
So, if there's a metric which can give me that, it'd be very helpful

Solution

For the last overall goal, I would set the alarm on ApproximateNumberOfMessagesVisible from Cloudwatch documentation on SQS this is:


The number of messages available for retrieval from the queue.


Units: Count


Valid Statistics: Average, Minimum, Maximum, Sum, Data Samples
(displays as Sample Count in the Amazon SQS console)

For the more generic computed metric question I would go with a lambda running priodically, gathering metrics from cloudwatch, doing the maths and pushing back to cloudwatch.

Here is an example lambda gathering data from Cloudwatch to push to elasticsearch. With the examples on the documentation you should be able to push metrics back from the lambda.

Be aware that calling cloudwatch API to gather and push metrics has a cost when you got over 1M request per month, there's other limits to be aware of to avoid breaking your budget/workflow.

Context

StackExchange DevOps Q#205, answer score: 9

Revisions (0)

No revisions yet.