Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Install System Manager Agent using User data:

#!/bin/bash
cd /tmp
sudo dnf install -y https://s3.amazonaws.com/ec2-downloads-
windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
sudo systemctl enable amazon-ssm-agent
sudo systemctl start amazon-ssm-agent
cd /etc/amazon/ssm/
touch amazon.ssm.agent.json
cp amazon-ssm-agent.json.template amazon-ssm-agent.json
sudo systemctl restart amazon-ssm-agent

yum info amazon-ssm-agent -> To check the ssm services

#!/bin/bash
cd /tmp
wget https://s3.amazonaws.com/amazoncloudwatch-agent/redhat/amd64/latest/amazon-
cloudwatch-agent.rpm

sudo dnf install -y https://s3.amazonaws.com/amazoncloudwatch-


agent/redhat/amd64/latest/amazon-cloudwatch-agent.rpm
cd ..

sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m


ec2 -s -c file:etc/opt/aws/amazon-cloudwatch-agent/bin/config.json

#!/bin/bash
cd /tmp
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
cd ..
cat <<EOT >> /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "cwagent"
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"cpu": {
"measurement": [
"cpu_usage_idle",
"cpu_usage_iowait",
"cpu_usage_user",
"cpu_usage_system"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": false
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"diskio": {
"measurement": [
"io_time"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60
}
}
}
}
EOT
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config –m
ec2 -s -c file:etc/opt/aws/amazon-cloudwatch-agent/bin/config.json

Attach a Role with SSMServiceRole

Open the Systems Manager console at https://console.aws.amazon.com/systems-manager/.


In the navigation pane, choose Run Command.
Choose Run command.
In the Command document list, choose AWS-ConfigureAWSPackage.
In the Targets area, choose the instance to install the CloudWatch agent on
In the Action list, choose Install.
In the Name field, enter AmazonCloudWatchAgent.
Keep Version set to latest to install the latest version of the agent.
Choose Run.

To start the CloudWatch agent using Run Command

1. Open the Systems Manager console at https://console.aws.amazon.com/systems-


manager/.
2. In the navigation pane, choose Run Command.
-or-

If the AWS Systems Manager home page opens, scroll down and choose Explore Run
Command.
3. Choose Run command.
4. In the Command document list, choose AmazonCloudWatch-ManageAgent.
5. In the Targets area, choose the instance where you installed the CloudWatch agent.
6. In the Action list, choose configure.
7. In the Optional Configuration Source list, choose ssm.
8. In the Optional Configuration Location box, enter the name of the agent configuration
file that you created and saved to Systems Manager Parameter Store, as explained in Create the
CloudWatch agent configuration file.
9. In the Optional Restart list, choose yes to start the agent after you have finished these
steps.
10. Choose Run.
11. Optionally, in the Targets and outputs areas, select the button next to an instance name
and choose View output. Systems Manager should show that the agent was successfully started.

References:

Role: https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-service-role.html

Agent Installation: https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-install-


managed-linux.html

Download agent using SSM:


https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/download-CloudWatch-Agent-
on-EC2-Instance-SSM-first.html

Configuration using SSM & Start aganet:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-
EC2-Instance-fleet.html

Configuration: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-
cloudwatch-agent-configuration-file-wizard.html

Manual Installation: https://docs.aws.amazon.com/systems-manager/latest/userguide/agent-install-


rhel.html

You might also like