Install Amazon CloudWatch on EC2 Instances

To utilize the Resouce Rightsizing tool to collect metrics for memory instances install Amazon CloudWatch agent. nOps analyzes the CPU utilization for the last two weeks and finds the average idle utilization.

nOps checks the average memory utilization for an Amazon EC2 instance over a two-week period and recommends an instance size that has at least the average memory utilization available. For example: If the current instance type has 8GB of memory available, and the average memory utilization is 700MB over a two-week period, the rightsizing recommendation will suggest an instance type that has 1GB of available memory.

How to install Amazon CloudWatch:

Log in to the instance using SSH.

Run the following commands at the console to download and install the Amazon CloudWatch agent:

wget https://s3.amazonaws.com/amazoncloudwatch-agent/debian/amd64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i -E ./amazon-cloudwatch-agent.deb

Download and install the collectd daemon:

sudo apt-get update && sudo apt-get install collectd

Create the Amazon CloudWatch configuration file by running the Amazon

CloudWatch configuration wizard:

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

Log in to the AWS IAM console and select the “Roles” menu item. Click the “Create role” button.

On the “Select type of trusted entity” page, select “EC2” as the service to be associated with the new role. Click the “Next: Permissions” button to proceed.

On the “Attach permissions policies” page, select the “CloudWatchAgentServerPolicy”. Click “Next: Tags” to proceed.

On the “Add tags” page, add tags if required (optional). Click “Next: Review” to proceed.

On the “Review” page, enter a name for the new role. Click “Create role” to proceed and create the new role.

Click your username in the top right corner of the navigation bar and select the “My Security Credentials” menu item from the resulting drop-down menu.

On the “My security credentials” page, click the “Create access key” button.

In the resulting dialog, note the new AWS access key ID and corresponding secret access key

Create an AWS credentials file with the AWS access key ID and shared access key at /home/bitnami/.aws/credentials with the following content. Replace the AWS-ACCESS-KEY-ID and AWS-SECRET-ACCESS-KEY placeholders with the keys obtained in the previous step:

[default] aws_access_key_id=AWS-ACCESS-KEY-ID aws_secret_access_key=AWS-SECRET-ACCESS-KEY

Edit the common configuration file for the Amazon CloudWatch agent at /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml and specify the path to

the credentials file created in the previous step.

sudo vi /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml

Update the following content:

[credentials] shared_credential_file = "/home/bitnami/.aws/credentials"

Start the Amazon CloudWatch agent with the following command:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s

Check that the agent is running with the following command:

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status

The steps above will also automatically configure the Amazon CloudWatch agent to automatically start on server reboot.

Learn more through AWS Help Article: Installing the CloudWatch Agent

Did this answer your question?