Installing CloudWatch Agent
Install CloudWatch Agent
- Start the EC2 instance connection
- Select Instances
- Select the newly created instance
- Copy Public IPv4 address
- Use PuTTY or MobaXterm to connect via port 22
- For detailed information about EC2 connection, please refer to Connecting Linux Virtual Machine

- MobaXterm interface.



- Since this is our first time accessing EC2 Instance we need to install the latest updates.

sudo yum update -y

- Connect to the EC2 Instance you just created and load the CloudWatch Agent package with the following command:
sudo wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm

- Install the downloaded agent package with the command:
sudo rpm -U ./amazon-cloudwatch-agent.rpm

- Create a script to send memory metrics to CloudWatch:
sudo vi /opt/aws/amazon-cloudwatch-agent/bin/config.json
- Press the i key and copy the following JSON file into the script:
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/httpd/access_log",
"log_group_name": "access_log"
}
]
}
}
},
"metrics": {
"metrics_collected": {
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 30
}
}
}
}

- Press the ESC key and then type :wq! to save the script.

- Run that script to send information to CloudWatch with the 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 Connection to CloudWatch
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status

- If the status is running, then proceed to the next step
- If the status is stopped, you need to start the Cloudwatch agent with the following command:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/bin/config. json

- Enter the following command to move to the directory containing the CloudWatch Agent log file:
cd /opt/aws/amazon-cloudwatch-agent/logs/

- Enter the following command to view the contents of the log file
cat amazon-cloudwatch-agent.log
