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

7,906

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:-

Share:
7,906

Related videos on Youtube

ben
Author by

ben

Statistically insignificant, gets lucky all the time.

Updated on September 18, 2022

Comments

  • ben
    ben almost 2 years

    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

    • earlNameless
      earlNameless over 7 years
      That'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
    ben over 7 years
    Thank 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
    Tensibai over 7 years
    Because 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.