disqus: brainbackdoor | false
kakaoChannel: false
floatFirstTOC: right

1. Cloudwatch로 수집하기

A. EC2에 IAM role 설정

5dbc54fbd5404dc180eac611fa5f69d7.png

B. Cloudwatch agent 설정

$ wget <https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb>
$ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
# /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/syslog",
                                                "log_group_name": "syslog",
                                                "log_stream_name": "{instance_id}",
																		            "timezone": "Local"
                                        }
                                ]
                        }
                }
        },
        "metrics": {
                "metrics_collected": {
                        "disk": {
                                "measurement": [
                                        "used_percent",
                                        "used",
                                        "total"
                                ],
                                "metrics_collection_interval": 60,
                                "resources": [
                                        "*"
                                ]
                        },
                        "mem": {
                                "measurement": [
                                        "mem_available"
                                ],
                                "metrics_collection_interval": 60
                        },
                        "netstat": {
                                "measurement": [
                                        "tcp_syn_sent",
                                        "tcp_syn_recv"
                                ],
                                "metrics_collection_interval": 60
                        },
                }
        }
}
$ 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
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
{
  "status": "running",
  "starttime": "2023-11-27T22:01:10+00:00",
  "configstatus": "configured",
  "version": "1.300031.0b313"
}

2. 지표

스크린샷 2023-11-28 오전 7.50.28.png