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!
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:
value_now - value_before
. This is the absolute delta of the values.value_before
. This is the value of the metric in the last datapoint.Assuming that your metric in Cloudwatch is m
.
The absolute_delta
can be obtained with: absolute_delta = RATE(m) * PERIOD(m)
.
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
Just plug everything together and you have your final metric:
change_percentage = 100 * absolute_delta / value_before
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With