- Attach needed IAM permissions to the EC2 instance profile IAM role:
CloudWatchAgentServerPolicy
AWS managed IAM policy- Additional permissions likely needed (to download config from SSM parameter and to set CW Logs retention):
{ "Effect": "Allow", "Action": [ "ssm:GetParameter" ], "Resource": [ "arn:aws:ssm:*:*:parameter/*CloudWatch*", "arn:aws:ssm:*:*:parameter/*cloudwatch*", ] }, { "Effect": "Allow", "Action": [ "logs:PutRetentionPolicy" ], "Resource": "*" }
- Install the agent:
- Amazon Linux 2:
sudo yum install amazon-cloudwatch-agent
- Other distributions:
- Download and install the package. Ubuntu example:
curl -LO https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
- Download and install the package. Ubuntu example:
- Amazon Linux 2:
- Create
/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
. The included example is a reasonable default, all available config can be found here. - Apply the config and start the agent:
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
Last active
January 7, 2025 06:45
-
-
Save atheiman/2091894d2b76844f619d40bcbcc6fd8d to your computer and use it in GitHub Desktop.
Linux Amazon CloudWatch Agent install and configure guide
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metrics": { | |
"append_dimensions": { | |
"ImageId": "${aws:ImageId}", | |
"InstanceId": "${aws:InstanceId}", | |
"InstanceType": "${aws:InstanceType}", | |
"AutoScalingGroupName": "${aws:AutoScalingGroupName}" | |
}, | |
"metrics_collected": { | |
"disk": { | |
"measurement": [ "used_percent" ], | |
"ignore_file_system_types": [ | |
"devtmpfs", | |
"overlay", | |
"squashfs", | |
"sysfs", | |
"tmpfs" | |
] | |
}, | |
"mem": { | |
"measurement": [ "used_percent" ] | |
}, | |
"processes": { | |
"measurement": [ | |
"total", | |
"total_threads" | |
] | |
} | |
} | |
}, | |
"logs": { | |
"logs_collected": { | |
"files": { | |
"collect_list": [ | |
{ | |
"file_path": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log", | |
"log_group_name": "/amazon-cloudwatch-agent/amazon-cloudwatch-agent.log", | |
"retention_in_days": 14 | |
} | |
] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment