Skip to content

[FEATURE] GPU 정보 수집을 위한 모니터링 대상 변경#33

Merged
youyeon11 merged 5 commits intodevelopfrom
feat/add-exporter-32
Oct 3, 2025
Merged

[FEATURE] GPU 정보 수집을 위한 모니터링 대상 변경#33
youyeon11 merged 5 commits intodevelopfrom
feat/add-exporter-32

Conversation

@youyeon11
Copy link
Contributor

📌 작업 목적

GPU 메트릭을 prometheus에서 수집할 수 있도록 dcgm-exporter를 컨테이너로 추가했습니다.


🗂 작업 유형

  • 기능 추가 (Feature)
  • 버그 수정 (Bug Fix)
  • 리팩터링 (Refactor)
  • 성능 개선 (Performance)
  • 테스트 추가/수정 (Test)
  • 빌드/배포/환경 설정 (Chore)
  • 문서 수정 (Docs)

🔨 주요 작업 내용

  • 기존에는 FastAPI에 대한 메트릭을 수집하면 된다고 생각했으나, fast api 서버는 task가 들어올 때만 작동하므로 서버의 GPU 정보만 수집하면 된다고 생각하여 변경하였습니다. (Fast API의 대시보드에는 주로 loki도 추가하는데 이러면 서버에 불필요한 부하 갈 수도 있어서 추가 안함)
  • Prometheus → dcgm-exporter → NVIDIA DCGM 라이브러리 → GPU 드라이버 로 수집

  • dcgm-exporter 추가
  dcgm-exporter:
      image: nvcr.io/nvidia/k8s/dcgm-exporter:latest
      container_name: dcgm-exporter
      ports:
        - "9400:9400"
      deploy:
        resources:
          reservations:
            devices:
              - driver: nvidia
                count: all
                capabilities: [gpu]
      environment:
        - NVIDIA_VISIBLE_DEVICES=all
        - NVIDIA_DRIVER_CAPABILITIES=utility,compute
      restart: unless-stopped
      networks:
        - mynetwork
      healthcheck:
        test: [ "CMD", "wget", "-qO-", "http://localhost:9400/metrics" ]
        interval: 30s
        timeout: 5s
        retries: 5
  • GPU 서버 모니터링을 위하여 GPU에 대한 정보 수집 후 공유 대시보드를 사용했습니다
  • 사용한 공유 대시보드 ID : 12239

  • prometheus 수집 대상 fast api 아예 배제하고 dcgm-exporter 수집하도록 job 추가했습니다
  - job_name: 'dcgm'
    scrape_interval: 15s
    static_configs:
      - targets: ['dcgm-exporter:9400']
        labels:
          exporter: 'dcgm'

🧪 테스트 결과

image

📎 관련 이슈


💬 논의 및 고민한 점

구현 과정에서 논의하거나 고민했던 부분 작성


@gemini-code-assist
Copy link

Summary of Changes

Hello @youyeon11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 Pull Request는 시스템 모니터링 전략을 개선하여 FastAPI 애플리케이션의 메트릭 수집 대신 GPU의 성능 및 상태 정보를 직접 수집하는 데 중점을 둡니다. 이는 FastAPI 서버가 태스크가 있을 때만 작동하므로, 서버의 GPU 정보만 수집하는 것이 더 효율적이라는 판단에 따른 것입니다. dcgm-exporter를 도입하여 Prometheus를 통해 GPU 메트릭을 효과적으로 모니터링할 수 있도록 환경을 설정했습니다.

Highlights

  • GPU 모니터링 전환: 기존 FastAPI 기반의 메트릭 수집 방식에서 GPU 정보 수집을 위해 dcgm-exporter를 활용하는 방식으로 모니터링 대상을 변경했습니다.
  • dcgm-exporter 추가: deployment/docker-compose.monitoring.yml 파일에 dcgm-exporter 서비스를 추가하여 NVIDIA GPU 메트릭을 수집할 수 있도록 설정했습니다.
  • Prometheus 설정 업데이트: Prometheus 설정(deployment/prometheus.yml)에서 FastAPI 관련 스크랩 작업을 제거하고, dcgm-exporter로부터 GPU 메트릭을 수집하는 새로운 작업을 추가했습니다.
  • FastAPI 메트릭 의존성 제거: app/main.py에서 prometheus_fastapi_instrumentator 관련 코드를 제거하고, requirements.txt에서 해당 라이브러리 및 prometheus-client 의존성을 삭제했습니다.
  • Docker Compose 네트워크 설정: deployment/docker-compose.yml에서 app-blueapp-green 서비스에 mynetwork를 추가하고, 전역 mynetwork 정의를 포함하여 서비스 간 통신을 용이하게 했습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@youyeon11
Copy link
Contributor Author

🤖 Gemini 코드 리뷰 결과

