Last active
November 7, 2021 20:55
-
-
Save domderen/787925f0417369c69d8a45ba6eb61cb7 to your computer and use it in GitHub Desktop.
This file contains 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
#!/bin/bash | |
echo "Installing CW Agent" | |
sudo yum install amazon-cloudwatch-agent -y | |
echo "Creating CW Agent config file" | |
cat > /opt/aws/amazon-cloudwatch-agent/bin/config.json <<EOL | |
{ | |
"agent": { | |
"metrics_collection_interval": 60, | |
"run_as_user": "root" | |
}, | |
"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, | |
"totalcpu": false | |
}, | |
"disk": { | |
"measurement": [ | |
"used_percent", | |
"inodes_free" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"diskio": { | |
"measurement": [ | |
"io_time", | |
"write_bytes", | |
"read_bytes", | |
"writes", | |
"reads" | |
], | |
"metrics_collection_interval": 60, | |
"resources": [ | |
"*" | |
] | |
}, | |
"mem": { | |
"measurement": [ | |
"mem_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"netstat": { | |
"measurement": [ | |
"tcp_established", | |
"tcp_time_wait" | |
], | |
"metrics_collection_interval": 60 | |
}, | |
"swap": { | |
"measurement": [ | |
"swap_used_percent" | |
], | |
"metrics_collection_interval": 60 | |
} | |
} | |
} | |
} | |
EOL | |
echo "Starting CW 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/bin/config.json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment