10A. CloudWatch ์๋ ์์ฑํ๊ธฐ
10A. CloudWatch ์๋ ์์ฑํ๊ธฐ ๊ด๋ จ

EC2 ์ธ์คํด์ค์ CPU ์ฌ์ฉ๋ฅ ์ ๋ชจ๋ํฐ๋งํ๊ณ ์ค์ ํ ์ธก์ ์น์ ๋๋ฌํ๋ฉด ์๋ฆผ ๋ฉ์ผ์ ์ ์กํ๋๋ก ์๋์ ์์ฑํด๋ณด๊ฒ ์ต๋๋ค. ์์ง EC2 ์ธ์คํด์ค๋ฅผ ์์ฑํ์ง ์์๋ค๋ฉด '4.3 EC2 ์ธ์คํด์ค ์์ฑํ๊ธฐ'๋ฅผ ์ฐธ์กฐํ์ฌ EC2 ์ธ์คํด์ค๋ฅผ ์์ฑํ๋๋ก ํฉ๋๋ค. ๋จผ์ EC2 ์ธ์คํด์ค(Example Server)๋ฅผ 1๋ถ ๋จ์๋ก ๋ชจ๋ํฐ๋ง ๊ฐ๋ฅํ๋๋ก ์ธ๋ถ ๋ชจ๋ํฐ๋ง ์ค์ ์ ํฉ๋๋ค.
Warning
์ธ๋ถ ๋ชจ๋ํฐ๋ง ์ค์ ์ ํ๋ฆฌ ํฐ์ด์์ ์ฌ์ฉํ ์ ์์ผ๋ฉฐ ์ถ๊ฐ ์๊ธ์ ์ง๋ถํด์ผ ํฉ๋๋ค. ์ถ๊ฐ ์๊ธ์ ์ง๋ถํ๊ณ ์ถ์ง ์๋ค๋ฉด ์ด ๋ถ๋ถ์ ๊ฑด๋๋ฐ์ด๋ ๋๊ณ ๊ธฐ๋ณธ ๋ชจ๋ํฐ๋ง ๋ง์ผ๋ก ์ค์ต์ด ๊ฐ๋ฅํฉ๋๋ค. ๋จ ์๋์ด ๋์ํ๋ ๊ฒ์ ํ์ธํ๋ ค๋ฉด 5๋ถ ์ด์ ๊ธฐ๋ค๋ ค์ผ ํฉ๋๋ค.
EC2 ์ธ์คํด์ค ๋ชฉ๋ก([INSTANCES]
โ [Instances]
)์์ EC2 ์ธ์คํด์ค(Example Server)๋ฅผ ์ ํํ๊ณ , ๋ง์ฐ์ค ์ค๋ฅธ์ชฝ ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํ์
๋ฉ๋ด๊ฐ ๋์ต๋๋ค(์์ชฝ [Actions]
๋ฒํผ์ ํด๋ฆญํด๋ ๊ฐ์ ๋ฉ๋ด๊ฐ ๋์ต๋๋ค). [Enable Detailed Monitoring]
์ ํด๋ฆญํฉ๋๋ค.


[Yes, Enable]
๋ฒํผ์ ํด๋ฆญํ์ฌ ์ธ๋ถ ๋ชจ๋ํฐ๋ง์ ํ์ฑํ ํฉ๋๋ค.
[Close]
๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.
[CloudWatch]
๋ฅผ ํด๋ฆญํฉ๋๋ค.
[Alarms]
๋ฅผ ํด๋ฆญํ๊ณ ์์ชฝ [Create Alarm]
๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.์๋ ์์ฑ์ฐฝ์ด ๋์ต๋๋ค.

[EC2 Matrics]
๋ฅผ ํด๋ฆญํฉ๋๋ค.InstanceId i-c5a8b8c3
์ ์ด์ ์ ์์ฑํ EC2 ์ธ์คํด์ค(Example Server)์
๋๋ค. EC2 ์ธ์คํด์ค๊ฐ ์ฌ๋ฌ ๊ฐ์ผ ๊ฒฝ์ฐ ์คํฌ๋กค์ ๋ด๋ฆฌ๋ฉด ๋ค๋ฅธ EC2 ์ธ์คํด์ค๋ ์ ํํ ์ ์์ต๋๋ค. [CPUUtilization]
์ ์ ํํ๊ณ , ์๋ ๊ทธ๋ํ ๋ถ๋ถ์์ ๋ชจ๋ํฐ๋ง ๊ฐ๊ฒฉ์ 1 Minute(1 ๋ถ)์ผ๋ก ๋ณ๊ฒฝํฉ๋๋ค.