안녕하세요! GPU 모니터링 대상 변경 PR 잘 확인했습니다. FastAPI 애플리케이션에서 직접 메트릭을 수집하는 방식에서, 하드웨어 레벨의 정보를 직접 얻을 수 있는 dcgm-exporter를 도입한 것은 매우 정확하고 올바른 방향의 개선이라고 생각합니다. 덕분에 더 신뢰성 높은 GPU 모니터링이 가능해지겠네요.

전반적인 변경 내용은 훌륭하며, 몇 가지 추가 개선점을 제안드리고자 리뷰를 남깁니다.

1) PR 의도 요약

이 PR은 기존의 FastAPI 애플리케이션 레벨의 간헐적 메트릭 수집 방식을 개선하기 위해 제출되었습니다. Docker Compose 환경에 NVIDIA의 dcgm-exporter 컨테이너를 추가하여, Prometheus가 GPU 하드웨어로부터 직접적이고 지속적인 메트릭을 수집하도록 변경하는 것을 목표로 합니다. 이를 통해 더 정확하고 안정적인 GPU 모니터링 환경을 구축하고, 불필요해진 FastAPI 관련 모니터링 의존성을 제거하여 애플리케이션을 경량화했습니다.

2) 전반적 평가 (품질/가독성/테스트/아키텍처)

  • 컨벤션: YAML과 Python 코드 모두 표준 컨벤션을 잘 따르고 있어 가독성이 좋습니다.
  • 아키텍처: 모니터링 책임을 애플리케이션에서 분리하여 전용 exporter를 사용하도록 변경한 것은 아키텍처 측면에서 매우 훌륭한 결정입니다. 의존성 방향과 모듈 경계가 명확해졌습니다.
  • 테스트: Grafana 대시보드 스크린샷을 통해 기능이 정상 동작함을 시각적으로 잘 검증해 주셨습니다. 인프라 변경의 특성상 자동화된 테스트는 어렵지만, 수동 검증이 충분히 이루어진 것으로 보입니다.

3) 우선순위별 피드백 목록

[P2] Docker 이미지에 :latest 태그 사용 지양

  • 파일/위치: deployment/docker-compose.monitoring.yml:30

  • 근거(왜 문제인지): :latest 태그는 빌드 시점에 따라 가리키는 이미지 버전이 계속 변경됩니다. 이로 인해 개발 환경과 운영 환경의 dcgm-exporter 버전이 달라지거나, 향후 예고 없이 새로운 버전을 pull 하면서 호환성 문제가 발생할 수 있습니다.

  • 영향(버그/보안/성능/유지보수 등): 배포의 재현성(Reproducibility)과 안정성이 저하됩니다. 특정 버전에서만 발생하는 버그를 추적하기 어려워지고, 의도치 않은 브레이킹 체인지가 포함될 수 있습니다.

  • 제안(구체적 조치): 안정적인 운영을 위해 특정 버전을 명시적으로 지정하는 것을 강력히 권장합니다. NVIDIA NGC 카탈로그에서 안정적인 버전을 확인하고 고정해주세요.

    # deployment/docker-compose.monitoring.yml
    
    # 제안
      dcgm-exporter:
          # 예시: nvcr.io/nvidia/k8s/dcgm-exporter:3.3.5-3.3.0-ubuntu22.04 와 같이 구체적인 버전 태그 사용
          image: nvcr.io/nvidia/k8s/dcgm-exporter:3.3.5-3.3.0-ubuntu22.04
          container_name: dcgm-exporter
          # ...

[P3] Prometheus 설정의 하드코딩된 타겟 주소 개선

  • 파일/위치: deployment/prometheus.yml:19, 23

  • 근거(왜 개선인지): 기존에 ${REMOTE_HOST} 환경 변수를 사용하던 부분들이 127.0.0.1로 하드코딩되었습니다. Prometheus가 자기 자신을 스크래핑하는 경우 일반적으로 문제가 없지만, 설정의 유연성을 떨어뜨릴 수 있습니다.

  • 영향(유지보수): 향후 다른 환경(예: 원격 서버의 node-exporter 모니터링)에서 이 설정을 재사용할 때 혼란을 주거나 직접 수정해야 하는 번거로움이 생길 수 있습니다.

  • 제안: 환경 변수를 사용하되, 기본값을 지정하는 방식으로 유연성을 유지하는 것이 좋습니다. 이렇게 하면 별도 설정이 없을 때는 localhost로 동작하고 필요시 외부에서 주입할 수 있습니다.

    # deployment/prometheus.yml
    
    # 제안
      - targets: ['${PROMETHEUS_HOST:-127.0.0.1}:9090']
        labels:
          service: 'monitor-1'
    # ...
    # node-exporter 등 다른 타겟에도 유사하게 적용 가능

