1
votes

I have a custom metric in cloudwatch that counts how many files have been uploaded to an S3 bucket. I want to get alarmed when the number of the uploaded files has exceeded some threshold that will be calculated in %. I have been thinking and I think I'll need to calculate for each value a percentage value :

Example :

at 8h: I have 80 files uploaded.

The maximum number of files that can be uploaded at a time is defined to be 200 files

so the percentage for the value of 80 is : p = 80*100/200 = 40%

So I need to create a custom metric that calculates the percentage of each value and get me notified by an alarm when the percentage is higher than 80%

Any idea how to do this calculation ?

Below the graph of the uploaded files

graph

1

1 Answers

1
votes

You need a separate metric where each metric is a percentage.

My suggestion is to have a lambda function that runs on a schedule using CloudWatch events. The frequency of the execution of the lambda function would be the same as the period of the above metric. For example, if you're publishing the above metric every minute, then you could execute your lambda every minute too.

Your lambda function would get the latest datapoint from your above metric via the GetMetricStatistics API and would calculate a percentage based on the latest datapoint and your threshold. It would then publish the percentage to a separate metric.