[Next]
๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.๊ทธ๋ฆผ 10-9์ ์๋ ์ธ๋ถ ์ค์ ์ ๋๋ค.
- Name: ์๋์ ์ด๋ฆ์ ๋๋ค. CPU Watch๋ก ์ ๋ ฅํฉ๋๋ค.
- Description: ์๋์ ์ค๋ช ์ ๋๋ค(์ ๋ ฅํ์ง ์์๋ ์๊ด์์ต๋๋ค).
- Whenever is: ์ธก์ ์น๋ฅผ ์ซ์๋ก ์ ๋ ฅํฉ๋๋ค. ์ฌ๊ธฐ์๋ CPU ์ฌ์ฉ๋ฅ (%)์ ๋๋ค. >= 30์ผ๋ก ์ค์ ํฉ๋๋ค(CPU ์ฌ์ฉ๋ฅ 30% ์ด์์์ ์๋ ๋์). 30๋ฅผ ์ ๋ ฅํ๋ฉด ์ค๋ฅธ์ชฝ ๊ทธ๋ํ์์ 30์ ํด๋นํ๋ ์์น์ ๋นจ๊ฐ์์ผ๋ก ์ ์ด ํ์๋ฉ๋๋ค.
- Whenever for: ์ค์ ํ ์ธก์ ์น๊ฐ ๋ช ๋ฒ ๋๋ฌํ์ ๋ ์๋์ด ๋์ํ ์ง ์ค์ ํฉ๋๋ค. ์ด ๊ฐ์ 3์ผ๋ก ์ค์ ํ๋ค๋ฉด ์ค์ ํ ์ธก์ ์น์ ์ฐ์์ผ๋ก 3๋ฒ ๋๋ฌํด์ผ ์๋์ด ๋์ํ๊ฒ ๋ฉ๋๋ค (ํ์ฌ ๋ชจ๋ํฐ๋ง ๊ฐ๊ฒฉ์ด 1๋ถ์ด๋ฉด 3๋ถ ์ฐ์์ผ๋ก ์ธก์ ์น์ ๋๋ฌ). 1๋ฒ์ด๋ 2๋ฒ ๋๋ฌํ์ ๊ฒฝ์ฐ ์๋์ ๋์ํ์ง ์์ต๋๋ค. ๊ธฐ๋ณธ๊ฐ ๊ทธ๋๋ก ์ฌ์ฉํฉ๋๋ค.
ํ ์คํธ์ฉ ์๋ ์ค์ ์ด๊ธฐ ๋๋ฌธ์ ๋ฌด์กฐ๊ฑด ์๋์ด ๋ฐ์ํ๋๋ก CPU ์ฌ์ฉ๋ฅ ์ธก์ ์น๋ฅผ ๋ฎ๊ฒ ์ก์์ต๋๋ค. ์ค์ ๋ก Auto Scaling๊ณผ ์ฐ๊ณํ ๋์๋ ๋ณดํต 60% ๋๋ 80%๋ก ์ค์ ํฉ๋๋ค. ์ก์ ์ ์ด๋ฉ์ผ ์๋ฆผ(Notification)์ ์ฌ์ฉํ๊ฒ ์ต๋๋ค.

[New list]
๋ฅผ ํด๋ฆญํฉ๋๋ค์๋ ์ก์ ์ค์ ์ ๋๋ค.
- Whenever this alarm: ๊ธฐ๋ณธ๊ฐ์ธ State is ALARM์ ์ ํํฉ๋๋ค.
- State is ALARM: ์ค์ ํ ์ธก์ ์น๋ฅผ ๋์ด์ฐ์ ๋์ ์ํ์ ๋๋ค.
- State is OK: ์ค์ ํ ์ธก์ ์น์ ๋๋ฌํ์ง ๋ชปํ์ ๋์ ์ํ์ ๋๋ค.
- State is INSUFFICIENT: ๋ฐ์ดํฐ๊ฐ ์์ด์ ์ธก์ ์น๋ฅผ ์ ์ ์์ ๋์ ์ํ์ ๋๋ค.
- Send notification to: ์ด๋ฉ์ผ ์๋ฆผ์ ๋ฐ์ ์ฌ๋ ์ด๋ฆ์ ๋๋ค. admin์ผ๋ก ์ค์ ํฉ๋๋ค.
- Email list: ์๋ฆผ์ ๋ฐ์ ์ด๋ฉ์ผ ์ฃผ์์ ๋๋ค. ์ฌ๋ฌ ์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์ ๋ ฅํ ์ ์์ผ๋ฉฐ ,(์ฝค๋ง)๋ก ๊ตฌ๋ถํฉ๋๋ค.

[Create Alarm]
๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.
์น ๋ธ๋ผ์ฐ์ ๋ฅผ ์คํํ๊ณ ์ ๋ ฅํ ์ด๋ฉ์ผ ์ฃผ์์ ๋ฉ์ผํจ์ผ๋ก ์ด๋ํฉ๋๋ค. ๋ฉ์ผํจ์ ๋ณด๋ฉด AWS Notification - Subscription Confirmation์ด๋ผ๋ ๋ฉ์ผ์ด ๋์ฐฉํ์ ๊ฒ์ ๋๋ค.

Confirm subscription
๋งํฌ๋ฅผ ํด๋ฆญํฉ๋๋ค.์ด๋ฉ์ผ ํ์ธ์ด ์๋ฃ๋์๋ค๋ ํ์ด์ง๊ฐ ํ์๋ฉ๋๋ค.

๋ค์ CloudWatch์ ์๋ ์์ฑ ํ๋ฉด์ ๋ณด๋ฉด ์ด๋ฉ์ผ ํ์ธ์ด ์๋ฃ๋์๋ค๊ณ ํ์๋ฉ๋๋ค.

[View Alarm]
๋ฒํผ์ ํด๋ฆญํฉ๋๋ค.CloudWatch ์๋ ๋ชฉ๋ก์์ ์๋ก ์์ฑํ ์๋์ ํ์ธํ ์ ์์ต๋๋ค.

[OK]
์ ์์นํด ์์ต๋๋ค.์ด์ CPU ์ฌ์ฉ๋ฅ ์ ๊ฐ์ ๋ก ์ฌ๋ ค์ ALARM ์ํ๊ฐ ๋๋๋ก ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค. ์ด์ ์ ์์ฑํ EC2 ์ธ์คํด์ค(Example Server)์ SSH๋ก ์ ์ํ ๋ค yes > /dev/null
๋ช
๋ น์ ์
๋ ฅํฉ๋๋ค.
yes > /dev/null

