Is it possible to set CloudWatch alarm for a combination of metrics?
Solution 1
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.
Solution 2
Recently AWS just announced CloudWatch Metric Math which should be suitable for your use case.
References:-
- Amazon CloudWatch Adds Metric Math to Enable Custom Operations on Metrics
- Create a CloudWatch Alarm Based on a Metric Math Expression
Related videos on Youtube
Comments
-
ben almost 2 years
For example, I want to trigger a CloudWatch alarm for the following:
Number of messages sent
-Number of messages deleted
>= 6The 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
-
earlNameless over 7 yearsThat's a good question, but most of the times, pure metrics are not enough to set alarms and intermediary quantities need to be built and exported to CloudWatch. e.g. maximum of a set of metrics, variation rate of a metric, delta to a goal value.
-
-
ben over 7 yearsThank You (+1). I figured it out a few mins later :D . However, I wasn't sure about the term
Approximate
in it. Why approximate, when it can tell the exact number of messages available? -
Tensibai over 7 yearsBecause the metrics are pulled periodically, so they can't guarantee that between the collect time and presentation time there was no change in the queue.