Image Credits: amazon.com
Amazon Web Services has inbuilt functionality to good metrics on the console by default, like CPU, but it’s missing some key metrics that can cause bottlenecks like memory usage or disk space; these are essential to monitor to ensure instance uptime and health.
The monitoring scripts are written by Amazon themselves, but aren’t included unless you set them up yourself, which isn’t always obvious. The scripts are available for different operating systems, however we will focus on Linux-based systems in this post. Amazon's documentation on CloudWatch Agent implementation, while comprehensive, is hard to find; hopefully this post will help you with your own instance monitoring.
Note: This post will be helpful for developers/devOps who would like to configure CloudWatch for disk and memory monitoring as the previous perl scripts provided by AWS is deprecated and not recommended and there is no other sources which mentions the steps clearly.
AWS has how-to instructions on creating memory, disk and swap checks via Perl scripts located at https://aws.amazon.com/code/8720044071969977. These scripts are customised and need cron jobs to be configured to use designated intervals, every 5 minutes.
Amazon introduced AWS CloudWatchAgent to automate this:
Here is a few important list of the available metrics within the manual monitoring scripts:
- Memory Utilization (%)
- Memory Used (MB)
- Memory Available (MB)
- Swap Utilization (%)
- Swap Used (MB)
- Disk Space Utilization (%)
- Disk Space Used (GB)
- Disk Space Available (GB)
Installation Process Overview
The general flow of installing the CloudWatch agent is as follows:
1. Create and Configure the IAM roles and users for the CloudWatch agent.
2. If you are installing on an EC2 instance, attach an IAM role to the instance. Else, If you are installing on an on-premises server, you need to create an IAM user to enable the CloudWatch agent to write information to CloudWatch.
3. Downloading the CloudWatch agent package, using either AWS Systems Manager Run Command or a public Amazon S3 download link.
4. Modify the CloudWatch agent configuration files as per our requirement.
5. Initiate the agent, using from the command line.
How to Simplify Memory and Disk Utilization Monitoring in AWS
1. Create an IAM Role and attach policy 'CloudWatchAgentServerPolicy'
2. Attach the instance you want to monitor to the created role from EC2 instance console.
Select Instance --> Actions --> Instance Settings --> Attach/Replace IAM Role
3. SSH to your EC2 instance and follow the steps
Downloading the CloudWatch Agent Package on an EC2 Instance
Make a directory for downloading the AmazonCloudWatchAgent and then navigate to that directory
Download the CloudWatch agent.
Unzip the package
Install the package
Open the CloudWatch Wizard and choose options
The config file generated will be at:
This file can be manually edited according to your requirements
Start the CloudWatch
CloudWatch Status can be checked at:
You'll see following status if CloudWatch is running
If required, CloudWatch monitoring can be stopped
CloudWatch logs will be generated at this path:
CloudWatch other paths are defined at this URL:
Here is an example of standard configuration file to monitor cpu, disk, memory & swap