11

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 ?

Naween Ghimire
  • 111
  • 1
  • 1
  • 3

3 Answers3

7

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.

arbazkhan002
  • 1,283
  • 2
  • 13
  • 18
5

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/

Wal
  • 174
  • 1
  • 5
  • Thanks for the response. But there is one more problem here, while creating custom metrics mon-put-data(...) you have to define a unit type. In my case it would be '%' for CPUUtilizatoin, where as NetworkIn, NetworkOut can't be having '%' as unit. How to overcome this ? – Naween Ghimire Feb 22 '13 at 04:26
  • 1
    Just to be clear the suggested strategy is to take the Network and CPU metrics (obtained via GetMetricStatistics) and combine them into a single new custom metric (by some function you define yourself) which you will then publish by PutMetricData ... then creating the alarm on that custom metric which will act as your Autoscaing alarm ... – Wal Feb 22 '13 at 10:02
0

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)

harsha
  • 1
  • 1