CloudWatch Agent for EC2
Install CloudWatch Agent
Configure CloudWatch Agent to Monitoring Instance's OS-Level Metrics
INSTANCE_NAME="<INSTANCE_NAME>"
sudo cat << EOF > /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"aggregation_dimensions": [
[
"InstanceId"
],
[
"AutoScalingGroupName",
"InstanceId"
],
[
"InstanceName",
"InstanceId"
],
[
"AutoScalingGroupName"
]
],
"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",
"cpu_usage_active"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": true,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"diskio": {
"measurement": [
"io_time",
"write_bytes",
"read_bytes",
"writes",
"reads"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"mem": {
"measurement": [
"used",
"mem_used_percent"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"net": {
"measurement": [
"bytes_sent",
"bytes_recv"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"netstat": {
"measurement": [
"tcp_established",
"tcp_time_wait"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
}
}
}
}
EOF
INSTANCE_NAME="<INSTANCE_NAME>"
cat << EOF > /opt/aws/amazon-cloudwatch-agent/bin/config.json
{
"agent": {
"metrics_collection_interval": 60,
"run_as_user": "root"
},
"metrics": {
"aggregation_dimensions": [
[
"InstanceId"
],
[
"AutoScalingGroupName",
"InstanceId"
],
[
"InstanceName",
"InstanceId"
],
[
"AutoScalingGroupName"
]
],
"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",
"cpu_usage_active"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"totalcpu": true,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"disk": {
"measurement": [
"used_percent",
"inodes_free"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"diskio": {
"measurement": [
"io_time",
"write_bytes",
"read_bytes",
"writes",
"reads"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"mem": {
"measurement": [
"used",
"mem_used_percent"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"net": {
"measurement": [
"bytes_sent",
"bytes_recv"
],
"metrics_collection_interval": 60,
"resources": [
"*"
],
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"netstat": {
"measurement": [
"tcp_established",
"tcp_time_wait"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
},
"swap": {
"measurement": [
"swap_used_percent"
],
"metrics_collection_interval": 60,
"append_dimensions": {
"InstanceName": "${INSTANCE_NAME}"
}
}
}
}
}
EOF
Note
If you use aws agents, you can use these log configurations.
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/aws/codedeploy-agent/codedeploy-agent.log",
"log_group_name": "codedeploy-agent-log",
"log_stream_name": "{instance_id}-agent-log",
"retention_in_days": 90
},
{
"file_path": "/opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log",
"log_group_name": "codedeploy-agent-deployment-log",
"log_stream_name": "{instance_id}-codedeploy-agent-deployment-log",
"retention_in_days": 90
},
{
"file_path": "/tmp/codedeploy-agent.update.log",
"log_group_name": "codedeploy-agent-updater-log",
"log_stream_name": "{instance_id}-codedeploy-agent-updater-log",
"retention_in_days": 90
}
]
}
}
}