7
votes

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!

2
What type of Dashboard are you using? One generated by Amazon CloudWatch, or is it running on some other software?John Rotenstein
A CloudWatch dashboard.plex4r

2 Answers

7
votes

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

4
votes

Metric math function RATE() calculates the rate of change per second.

Returns the rate of change of the metric, per second. This is calculated as the difference between the latest data point value and the previous data point value, divided by the time difference in seconds between the two values.

From https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/using-metric-math.html

So to get the rate of change for your period you could do this:

RATE(m1)*PERIOD(m1)

and set the period of the dashboard to the wanted value.

Problem in your case is that you need it for a period of 30 min, I don't think you can set 30 min as period on the CloudWatch dashboard. Closest values would be 15 min or 1 hour.