Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CloudWatch metric math with a cumulative metric's value 30 minutes ago to show rate of change

I have a AWS CloudWatch custom metric that represents a cumulative value which continues to increase overtime. I will add that metric to a dashboard, but I also want to show the rate of change of this metric over the last 30 minutes. Ideally I would like a function to return the metric's value from 30 minutes ago and subtract that from the current value. The "Rate()" function does not seem to help.

I could submit the metrics value a second time with a timestamp that is 30 minutes in the future and subtract these two metrics, but I am hoping for a solution that uses metric math and does not force me to submit another metric. I can think of other use cases where I might want to do math with metrics from different time periods. Hope I am just missing something here!

like image 339
plex4r Avatar asked Oct 23 '18 14:10

plex4r


1 Answers

You can use some arithmetic to obtain the previous value and then you're able to calculate the percentage of change as you want.

The value you want is: (value_now - value_before) / value_before

Breaking this into 2 parts:

  1. Obtain value_now - value_before. This is the absolute delta of the values.
  2. Obtain value_before. This is the value of the metric in the last datapoint.

Assuming that your metric in Cloudwatch is m.

Step 1: The absolute delta

The absolute_delta can be obtained with: absolute_delta = RATE(m) * PERIOD(m).

Step 2: The previous value

With some arithmetic it is possible to obtain previous_value. Given the definition of absolute delta:

absolute_delta = value_now - value_before

Since we have value_now = m and absolute_delta, then it's a matter of inverting the equation:

value_before = value_now - absolute_delta

Final equation

Just plug everything together and you have your final metric:

change_percentage = 100 * absolute_delta / value_before

In CloudWatch terms:

cloudwatch metrics definition

like image 146
Edison Gustavo Muenz Avatar answered Sep 23 '22 00:09

Edison Gustavo Muenz