Created
May 13, 2022 14:17
-
-
Save MateusBMP/c856916f976180217fad1bd97d6db604 to your computer and use it in GitHub Desktop.
Install basic CloudWatch Agent into Debian EC2 instance (see: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/installing-cloudwatch-agent-commandline.html)
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
| #!/usr/bin/bash | |
| wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/arm64/latest/amazon-cloudwatch-agent.deb | |
| sudo dpkg -i -E ./amazon-cloudwatch-agent.deb | |
| sudo apt update | |
| sudo apt install collectd -y | |
| touch /opt/aws/amazon-cloudwatch-agent/bin/config.json | |
| cat <<- "EOF" >> /opt/aws/amazon-cloudwatch-agent/bin/config.json | |
| { | |
| "agent": { | |
| "metrics_collection_interval": 60, | |
| "run_as_user": "root" | |
| }, | |
| "logs": { | |
| "logs_collected": { | |
| "files": { | |
| "collect_list": [ | |
| { | |
| "file_path": "/var/log", | |
| "log_group_name": "log", | |
| "log_stream_name": "{instance_id}", | |
| "retention_in_days": -1 | |
| } | |
| ] | |
| } | |
| } | |
| }, | |
| "metrics": { | |
| "aggregation_dimensions": [ | |
| [ | |
| "InstanceId" | |
| ] | |
| ], | |
| "append_dimensions": { | |
| "AutoScalingGroupName": "${aws:AutoScalingGroupName}", | |
| "ImageId": "${aws:ImageId}", | |
| "InstanceId": "${aws:InstanceId}", | |
| "InstanceType": "${aws:InstanceType}" | |
| }, | |
| "metrics_collected": { | |
| "collectd": { | |
| "metrics_aggregation_interval": 60 | |
| }, | |
| "disk": { | |
| "measurement": [ | |
| "used_percent" | |
| ], | |
| "metrics_collection_interval": 60, | |
| "resources": [ | |
| "*" | |
| ] | |
| }, | |
| "mem": { | |
| "measurement": [ | |
| "mem_used_percent" | |
| ], | |
| "metrics_collection_interval": 60 | |
| }, | |
| "statsd": { | |
| "metrics_aggregation_interval": 60, | |
| "metrics_collection_interval": 10, | |
| "service_address": ":8125" | |
| } | |
| } | |
| } | |
| } | |
| EOF | |
| 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