반응형
개요
amp은 프로메테우스 모니터링 서비스입니다.
장점
- 프로메테우스 서버(pod)를 이중화 하지 않아도 됩니다.
- 사용하는 만큼 비용을 지불하기 때문에 볼륨(PV, EFS) 설정을 하지 않아도됩니다.
- pod를 관리할 필요없으며, 확장성, 가용성 및 보안을 누릴 수 있습니다.
단점 :
- prometheus Dashboard가 없어서 사용하기 불편합니다.
- awscurl으로 query URL으로 메트릭 정보 및 알람 정보를 봐야합니다.
- AlertManager Dashboard가 없어서 사용하기 불편합니다.
- Rule Management를 yaml형태로 업로드해서 사용해야합니다.
- Alert Manager에 yaml형태로 업로드해서 사용해야합니다.
- Alert은 SNS만 지원됩니다.
- AMP -> SNS -> Lambda -> Slack
1. AMP 구축
- amp -> "All workspaces" -> "Create workspace" 클릭
- Workspace alias : amp Name 입력
- "Create workspace" 클릭
2. AMP Rule
- 프로메테우스 Rule 설정방법입니다.
- 프로메테우스에서 설정한 Rule 규칙에 맞으면 Alert를 발생합니다.
- Rule example
groups:
- name: test # rule 구분 이름
rules:
- record: metric:recording_rule
expr: avg(rate(container_cpu_usage_seconds_total[5m]))
- name: alert-test # rule 구분 이름
rules:
- alert: metric:alerting_rule # Alert 이름
expr: avg(rate(container_cpu_usage_seconds_total[5m])) > 0 # Alert Rule
for: 2m # Alert rule 시간 설정
# Alert 조건에 맞으면 Pending 상태 for 2분동안 조건이 유지되면 Alert 발생
Rule 등록 방법
- "Rules management" -> "Add namespace" 클릭
- "Choose file" 클릭 : rule.yaml 파일 업로드
- Continue 클릭
3. 알람 선행조건 : SNS & Lambda 생성
- 알람 FlowChart : AMP Alertmanager -> SNS -> Lambda -> Slack
- AMP Alertmanager는 Alert를 SNS(Simple Notification Service)으로만 보낼 수 있습니다.
- Lamdba를 통해서 Slack으로 메세지를 보냅니다.
3-1. Lambda 생성
- Lambda -> Functions -> "Create function" 클릭
- "Author from scratch" 클릭
- Function name : 입력
- Runtime : Python 3.x 클릭
- Architecture : x86_64 클릭
- "Create function" 클릭
- Lambda code 등록
- url : slack hook 주소 넣기
- slack hook 주소 만들기 : https://dongwook35.tistory.com/50
#!/usr/bin/python3.6
import urllib3
import json
import yaml
http = urllib3.PoolManager()
def lambda_handler(event, context):
url = "https://hooks.slack.com/services/xxxxxxxxxx" # slack hook 주소 입력
msg = yaml.safe_load(event['Records'][0]['Sns']['Message'])
encoded_msg = json.dumps(msg).encode('utf-8')
resp = http.request('POST',url, body=encoded_msg)
print({
"SNS": event['Records'][0]['Sns'],
"message": event['Records'][0]['Sns']['Message'],
"status_code": resp.status,
"response": resp.data
})
- 에서 업로드 클릭
- .zip 파일 클릭
- pyYAML zip파일 업로드
pyYAML 만드는 방법
$ python3 -m venv pyyaml
$ source pyyaml/bin/activate
$ pip install pyyaml -t ./python
$ deactivate
$ zip -r layer-PyYAML.zip ./python/
$ aws lambda publish-layer-version --layer-name PyYAML --description "PyYAML" --compatible-runtimes python3.6 python3.7 python3.8 python3.9 --zip-file fileb://layer-PyYAML.zip
3-2. Lambda 생성
- SNS-> Topics -> "Create topic" 클릭
- Type : Standard 클릭
- Name : 이름 입력
- Access policy - optional : Advanced 클릭
- "Create topic" 클
{
"Version": "2008-10-17",
"Id": "__default_policy_ID",
"Statement": [
{
"Sid": "__default_statement_ID",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"SNS:Publish",
"SNS:RemovePermission",
"SNS:SetTopicAttributes",
"SNS:DeleteTopic",
"SNS:ListSubscriptionsByTopic",
"SNS:GetTopicAttributes",
"SNS:AddPermission",
"SNS:Subscribe"
],
"Resource": "",
"Condition": {
"StringEquals": {
"AWS:SourceAccount": "xxx" # AWS AccountID 입력
},
"ArnEquals": {
"aws:SourceArn": "arn:aws:aps:*:xxx:workspace/*" # AWS AccountID 입력
}
}
}
]
}
- Lambda 구독 설정
- SNS에서 메세지가 들어오면 Lambda으로 전달하기 위해서 구독 설정
- 생성한 Lambda 클릭 -> Subscriptions -> "Create subscription" 클
- Topic ARN : 생성한 SNS 클릭
- Protocol : Lambda 클릭
- Endpoint : 생성한 Lambda 클릭
- "Create subscription" 클
4. AMP Alertmanager
- 프로메테우스 Rule 조건에 맞으면 Alert를 발생합니다.
- Alertmanager는 Alert를 보낼 곳을 정의하는 곳입니다.
- AMP Alertmanager는 Alert를 SNS(Simple Notification Service)으로만 보낼 수 있습니다.
- 메뉴얼 : https://docs.aws.amazon.com/ko_kr/prometheus/latest/userguide/AMP-alertmanager-receiver.html
- 생성한 amp 클릭 -> "Alert manager" -> "Add definition" 클
- Choose file : alertmanager.yaml 클릭
- Countinue 클릭
5. AMP Scrape 설정
- EKS, WorkerNode, pod 데이터를 프로메테우스에서 읽을 수 있도록 메트릭 exporter 설치
- exporter에서 생성한 메트릭을 scrap할 수 있는 ADOT(OpenTelemetry) 설치
- 메뉴얼 링크 : https://docs.aws.amazon.com/ko_kr/prometheus/latest/userguide/AMP-onboard-ingest-metrics-OpenTelemetry.html
반응형
'모니터링 > prometheus' 카테고리의 다른 글
[kube-state-metrics] 설치 (0) | 2025.06.02 |
---|---|
[ prometheus ] scrape 설정 (0) | 2023.09.26 |
[ prometheus ] blackbox exporter (0) | 2023.09.26 |
[ Prometheus ] Alert - Rule (0) | 2023.03.16 |
[ Prometheus ] AlertManager - Slack 설정 (0) | 2023.03.16 |