Skip to content

feat: 모니터링 설정#58

Open
byunhm02 wants to merge 7 commits into
developfrom
feature/#54_monitoring-setting
Open

feat: 모니터링 설정#58
byunhm02 wants to merge 7 commits into
developfrom
feature/#54_monitoring-setting

Conversation

@byunhm02

@byunhm02 byunhm02 commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

🚀 Related issue

closes #54

#️⃣ Summary

  • prometheus, grafana 모니터링 설정

🎯 Work Description

  • docker-compose.yml에 Prometheus 서비스 추가
  • prometheus.yml 설정 파일 작성(Spring Boot actuator 메트릭 수집,nginx-exporter 메트릭 수집)
  • docker-compose.yml에 Grafana 서비스 추가
  • stub_status 엔드포인트 추가

👍 동작 확인

  • swagger나 postman 결과를 캡쳐하여 첨부
image

💬 To Reviewers

  • 노션에 있는 application.yml에서 바뀐사항 없다면 그 뒤에 actuator 설정 추가하겠습니다!~

Summary by CodeRabbit

  • 새로운 기능

    • Prometheus·Grafana 모니터링 스택 추가(서비스 및 퍼시스턴트 볼륨 포함), Grafana 대시보드·데이터소스 프로비저닝 적용
    • 애플리케이션(/actuator/prometheus) 및 Nginx(/stub_status) 메트릭 엔드포인트 추가로 모니터링 가능
  • 작업(Chores)

    • 배포 스크립트 및 CI에 모니터링 구성 파일 전송 항목 추가되어 배포 시 모니터링 설정이 배포됩니다

@coderabbitai

coderabbitai Bot commented Mar 19, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Prometheus·Grafana 모니터링 기능이 추가되었습니다: Docker Compose에 Prometheus, Grafana, nginx-exporter와 영속 볼륨이 추가되고 prometheus.yml·Grafana 프로비저닝·대시보드 파일이 도입되었으며, Nginx에 /stub_status 엔드포인트와 CI 배포 워크플로우의 파일 복사에 prometheus.yml가 포함되었습니다.

Changes

Cohort / File(s) Summary
CI/CD 워크플로우
\.github/workflows/deploy.yml
EC2로 파일 전송 시 source 목록에 prometheus.yml 추가
Docker Compose 서비스
docker-compose.yml
prometheus, grafana, nginx-exporter 서비스 추가 및 prometheus_data, grafana_data 볼륨 선언; 포트·네트워크·restart 정책 설정
Prometheus 설정 파일
prometheus.yml
글로벌 scrape/evaluation 간격 15s, carena(/actuator/prometheus)와 nginx-exporter 스크랩 타겟 추가
Nginx 설정 및 배포 스크립트
nginx/conf.d/nginx-blue.conf.template, nginx/conf.d/nginx-green.conf.template, scripts/deploy.sh
location /stub_status 블록 추가 (stub_status on, allow 172.0.0.0/8 / deny all)
애플리케이션 보안 예외
src/main/java/.../PublicEndpoint.java
PROMETHEUS("/actuator/prometheus", HttpMethod.GET) 상수 추가로 해당 엔드포인트를 공개 처리
Grafana 프로비저닝 및 대시보드
monitoring/grafana/provisioning/...
Grafana 데이터소스·대시보드 프로비저닝 파일(datasources/prometheus.yml, dashboard.yml, dashboards/carena_dashboard.json) 추가

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CI as CI/CD Deploy
  participant EC2 as EC2 Host
  participant Prom as Prometheus
  participant App as Application (blue/green)
  participant NExp as nginx-exporter
  participant Graf as Grafana

  CI->>EC2: Upload `docker-compose.yml`,`prometheus.yml`,nginx templates,...
  EC2->>Prom: Start Prometheus service (reads /prometheus.yml)
  Prom->>App: GET /actuator/prometheus (blue:8080, green:8080) (scrape)
  Prom->>NExp: GET /metrics (nginx-exporter:9113) (scrape)
  Graf->>Prom: Query metrics (Prometheus API)
  Graf-->>User: Render dashboards
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • Kyoung-M1N

Poem

