2

I have an ubuntu instance on AWS and I want an email when 80% of disk space is consumed. I have checked the cloud watch but there is no such option to monitor disk space. There is only one option which is custom metric https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/mon-scripts.html but I am not sure that it will give an email alert. Please guide me for the same.

1 Answer 1

2

Update:

1. Create an instance and attach the IAM Role :

 AmazonEC2RoleforSSM
 CloudWatchAgentAdminPolicy
 CloudWatchAgentServerPolicy
 AmazonSSMManagedInstanceCore

2. Install CloudWatch agent : : In the RunCommand , choose AWS-ConfigureAWSPackage to the install it on the desired Target.

3. Running the CloudWatch agent wizard : Start the CloudWatch agent configuration wizard by entering the following:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard

At one stage, you will prompted by the wizard to choose which default predefined metrics you want and if you want to store the config in the SSM parameter store. I had chosen Advanced to include all metrics and Yes to store in the config. Once completed , the entire config is available in the Parameter store in AWS Systems Manager. My config snippet has :

"disk": {
                "measurement": [
                    "used_percent",
                    "inodes_free"
                ],
                "metrics_collection_interval": 60,
                "resources": [
                    "*"
                ]
            },

4. Start the CloudWatch agent There are 2 ways to start the agent : a. From Run Command b. From command line with Systems Manager Parameter store.

The Run Command failed for some reason but the command line worked

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:configuration-parameter-store-name -s

c. If you encounter any error No package collectd available , install the necessary package to restart the agent.

For Amazon Linux :

sudo amazon-linux-extras install epel
sudo yum install collectd

For Ubuntu :

sudo apt-get install collectd collectd-utils

5. CloudWatch console

Create a Dashboard to monitor the instance metrics which is now available as custom namespaces via the CWAgent. You can also set necessary Alarm to notify / email recipients.


CloudWatch custom metrics

enter image description here


Previous post

You may want to deploy Systems Manager (SSM) Agent installed on you instance to monitor and alert you for disk space usage. For this use, you will need to create a Role in IAM for the EC2 instance to send data to CloudWatch. Once that's complete, you can use a JSON script to monitor disk space from within the Run command of SSM.

More details are available at https://blog.justinworrell.com/2017/09/30/monitoring-free-disk-space-on-a-windows-ec2-instance-with-cloudwatch/

3
  • this is for windows instance but I am using ubuntu instance for that it is not working Commented Jul 16, 2019 at 7:39
  • Ubuntu Server AMIs starting with 16.04 has SSM installed readily with snap packages. You will want to see docs.aws.amazon.com/systems-manager/latest/userguide/… for the complete details Commented Jul 17, 2019 at 4:48
  • I have Ubuntu Server 18.04 and SSM is intalled by default. The only problem I am facing in the doc blog.justinworrell.com/2017/09/30/… is when I try to run a command, AWS-ConfigureCloudWatch is only available for windows platform. So I am not able to select my instance there. Commented Jul 17, 2019 at 5:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .