CloudWatch Agent를 Parameter Store에서 관리해 보기

CloudWatch Agent를 Parameter Store에서 관리해 보는 방법에 대해서 정리해 봤습니다.
2022.09.10

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

안녕하세요 클래스메소드 김재욱(Kim Jaewook) 입니다. 이번에는 CloudWatch Agent를 Parameter Store에서 관리해 보는 방법에 대해서 정리해 봤습니다.

CloudWatch Agent를 설정하고, 메모리, 디스크 사용률을 이메일로 통지하는 CloudWatch Alarm을 생성해 보는 방법에 대해서는 아래 블로그를 참고해 주세요.

CloudWatch Agent 설치

CloudWatch Agent를 설치하기 위해 먼저, Run Command로 들어와서「명령 실행」버튼을 클릭합니다.

AWS-ConfigureAWSPackage를 선택합니다.

이어서 명렁 파라미터에 Name에 AmazonCloudWatchAgent를 입력합니다.

마지막으로 EC2 인스턴스를 선택하고, 명령을 실행합니다.

명령어가 성공적으로 실행 된 것을 확인할 수 있습니다.

cd "C:\Program Files\Amazon\AmazonCloudWatchAgent"
.\amazon-cloudwatch-agent-config-wizard.exe

다음 명령어로 CloudWatch Agent 설정을 시작합니다.


=============================================================
= Welcome to the AWS CloudWatch Agent Configuration Manager =
=============================================================
On which OS are you planning to use the agent?
1. linux
2. windows
default choice: [2]:

Trying to fetch the default region based on ec2 metadata...
Are you using EC2 or On-Premises hosts?
1. EC2
2. On-Premises
default choice: [1]:

Do you want to turn on StatsD daemon?
1. yes
2. no
default choice: [1]:


Which port do you want StatsD daemon to listen to?
default choice: [8125]

What is the collect interval for StatsD daemon?
1. 10s
2. 30s
3. 60s
default choice: [1]:

What is the aggregation interval for metrics collected by StatsD daemon?
1. Do not aggregate
2. 10s
3. 30s
4. 60s
default choice: [4]:

Do you have any existing CloudWatch Log Agent configuration file to import for migration?
1. yes
2. no
default choice: [2]:

Do you want to monitor any host metrics? e.g. CPU, memory, etc.
1. yes
2. no
default choice: [1]:

Do you want to monitor cpu metrics per core?
1. yes
2. no
default choice: [1]:

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]:

Do you want to aggregate ec2 dimensions (InstanceId)?
1. yes
2. no
default choice: [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]:

Which default metrics config do you want?
1. Basic
2. Standard
3. Advanced
4. None
default choice: [1]:
2

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]:

Do you want to monitor any customized log files?
1. yes
2. no
default choice: [1]:
2

Do you want to monitor any Windows event log?
1. yes
2. no
default choice: [1]:
2

Please check the above content of the config.
The config file is also located at config.json.
Edit it manually if needed.
Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:

What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy)
default choice: [AmazonCloudWatch-windows]
AmazonCloudWatch-test-cloudwatchagent

Trying to fetch the default region based on ec2 metadata...
Which region do you want to store the config in the parameter store?
default choice: [ap-northeast-1]

Which AWS credential should be used to send json config to parameter store?
1. ASIAYGKV54QYWOZRWI3G(From SDK)
2. Other
default choice: [1]:

CloudWatch Agent는 다음과 같이 설정합니다.


Do you want to store the config in the SSM parameter store?
1. yes
2. no
default choice: [1]:

What parameter store name do you want to use to store your config? (Use 'AmazonCloudWatch-' prefix if you use our managed AWS policy)
default choice: [AmazonCloudWatch-windows]
AmazonCloudWatch-test-cloudwatchagent

Trying to fetch the default region based on ec2 metadata...
Which region do you want to store the config in the parameter store?
default choice: [ap-northeast-1]

Which AWS credential should be used to send json config to parameter store?
1. ASIAYGKV54QYWOZRWI3G(From SDK)
2. Other
default choice: [1]:

다음 선택지를 통해서 CloudWatch Agent 설정 값을 Parameter Store에 저정하게 됩니다.

다시 Run Command로 들어가서 AmazonCloudWatch-ManageAgent를 선택합니다.

이어서 Optional Configuration Location에 조금 전 CloudWatch Agent에서 설정할 때 입력 했던 파라미터의 이름을 입력합니다.

현재 블로그에서는 AmazonCloudWatch-test-cloudwatchagent 라는 이름으로 파라미터를 생성한 상태입니다.

이후, 인스턴스를 선택하고 Run Command를 실행합니다.

이제 CloudWatch로 들어가서 해당 인스턴스의 아이디를 검색하면 CWAgent 지표에 나타나는 것을 확인할 수 있습니다.

Parameter Store를 이용해서 CloudWatch Agent 실행

현재 EC2라는 이름의 인스턴스에 CloudWatch Agent가 실행중인 상태입니다.

그리고 EC2-2라는 인스턴스에 EC2에 설정한 것과 동일한 CloudWatch Agent를 실행할 생각입니다.

먼저 CloudWatch Agent를 설치합니다.

CloudWatch Agent를 설치하지 않으면, CloudWatch Agent가 설치되지 않았다는 에러 메시지가 뜨게 됩니다.

Name에 CloudWatch Agent를 입력합니다.

CloudWatch Agent를 설치할 인스턴스를 선택하고, Run Command를 실행합니다.

Parameter Store로 들어가서, 파라미터의 값을 복사합니다.

「파라미터 생성」버튼을 클릭합니다.

파라미터의 이름을 입력하고「값」에는 조금 전 복사한 CloudWatch Agent의 설정 값을 붙여넣고, 파라미터 생성을 끝마칩니다.

Run Command로 들어가서 AmazonCloudWatch-ManageAgent를 선택합니다.

Optional Configuration Location에는 조금 전 생성한 파라미터의 이름을 입력합니다.

마지막으로 EC2 인스턴스를 선택하고, Run Command를 실행합니다.

조금 기다려보면 상태가 성공으로 바뀌는 것을 확인할 수 있습니다.

CloudWatch에서 확인해 보면 EC2-2 인스턴스에 문제 없이 CloudWatch Agent가 적용된 것을 확인할 수 있습니다.

이런식으로 Parameter Store에 파라미터를 생성해서 CloudWatch Agent 설정값을 관리하면, 보다 빠르게 인스턴스에 CloudWatch Agent를 적용할 수 있고, 새 인스턴스에 보다 간편하게 설정 값을 수정할 수 있습니다.

본 블로그 게시글을 보시고 문의 사항이 있으신 분들은 클래스메소드코리아 (info@classmethod.kr)로 연락 주시면 빠른 시일 내 담당자가 회신 드릴 수 있도록 하겠습니다 !