반응형
기본적으로 Alertmanager는 기본적으로 Google-chat으로 알림을 보낼 수 없습니다.
그러나 현재 회사에서 Google-chat을 사용하고 있어서, Alertmanager에서 발생하는 alert 페이로드를 받아서 설정된 Google-chat 웹훅 엔드포인트로 메시지를 전달해주는 애플리케이션을 생성하였습니다.
이제 제가 했던 방법을 설명드리겠습니다.
사전 준비
- k8s 클러스터
- kube-prometheus-stack 설치
- Google-chat 스페이스의 webhook 주소
1. 코드 clone
- 먼저 calert git clone 해줍니다.
git clone https://github.com/mr-karan/calert.git
2. go build 실행
- clone한 디렉터리로 이동 한 후
go build명령어 실행, 이 때 linux 환경으로 빌드를 해주어야합니다.GOOS=linux GOARCH=amd64 go build -o calert.bin ./cmd
3. config.sample.toml 파일 내용 수정
- config.sample.toml 파일을 열어서 내용 수정해줍니다.
[app]
address = "0.0.0.0:6000" # http://<서버_IP>:6000 형태로 접근 가능
server_timeout = "60s" # HTTP 요청 타임아웃 시간, 60초 이상 걸리면 연결 종료
enable_request_logs = true # 들어오는 HTTP 요청 로그 남길 지 여부
log = "info" # 로그 레벨 설정
[providers.<Prometheus Alertmanager 설정 파일의 receivers.name 값과 동일 해야합니다.>]
type = "google_chat" # google_chat으로 고정
endpoint = "<여기에 google-chat의 webhook 등록>"
max_idle_conns = 50 # HTTP 클라이언트의 최대 유휴 연결 수, 즉 동시에 여러 Alert 보낼 때 연결 재사용 최적화를 위함
timeout = "30s" # google-chatdㅡ로 메시지 전송 시 타임아웃 (30초 초과 시 실패 처리)
# proxy_url = "http://internal-squid-proxy.com:3128"
template = "static/message.tmpl"
thread_ttl = "12h"
threaded_replies = false # Whether to send threaded replies or not.
dry_run = false4. Dockerfile 작성
FROM ubuntu:22.04
RUN apt-get -y update && apt install -y ca-certificates
WORKDIR /app
COPY calert.bin .
COPY static/ /app/static/
COPY config.sample.toml config.sample.toml
ARG CALERT_GID="999"
ARG CALERT_UID="999"
RUN addgroup --system --gid $CALERT_GID calert && \
adduser --uid $CALERT_UID --system --ingroup calert calert && \
chown -R calert:calert /app
USER calert
EXPOSE 6000
ENTRYPOINT [ "./calert.bin" ]5. 이미지 빌드 후 푸시
- 저는 현재 ECR을 사용하고 있어서 ECR로 보냈습니다.
- 자신이 사용하고 있는 이미지 Repo에 Push 하면 됩니다.
docker build -t <사용하는 Repo:태그> . docker push <사용하는 Repo:태그>
6. Deploy, Service 생성
apiVersion: v1
kind: Service
metadata:
name: alertmanager-service
spec:
selector:
app: alert
ports:
- port: 6000
targetPort: 6000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: alertmanager
spec:
replicas: 1
selector:
matchLabels:
app: alert
template:
metadata:
labels:
app: alert
spec:
containers:
- name: alert
image: <자신이 사용하고 있는 이미지 레포>
ports:
- containerPort: 60007. alertmanager-values.yaml 설정변경
kube-prometheus-stack차트에서 사용하던values.yaml내용 중 아래 부분을 수정해주면 됩니다.alertmanager: config: route: name: 'google-chat' receivers: - name: 'google-chat' webhook_configs: - url: "http://<앞서 생성한 서비스 이름.네임스페이스.svc.cluster.local:6000/dispatch>" send_resolved: true
이상 입니다.
감사합니다.
반응형
'Monitoring' 카테고리의 다른 글
| OpenTelemetry Collector 샘플링 튜닝: 원하는 트레이스를 잡아내는 방법 (0) | 2025.08.26 |
|---|---|
| 개발자의 도움 필요 없이 분산 Trace 추적: OpenTelemetry Auto-Instrumentation과 Tempo 활용법 (1) | 2025.08.21 |
| Istio ingressgateway 와 ALB 연결 (0) | 2025.07.24 |
| Istio, Kiali 설치 및 Prometheus, Grafana 연결 (Using Helm) (3) | 2025.07.24 |
| 트래픽 조절하면서 Canary 배포 해보기 (used by Istio) (3) | 2025.07.24 |