JSCODE Logo
프로그래밍 과외블로그후기멘토진
회사명 : JSCODE대표 : 박재성사업자 등록번호 : 244-22-01557통신판매업 : 제 2023-인천미추홀-0381 호
학원 명칭 : 제이에스코드(JSCODE)원격학원학원설립ㆍ운영 등록번호 : 제6063호

서울특별시 구로구 경인로 20가길 11(오류동, 아델리아)

Copyright ⓒ 2025 JSCODE - 최상위 현업 개발자들의 프로그래밍 교육 All rights reserved.

이용약관개인정보처리방침
← 블로그 목록으로 돌아가기

[실습] EC2 모니터링 셋팅하기

JSCODE 박재성
JSCODE 박재성
2025-12-06
author
JSCODE 박재성
category
부하테스트
createdAt
Dec 6, 2025
series
대규모 트래픽 처리를 위한 부하테스트 입문/실전
slug
exercise-monitor-ec2
type
post
updatedAt
Dec 6, 2025 04:46 AM

✅ EC2가 수집하는 기본 지표들

EC2 인스턴스를 생성하면 기본적으로 수집하는 지표들이 있다.
  • CPU 사용률(CPUUtilization)
  • 네트워크 사용률(NetworkIn, NetworkOut)
  • 디스크 성능(DiskReadOps, DiskWriteOps)
  • 디스크 읽기/쓰기(DiskReadBytes, DiskWriteBytes)
  • 등등
notion image
 
단순히 인스턴스가 멈추지 않고 가동되고 있는지를 확인하기에는 위의 지표를 감시하는 것만으로 충분할 지도 모르지만, 확실한 모니터링을 위해서는 메모리(Memory)도 반드시 모니터링 할 필요가 있다. CloudWatch Agent를 인스턴스에 설치하고 구성 파일을 설정한 후 실행하면 메모리(Memory)를 포함한 더 많은 지표를 수집할 수 있다.
 
 