🐰 깡충, 모니터링 왔구나!
Prometheus는 숫자들을 세고,
Grafana는 그걸 그림으로 불러오네,
/stub_status는 살짝 엿보며 지키고,
서버들아, 이제 밝게 뛰어라 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목 '모니터링 설정'은 변경 사항의 핵심 내용(Prometheus 및 Grafana 모니터링 기능 추가)을 명확하게 요약하고 있습니다.
Linked Issues check ✅ Passed 모든 연결된 이슈 #54의 요구사항(Prometheus 서비스 추가, prometheus.yml 설정, Grafana 서비스 추가, stub_status 엔드포인트)이 코드 변경사항에 반영되어 충족되었습니다.
Out of Scope Changes check ✅ Passed PublicEndpoint.java의 PROMETHEUS 엔드포인트 추가는 /actuator/prometheus 경로를 공개 엔드포인트로 설정하는 것으로 모니터링 기능 구현 범위 내 필요한 변경입니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR 설명이 제공된 템플릿 구조를 따르고 있으며, 관련 이슈, 요약, 작업 설명, 동작 확인, 리뷰어 코멘트가 포함되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/#54_monitoring-setting

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@byunhm02 byunhm02 changed the title Feature/#54 monitoring setting feat: 모니터링 설정 Mar 19, 2026
@byunhm02 byunhm02 self-assigned this Mar 19, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (3)
nginx/conf.d/nginx-green.conf.template (2)

13-17: 들여쓰기가 일관되지 않습니다.

location /stub_status 블록 내부의 들여쓰기가 상위 location / 블록과 일치하지 않습니다. 가독성과 유지보수를 위해 일관된 들여쓰기를 사용해주세요.

🔧 들여쓰기 수정 제안
     location /stub_status {
-            stub_status on;
-            allow 172.0.0.0/8;
-            deny all;
-        }
+        stub_status on;
+        allow 172.0.0.0/8;
+        deny all;
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nginx/conf.d/nginx-green.conf.template` around lines 13 - 17, 들여쓰기 불일치:
location /stub_status 블록의 들여쓰기가 상위 location / 블록과 맞지 않으니 location /stub_status,
stub_status on;, allow 172.0.0.0/8;, deny all;, 그리고 마지막 중괄호의 들여쓰기를 상위 location /
블록과 동일한 수준으로 정렬해 주세요; 각 중첩 블록은 프로젝트의 기존 스타일(예: 4스페이스 또는 탭)을 따라 통일된 들여쓰기를 사용하도록
수정하면 됩니다.

15-15: IP 대역 범위가 과도하게 넓습니다.

172.0.0.0/8은 172.0.0.0 ~ 172.255.255.255 전체를 허용하며, 이 중 일부는 공용 IP 대역입니다. Docker 브릿지 네트워크는 일반적으로 172.17.0.0/16 또는 172.16.0.0/12 (사설 IP 범위)를 사용합니다. 보안을 위해 더 제한적인 CIDR을 사용하는 것이 좋습니다.

🔒 더 제한적인 IP 대역 사용 제안
     location /stub_status {
-            allow 172.0.0.0/8;
+            allow 172.16.0.0/12;
             deny all;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@nginx/conf.d/nginx-green.conf.template` at line 15, The nginx allow directive
