linuxamazon-web-servicesamazon-cloudwatchcloudwatch-alarms

CloudWatch Alarms based on file existence in Ec2


I have a requirement to monitor for a specific file in the /mnt/file-i-need-to-monitor.txt path where I need to;

  1. Create alarms if the file doesn't exist anymore.
if [ ! -f /mnt/file-i-need-to-monitor.txt ]; then
    // create aws alarm and notify via an email
fi

How can I integrate this methodology?

I have looked into the aws log agent but it seems like it is for pushing any custom logs to a log group.

Can someone help me fix this?


Solution

  • Hello Jananath Banuka,

    For your case, you can use aws cli to push a custom metric, And you create an alert based on the console if this custom metric if you have > 1

    https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/put-metric-data.html