- Install AWS CLI (if not already installed):
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
- Create an IAM User with Proper Permissions:
Generate Access Key and Secret Access Key for the user
- Install the CloudWatch Agent:
wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb
sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
- Configure AWS Credentials:
aws configure
sudo aws configure --profile AmazonCloudWatchAgent
AWS Access Key ID [None]:
AWS Secret Access Key [None]: >
Default region name [None]:
Default output format [None]:
- Create CloudWatch configuration file to collect memory and Disk usage metrics
sudo vi /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60
},
"metrics": {
"append_dimensions": {
"InstanceId": "${aws:InstanceId}"
},
"metrics_collected": {
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
- Modify the CloudWatch Agent Configuration File :
sudo vim /opt/aws/amazon-cloudwatch-agent/etc/common-config.toml
Press “I” to enter insert mode in Vim, and uncomment this line
[credentials]
shared_credential_profile = "AmazonCloudWatchAgent"
Press “ESC”, and then type “:wq!” to save the file and exit Vim.
- Start the CloudWatch Agent and check the status :
sudo amazon-cloudwatch-agent-ctl -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -a fetch-config -s
sudo systemctl status amazon-cloudwatch-agent
- Verify metrics in CloudWatch
- Push JSON Configuration to Systems Manager Parameter Store:
aws ssm put-parameter --name "CloudWatchAgentForAppServer02-Config" --type "String" --value file:///opt/aws/amazon-cloudwatch-agent/bin/config.json
- Verify this in SSM Parameter Store