✅ EC2에 Cloudwatch Agent 설치하기

  1. IAM Role 생성
    1. notion image
      notion image
       
  1. 정책 선택하기
    1. notion image
       
  1. 역할 이름 설정하기
    1. notion image
      notion image
       
  1. EC2 인스턴스에 IAM Role 연결
    1. notion image
      notion image
       
  1. EC2 인스턴스로 접속해 Cloudwatch Agent 설치하기
    1. # Ubuntu x86-64 Cloudwatch Agent 다운로드 $ wget https://s3.amazonaws.com/amazoncloudwatch-agent/ubuntu/amd64/latest/amazon-cloudwatch-agent.deb # 다운받은 패키지 설치 $ sudo dpkg -i -E ./amazon-cloudwatch-agent.deb
       
  1. CloudWatch Agent 설정 파일 생성하기
    1. $ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
      ================================================================ = Welcome to the Amazon CloudWatch Agent Configuration Manager = = = = CloudWatch Agent allows you to collect metrics and logs from = = your host and send them to CloudWatch. Additional CloudWatch = = charges may apply. = ================================================================ # 사용하고 있는 운영체제는 무엇입니까? On which OS are you planning to use the agent? 1. linux 2. windows 3. darwin default choice: [1]: 1 # EC2 인스턴스 환경인지? 아니면 온프레미스 환경인지? Trying to fetch the default region based on ec2 metadata... I! imds retry client will retry 1 timesAre you using EC2 or On-Premises hosts? 1. EC2 2. On-Premises default choice: [1]: 1 # 리눅스에서 어떤 user가 Cloudwatch Agent를 사용할 건지? Which user are you planning to run the agent? 1. cwagent 2. root 3. others default choice: [1]: 2 # StatsD 데몬(애플리케이션 지표를 수집)을 사용할 건지? Do you want to turn on StatsD daemon? 1. yes 2. no default choice: [1]: 2 # CollectD라는 시스템 메트릭 모니터링 도구를 사용할 건지? Do you want to monitor metrics from CollectD? WARNING: CollectD must be installed or the Agent will fail to start 1. yes 2. no default choice: [1]: 2 # 컴퓨터(host)의 메트릭(CPU, 메모리 등)을 모니터링 할 건지? Do you want to monitor any host metrics? e.g. CPU, memory, etc. 1. yes 2. no default choice: [1]: 1 # 코어별로 CPU 메트릭을 모니터링 할 건지? Do you want to monitor cpu metrics per core? 1. yes 2. no default choice: [1]: 1 # 모든 메트릭에 EC2 Dimension(이미지 ID, 인스턴스 ID, 인스턴스 타입, 오토스케일링 그룹 이름)의 정보를 추가해서 수집할 건지? Do you want to add ec2 dimensions (ImageId, InstanceId, InstanceType, AutoScalingGroupName) into all of your metrics if the info is available? 1. yes 2. no default choice: [1]: 1 # EC2 Dimension(InstanceId)를 기준으로 집계를 할 건지? Do you want to aggregate ec2 dimensions (InstanceId)? 1. yes 2. no default choice: [1]: 1 # 메트릭을 몇 초 간격으로 수집을 할 건지? Would you like to collect your metrics at high resolution (sub-minute resolution)? This enables sub-minute resolution for all metrics, but you can customize for specific metrics in the output json file. 1. 1s 2. 10s 3. 30s 4. 60s default choice: [4]: 4 # 기본 메트릭 구성을 어떻게 설정할 건지? # Basic : 메모리 사용량(mem_used_percent), 디스크 사용량(disk_used_percent)) Which default metrics config do you want? 1. Basic 2. Standard 3. Advanced 4. None default choice: [1]: 1 Current config as follows: { "agent": { "metrics_collection_interval": 60, "run_as_user": "root" }, "metrics": { "aggregation_dimensions": [ [ "InstanceId" ] ], "append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}", "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" }, "metrics_collected": { "disk": { "measurement": [ "used_percent" ], "metrics_collection_interval": 60, "resources": [ "*" ] }, "mem": { "measurement": [ "mem_used_percent" ], "metrics_collection_interval": 60 } } } } # 위의 구성에 만족하는 지? Are you satisfied with the above config? Note: it can be manually customized after the wizard completes to add additional items. 1. yes 2. no default choice: [1]: 1 # 합치고 싶은 CloudWatch Agent의 설정 파일이 있는 지? Do you have any existing CloudWatch Log Agent (http://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html) configuration file to import for migration? 1. yes 2. no default choice: [2]: 2 # 로그 파일을 모니터링 할 건지? Do you want to monitor any log files? 1. yes 2. no default choice: [1]: 2 # CloudWatch Agent가 X-ray(AWS의 분산 추적 시스템)의 정보를 수집하게 할 건지? Do you want the CloudWatch agent to also retrieve X-ray traces? 1. yes 2. no default choice: [1]: 2 Existing config JSON identified and copied to: /opt/aws/amazon-cloudwatch-agent/etc/backup-configs Saved config file to /opt/aws/amazon-cloudwatch-agent/bin/config.json successfully. Current config as follows: { "agent": { "metrics_collection_interval": 60, "run_as_user": "root" }, "metrics": { "aggregation_dimensions": [ [ "InstanceId" ] ], "append_dimensions": { "AutoScalingGroupName": "${aws:AutoScalingGroupName}", "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}" }, "metrics_collected": { "disk": { "measurement": [ "used_percent" ], "metrics_collection_interval": 60, "resources": [ "*" ] }, "mem": { "measurement": [ "mem_used_percent" ], "metrics_collection_interval": 60 } } } } Please check the above content of the config. The config file is also located at /opt/aws/amazon-cloudwatch-agent/bin/config.json. Edit it manually if needed. # 설정 정보를 AWS의 SSM parameter store(AWS의 값 저장소)에 저장할 건지? Do you want to store the config in the SSM parameter store? 1. yes 2. no default choice: [1]: 2 Program exits now.
       
  1. CloudWatch Agent 실행하기
    1. $ 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
       
  1. CloudWatch Agent가 잘 실행되고 있는 지 확인하기
    1. $ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
       
  1. CloudWatch로 가서 메트릭이 잘 수집되고 있는 지 확인하기
    1. notion image
      notion image
      notion image
 
 
 

✅ 세부 모니터링 설정

EC2에 기본적으로 설정되어 있는 모니터링은 5분 간격으로 메트릭(CPU 등)을 수집한다. 부하 테스트를 통해 정확한 모니터링을 하기 위해 5분 간격이 아닌 1분 간격으로 메트릭을 수집하게끔 바꿔보자.
notion image
notion image
 
author
category
부하테스트
createdAt
Dec 6, 2025
series
대규모 트래픽 처리를 위한 부하테스트 입문/실전
slug
type
series-footer
updatedAt
Dec 6, 2025 04:54 AM
📎
이 글은 대규모 트래픽 처리를 위한 부하테스트 입문/실전 강의의 수업 자료 중 일부입니다.