Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Cloud watch alarm, triggering autoscaling using multiple metrics

I want to create a cloud watch alarm which triggers autoscaling based on more than one metric data. Since this is not natively supported by Cloud Watch ( Correct me if i am wrong ). I was wondering how to overcome this.

Can we get the data from different metrics, say CPUUtilization, NetworkIn, NetworkOut and then create a custom metrics using mon-put-data and enter these data to create a new metric based on which to trigger an autoscaling ?

like image 796
Naween Ghimire Avatar asked Feb 19 '13 10:02

Naween Ghimire


People also ask

How do you make a CloudWatch alarm for multiple metrics?

To create an alarm that's based on a metric math expressionOpen the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Alarms, and then choose All alarms. Choose Create alarm.

Can CloudWatch trigger Auto Scaling?

The Auto Scaling action isn't enabled for the CloudWatch alarm, which prevents the scaling policy from being invoked. The scaling policy in the Auto Scaling group is disabled. A disabled policy prevents the group from being evaluated.

Can you configure the alarm to monitor more than 1 metric?

You can set an alarm on the result of a math expression that is based on one or more CloudWatch metrics. A math expression used for an alarm can include as many as 10 metrics. Each metric must be using the same period.


2 Answers

You can now make use of CloudWatch Metric Math.

Metric math enables you to query multiple CloudWatch metrics and use math expressions to create new time series based on these metrics. You can visualize the resulting time series in the CloudWatch console and add them to dashboards.

More information regarding Metric Math Syntax and Functions available here: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html#metric-math-syntax

However, it needs to be noted that there are no logical operators and you have to use arithmetic functions to make your way out.

To help out anyone bumping here, posting an example: Lets say you want to trigger an alarm if CPUUtilization < 20% and MemoryUtilization < 30%.

m1 = Avg CPU Utilization % for 5mins
m2 = Avg Mem Utilization % for 5mins

Then:

Avg. CPU Utilization % < 20  for 5 mins AND Avg Mem Utilization % < 30 for 5mins   ... (1)

is same as

(m1 - 20) / ABS([m1 - 20]) + (m2 - 30) / ABS([m2 - 30]) < 0   ... (2)

So, define your two metrics and build a metric query which looks like LHS of equation (2) above. Set your threshhold to be 0 and set comparison operator to be LessThanThreshold.

like image 173
arbazkhan002 Avatar answered Oct 19 '22 22:10

arbazkhan002


Yes .. Cloudwatch Alarms can only trigger on a single Cloudwatch Metric so you would need to publish your own 'aggregate' custom metric and alarm on that as you suggest yourself.

Here is a blog post describing using custom metrics to trigger autoscaling.

http://www.thatsgeeky.com/2012/01/autoscaling-with-custom-metrics/

like image 41
Wal Avatar answered Oct 20 '22 00:10

Wal