Skip to content

[Feat] API Server 프로메테우스/그라파나 모니터링 추가#322

Open
qjatjr29 wants to merge 17 commits intodevelopfrom
feat/#313-monitoring
Open

[Feat] API Server 프로메테우스/그라파나 모니터링 추가#322
qjatjr29 wants to merge 17 commits intodevelopfrom
feat/#313-monitoring

Conversation

@qjatjr29
Copy link
Collaborator

@qjatjr29 qjatjr29 commented Feb 4, 2026

📌 관련 이슈

closed: #313


✅ PR 체크리스트(최소요구조건)

[ ] 테스트 작성했다.

✨ 작업 개요

Prometheus와 Grafana 기반 모니터링 시스템을 구축하여 API, Outbox, RabbitMQ, Elasticsearch 전 영역에서 성능 지표를 수집

  • 도메인별 메트릭 서비스 구현 (API, Outbox, RabbitMQ, ES)
  • 전역 인터셉터를 통한 API 요청 메트릭 자동 수집
  • OutboxPublisher에 Outbox 및 RabbitMQ 메트릭 연동
  • RecordSyncConsumer에 RabbitMQ 및 ES 메트릭 연동

🧹 작업 상세 내용

1. Prometheus 모니터링 기반 구축

파일

  • metrics.constants.ts - API, Outbox, RabbitMQ, ES 메트릭 이름 상수 정의
  • metrics.provider.ts - Counter, Histogram, Gauge 프로바이더 통합 정의
  • api-metrics.service.ts - HTTP 요청 횟수 및 응답 시간 메트릭 기록
  • outbox-metrics.service.ts - Outbox 이벤트 발행, 상태 전이, DLQ 메트릭 기록
  • rabbitmq-metrics.service.ts - 메시지 publish/consumer, 인플라이트 메트릭 기록
  • elasticsearch-metrics.service.ts - ES 작업(index/update/delete) 성공/실패 및 성능 메트릭 기록

메트릭 정의

카테고리 메트릭명 타입
API http_requests_total Counter
  http_request_duration_seconds Histogram
Outbox outbox_events_published_total Counter
  outbox_status_transitions_total Counter
  outbox_processing_duration_seconds Histogram
  outbox_dead_letter_total Counter
RabbitMQ messages_published_total Counter
  messages_consumed_total Counter
  message_processing_duration_seconds Histogram
  messages_in_flight Gauge
ES elasticsearch_operations_total Counter
  elasticsearch_operation_duration_seconds Histogram
  record_sync_events_total Counter

2. 응답 변환 및 메트릭 수집 인터셉터

  • response-transform.interceptor.ts - /metrics 엔드포인트 예외 처리로 순환 문제 방지
  • api-metrics.interceptor.ts - 전역 인터셉터로 모든 HTTP 요청 메트릭 자동 수집

📸 스크린샷 (선택)

서버 리소스

image

API 성능

image image image

Elasticsearch 동기화 모니터링

image image image

🔍 고민 지점

[ 첫 번째 고민 ]

  • 문제점:
  • 해결 과정:

[ 두 번째 고민 ]

  • 문제점:
  • 해결 과정:

💬 기타 참고 사항

알림 시스템이나 DB 같은 것에 아직 모니터링을 붙이지 못했어요...!

일단 먼저 해야하는 것 (동기화 부분 장소 address) 처리 한 후 이어서 해볼예정이에요.

또한, 아직 인프라를 고려하지 않은 PR이라 머지후 dev, prod 환경에서도 모니터링을 확인할 수 있도록 좀 더 살펴본 후 PR에 내용을 추가하고자 해요 (다시 말씀드릴게요!)


- HTTP 요청 횟수와 요청 처리 시간수집
- /metrics 요청은 공통 응답 포맷 변환을 건너뛰도록 예외 처리
- 모든 HTTP 요청에 대해 메서드, 경로, 상태 코드 기준으로 메트릭을 수집
- Outbox 이벤트 발행 성공, 실패 Counter 메트릭으로 기록
- 처리 시간을 Histogram 메트릭으로 기록
- 상태 변경(from -> to status) 카운트
- 데드레터 발생 건수를 별도 메트릭으로 분리
- 메시지 발행 성공, 실패, 소비 ACK, NACK Counter 메트릭
- 처리 시간(초)을 Histogram으로 관측
- 메시지 큐의 인플라이트(in-flight) 상태를 Gauge 메트릭으로 기록
- 인덱싱/업데이트/삭제 작업의 성공, 실패 건수를 Counter 메트릭으로 기록

- 처리 시간을 Histogram으로 확인

- 레코드 동기화 이벤트 발생을 별도 Counter 메트릭으로 기록
- Outbox, RabbitMQ, Elasticsearch 별 Counter, Gauge, Histogram 프로바이더정의
- OutboxMetricsService, RabbitMQMetricsService, ElasticsearchMetricsService를 모듈 프로바이더로 추가

- 해당 메트릭 서비스들을 모듈 exports에 포함
- 이벤트 발행 성공, 실패, 상태 전이, 처리 시간, DLQ 발생을 메트릭으로 기록
- 메시지 소비 ACK/NACK, 인플라이트, 처리 시간 메트릭을 기록
- ES 작업 타입(index/update/delete)별 성공, 실패와 처리 시간을 메트릭으로 확인, 동기화 이벤트도 카운트
@qjatjr29 qjatjr29 self-assigned this Feb 4, 2026
@qjatjr29 qjatjr29 added the backend 백엔드 전반 로직, 서버 구현 작업 label Feb 4, 2026
Copy link
Collaborator

@mindaaaa mindaaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우와 백엔드 모니터링에서는 별도 관측 서비스 레이어도 필요하군요!
코드 처음봐서 신기합니다!

서버 안에서 일어난 사건들을 다 이어지게 관측할 수 있어서 좋아보이네요👀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 백엔드 전반 로직, 서버 구현 작업

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 백엔드 모니터링 붙이기

3 participants