[P4] Healthcheck 명령어의 견고성 확보

  • 파일/위치: deployment/docker-compose.monitoring.yml:45

  • 근거(왜 개선인지): healthcheckwget을 사용하셨는데, 일부 경량화된 컨테이너 이미지에는 wget이 포함되지 않는 경우가 있습니다. curl이 좀 더 보편적으로 사용되며, 실패 시 명시적으로 non-zero exit code를 반환하는 옵션(-f)이 있어 healthcheck에 더 적합합니다.

  • 영향(안정성): wget이 없는 이미지를 사용할 경우, 컨테이너가 정상임에도 불구하고 healthcheck가 계속 실패하여 불필요한 재시작을 유발할 수 있습니다.

  • 제안: wget 대신 curl을 사용하고, 실패 시 에러 코드를 반환하도록 -f 옵션을 추가하는 것을 고려해 보세요.

    # deployment/docker-compose.monitoring.yml
    
    # 제안
      healthcheck:
        test: [ "CMD", "curl", "-f", "http://localhost:9400/metrics", "||", "exit 1" ]
        interval: 30s
        timeout: 5s
        retries: 5

[P5] PR과 무관한 파일 변경 사항 확인

  • 파일/위치: deployment/generate_review.py:62
  • 근거: Gemini 프롬프트의 문구가 당신은에서 너는으로 변경되었습니다. 이는 이번 PR의 핵심 기능인 'GPU 모니터링 대상 변경'과는 관련이 없어 보입니다.
  • 영향: 영향은 거의 없지만, 커밋 히스토리를 깔끔하게 유지하고 PR의 범위를 명확하게 하기 위해 관련 없는 변경은 제외하는 것이 좋습니다.
  • 제안: 이 변경이 의도된 것이 아니라면 원복하여 이번 PR에서는 제외하는 것을 추천합니다.

전반적으로 GPU 모니터링 아키텍처를 올바른 방향으로 개선하는 훌륭한 PR이라고 생각합니다. 제안 드린 몇 가지 사항들을 검토해 보시면 더욱 안정적이고 유연한 시스템을 만드는 데 도움이 될 것입니다.

수고 많으셨습니다! 👍

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

이번 PR은 Prometheus를 사용한 GPU 메트릭 수집을 위해 dcgm-exporter를 도입하고, 기존 FastAPI 메트릭 수집을 제거하는 변경사항을 담고 있습니다. 전반적으로 PR의 목적에 맞게 변경이 잘 이루어졌습니다. 몇 가지 개선점을 제안드립니다. docker-compose.monitoring.yml 파일에서 dcgm-exporter의 Docker 이미지 태그를 latest 대신 특정 버전으로 고정하여 안정성을 높이는 것을 권장합니다. 또한, dcgm-exporter 컨테이너의 healthcheckwget이 없어 실패할 가능성이 높으므로 제거하는 것이 좋습니다. 마지막으로, docker-compose.ymldocker-compose.monitoring.yml에 중복으로 정의된 네트워크를 하나로 통합하여 관리 효율성을 높이는 방안을 제안했습니다. 코드 리뷰 내용을 확인하시고 반영 부탁드립니다.

- mynetwork

dcgm-exporter:
image: nvcr.io/nvidia/k8s/dcgm-exporter:latest

Choose a reason for hiding this comment

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

high

프로덕션 환경의 안정성을 위해 Docker 이미지에 latest 태그를 사용하는 것을 지양해야 합니다. latest 태그는 예기치 않은 변경사항을 가져올 수 있으므로, 특정 버전으로 고정하는 것이 좋습니다. 예를 들어 3.3.5-3.1.8-ubuntu22.04와 같은 구체적인 버전을 명시해주세요.

      image: nvcr.io/nvidia/k8s/dcgm-exporter:3.3.5-3.1.8-ubuntu22.04

Comment on lines 49 to 53
healthcheck:
test: [ "CMD", "wget", "-qO-", "http://localhost:9400/metrics" ]
interval: 30s
timeout: 5s
retries: 5

Choose a reason for hiding this comment

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

high

nvcr.io/nvidia/k8s/dcgm-exporter 이미지는 scratch를 기반으로 한 최소한의 이미지이므로 wget과 같은 쉘 유틸리티가 포함되어 있지 않습니다. 따라서 현재 설정된 healthcheck는 실패하게 되어 컨테이너가 비정상 상태로 간주될 수 있습니다. 이 healthcheck를 제거하는 것이 좋습니다.

Comment on lines +36 to +38
networks:
mynetwork:
driver: bridge No newline at end of file

Choose a reason for hiding this comment

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

medium

mynetwork 네트워크가 docker-compose.monitoring.yml 파일과 docker-compose.yml 파일 양쪽 모두에 정의되어 있습니다. 여러 compose 파일에서 동일한 네트워크를 사용하는 경우, 한 파일에서만 네트워크를 정의하고 다른 파일에서는 external: true 옵션을 사용하여 외부 네트워크로 참조하는 것이 좋습니다. 이렇게 하면 중복을 피하고 설정을 더 명확하게 관리할 수 있습니다. 예를 들어, 이 파일(docker-compose.yml)에 네트워크 정의를 남겨두고, docker-compose.monitoring.yml에서는 mynetwork를 외부 네트워크로 참조하도록 수정할 수 있습니다.

@youyeon11 youyeon11 merged commit 1f5f292 into develop Oct 3, 2025
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.

1 participant