AWS Cloud watch alarm, triggering autoscaling usin

2020-08-20 08:27发布

问题:

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 ?

回答1:

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/



回答2:

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.



回答3:

This is supported now. You can check https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html for the same.

As an example, you can use something like (CPU Utilization>80) OR (MEMORY Consumed>55)