currently uses an overly broad CIDR "allow 172.0.0.0/8;": replace this with a
more restrictive private-range CIDR (e.g., "allow 172.17.0.0/16;" or "allow
172.16.0.0/12;") or make it configurable via a template variable, updating the
allow directive in nginx-green.conf.template accordingly to limit access to the
expected Docker/private subnet.
scripts/deploy.sh (1)

96-100: 동일한 IP 대역 범위 문제가 있습니다.

템플릿 파일들과 마찬가지로 172.0.0.0/8 대역이 과도하게 넓습니다. 172.16.0.0/12로 변경을 권장합니다.

🔒 IP 대역 수정 제안
   location /stub_status {
       stub_status on;
-      allow 172.0.0.0/8;
+      allow 172.16.0.0/12;
       deny all;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/deploy.sh` around lines 96 - 100, In the nginx "location
/stub_status" block the allowed CIDR is overly broad (172.0.0.0/8); update the
allow directive to the narrower RFC1918 range 172.16.0.0/12 to match the
template security recommendation (modify the allow 172.0.0.0/8; line to allow
172.16.0.0/12;).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/deploy.yml:
- Line 54: The deploy workflow's source list omits the monitoring directory
referenced by the docker-compose Grafana volume, so update the "source" entry
that currently lists "docker-compose.yml,nginx/,scripts/,prometheus.yml" to also
include "monitoring/" (or specifically "monitoring/grafana/provisioning") so the
provisioning files are uploaded; alternatively, if the provisioning directory
doesn't exist yet, create the "monitoring/grafana/provisioning" directory and
add the required Grafana provisioning files before updating the source list so
the Grafana service's "./monitoring/grafana/provisioning" volume mount is
present on the target host.

In `@docker-compose.yml`:
- Around line 129-156: Prometheus and Grafana are exposed without
authentication; update the docker-compose service definitions for prometheus and
grafana to bind ports to localhost (change the ports mapping from "9090:9090"
and "3000:3000" to host-bound mappings like "127.0.0.1:9090:9090" and
"127.0.0.1:3000:3000"), add Grafana environment configuration to set a secure
admin password (use GF_SECURITY_ADMIN_PASSWORD in the grafana service), and
instead of exposing these services publicly recommend placing them behind an
authenticated reverse proxy (e.g., nginx) configured to handle TLS and access
control so prometheus and grafana services remain localhost-only.
- Line 151: docker-compose.yml references a host mount
./monitoring/grafana/provisioning which doesn't exist; either create the missing
directory with required provisioning files, add an initialization step that
creates ./monitoring/grafana/provisioning and places default provisioning files
before bringing Grafana up, or change the service's volume definition (the line
mounting ./monitoring/grafana/provisioning) to use a named volume or conditional
setup so Grafana won't fail on startup when the host path is absent.

In `@prometheus.yml`:
- Around line 6-11: Add the Prometheus endpoint to the public endpoints so
unauthenticated GET scrapes succeed: update the PublicEndpoint registry by
adding a new PublicEndpoint("/actuator/prometheus", HttpMethod.GET) (ensure
HttpMethod is imported/used consistently) so SecurityConfig's public-endpoint
checks will allow Prometheus to access /actuator/prometheus on blue/green
without authentication.

---

Nitpick comments:
In `@nginx/conf.d/nginx-green.conf.template`:
- Around line 13-17: 들여쓰기 불일치: location /stub_status 블록의 들여쓰기가 상위 location / 블록과
맞지 않으니 location /stub_status, stub_status on;, allow 172.0.0.0/8;, deny all;,
그리고 마지막 중괄호의 들여쓰기를 상위 location / 블록과 동일한 수준으로 정렬해 주세요; 각 중첩 블록은 프로젝트의 기존 스타일(예:
4스페이스 또는 탭)을 따라 통일된 들여쓰기를 사용하도록 수정하면 됩니다.
- Line 15: The nginx allow directive currently uses an overly broad CIDR "allow
172.0.0.0/8;": replace this with a more restrictive private-range CIDR (e.g.,
"allow 172.17.0.0/16;" or "allow 172.16.0.0/12;") or make it configurable via a
template variable, updating the allow directive in nginx-green.conf.template
accordingly to limit access to the expected Docker/private subnet.

In `@scripts/deploy.sh`:
- Around line 96-100: In the nginx "location /stub_status" block the allowed
CIDR is overly broad (172.0.0.0/8); update the allow directive to the narrower
RFC1918 range 172.16.0.0/12 to match the template security recommendation
(modify the allow 172.0.0.0/8; line to allow 172.16.0.0/12;).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 57934f65-fe09-4aaa-a940-d2ee972f0815

📥 Commits

Reviewing files that changed from the base of the PR and between 0c08bfd and 2bf8750.

📒 Files selected for processing (6)
  • .github/workflows/deploy.yml
  • docker-compose.yml
  • nginx/conf.d/nginx-blue.conf.template
  • nginx/conf.d/nginx-green.conf.template
  • prometheus.yml
  • scripts/deploy.sh

Comment thread .github/workflows/deploy.yml Outdated
username: ${{ secrets.EC2_USER }}
key: ${{ secrets.EC2_SSH_KEY }}
source: "docker-compose.yml,nginx/,scripts/"
source: "docker-compose.yml,nginx/,scripts/,prometheus.yml"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

monitoring/ 디렉토리가 전송 목록에서 누락되었습니다.

docker-compose.yml의 Grafana 서비스에서 ./monitoring/grafana/provisioning 볼륨을 마운트하고 있지만, 이 디렉토리가 EC2로 전송되지 않습니다. Grafana 컨테이너가 시작 시 실패하거나 프로비저닝 없이 기본 설정으로 실행됩니다.

🐛 monitoring 디렉토리 추가 제안
-          source: "docker-compose.yml,nginx/,scripts/,prometheus.yml"
+          source: "docker-compose.yml,nginx/,scripts/,prometheus.yml,monitoring/"

또는 monitoring/grafana/provisioning 디렉토리가 아직 생성되지 않았다면, 해당 디렉토리와 프로비저닝 파일을 먼저 추가해야 합니다.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
source: "docker-compose.yml,nginx/,scripts/,prometheus.yml"
source: "docker-compose.yml,nginx/,scripts/,prometheus.yml,monitoring/"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/deploy.yml at line 54, The deploy workflow's source list
omits the monitoring directory referenced by the docker-compose Grafana volume,
so update the "source" entry that currently lists
"docker-compose.yml,nginx/,scripts/,prometheus.yml" to also include
"monitoring/" (or specifically "monitoring/grafana/provisioning") so the
provisioning files are uploaded; alternatively, if the provisioning directory
doesn't exist yet, create the "monitoring/grafana/provisioning" directory and
add the required Grafana provisioning files before updating the source list so
the Grafana service's "./monitoring/grafana/provisioning" volume mount is
present on the target host.

Comment thread docker-compose.yml
Comment on lines +129 to +156
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- app-network
restart: always

grafana:
image: grafana/grafana
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning
restart: always
depends_on:
- prometheus
networks:
- app-network

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prometheus와 Grafana가 외부에 인증 없이 노출됩니다.

Prometheus (포트 9090)와 Grafana (포트 3000)가 공용 네트워크에 직접 노출되어 있습니다. 이는 다음과 같은 보안 위험이 있습니다:

  • Prometheus: 민감한 메트릭 데이터 노출, 타겟 정보 유출
  • Grafana: 기본 자격 증명(admin/admin)으로 접근 가능

운영 환경에서는 다음을 권장합니다:

  1. 포트를 127.0.0.1:9090:9090으로 바인딩하여 로컬 접근만 허용
  2. Nginx 리버스 프록시를 통해 인증 추가
  3. Grafana 환경 변수로 기본 비밀번호 변경 (GF_SECURITY_ADMIN_PASSWORD)
🔒 보안 강화 제안 (로컬 바인딩)
   prometheus:
     image: prom/prometheus
     container_name: prometheus
     ports:
-      - "9090:9090"
+      - "127.0.0.1:9090:9090"
     ...

   grafana:
     image: grafana/grafana
     container_name: grafana
     ports:
-      - "3000:3000"
+      - "127.0.0.1:3000:3000"
+    environment:
+      - GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
     ...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- "9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- app-network
restart: always
grafana:
image: grafana/grafana
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning
restart: always
depends_on:
- prometheus
networks:
- app-network
prometheus:
image: prom/prometheus
container_name: prometheus
ports:
- "127.0.0.1:9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
networks:
- app-network
restart: always
grafana:
image: grafana/grafana
container_name: grafana
ports:
- "127.0.0.1:3000:3000"
environment:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
volumes:
- grafana_data:/var/lib/grafana
- ./monitoring/grafana/provisioning:/etc/grafana/provisioning
restart: always
depends_on:
- prometheus
networks:
- app-network
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docker-compose.yml` around lines 129 - 156, Prometheus and Grafana are
exposed without authentication; update the docker-compose service definitions
for prometheus and grafana to bind ports to localhost (change the ports mapping
from "9090:9090" and "3000:3000" to host-bound mappings like
"127.0.0.1:9090:9090" and "127.0.0.1:3000:3000"), add Grafana environment
configuration to set a secure admin password (use GF_SECURITY_ADMIN_PASSWORD in
the grafana service), and instead of exposing these services publicly recommend
placing them behind an authenticated reverse proxy (e.g., nginx) configured to
handle TLS and access control so prometheus and grafana services remain
localhost-only.

Comment thread docker-compose.yml
Comment thread prometheus.yml
@byunhm02 byunhm02 requested a review from Kyoung-M1N March 19, 2026 12:17
@Kyoung-M1N

Copy link
Copy Markdown
Contributor

설정 자체에는 문제가 없는거 같아요!
Prometheus와 Grafana로 수집 및 시각화할 수치를 자동으로 대시보드에 올려주는 설정 파일을 추가하면 좋을 것 같아요!
그리고 혹시 가능하면 로컬에서 docker를 구동시켜서 확인해보는 것도 좋을 것 같아요!

@Kyoung-M1N Kyoung-M1N left a comment

Copy link
Copy Markdown
Contributor

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: 모니터링 설정

2 participants