콘텐츠로 이동

Prometheus로 NPU 메트릭 수집하기

NPU Operator가 배포한 Metrics Exporter를 Prometheus에 연결하고 노드별 NPU 온도를 조회합니다.

이 튜토리얼은 Metrics Exporter 구성을 기준으로 합니다. Operator가 아직 설치되어 있지 않다면 먼저 NPU Operator 설치 절차를 진행합니다.

Prometheus Operator가 설치된 클러스터에서 시작합니다. 설치 방법은 kube-prometheus-stack 설치 가이드에서 확인할 수 있습니다.

1. 수집 대상 연결하기

Prometheus가 ServiceMonitor를 선택할 때 사용하는 레이블 조건과 Exporter Service의 포트 이름을 확인합니다.

$ kubectl get prometheus -n monitoring kube-prometheus-stack-prometheus \
  -o jsonpath='{.spec.serviceMonitorSelector.matchLabels}{"\n"}'
{"release":"kube-prometheus-stack"}

$ kubectl get service -n rbln-system rbln-metrics-exporter-service \
  -o jsonpath='{.spec.ports[0].name}{"\t"}{.spec.ports[0].port}{"\n"}'
http    9090

ServiceMonitor의 metadata.labels는 Prometheus의 selector 조건에 맞아야 합니다. spec.selector에는 Exporter Service의 레이블을 지정합니다. endpoints.port에는 숫자가 아닌 Service의 포트 이름 http를 지정합니다.

kubectl apply -f - <<'EOF'
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: npu-tutorial-metrics
  namespace: monitoring
  labels:
    release: kube-prometheus-stack
spec:
  namespaceSelector:
    matchNames: [rbln-system]
  selector:
    matchLabels:
      app.kubernetes.io/component: metrics-exporter
      app.kubernetes.io/name: rbln-npu-operator
  endpoints:
  - port: http
    path: /metrics
    interval: 15s
EOF

2. 메트릭 조회하기

한 터미널에서 Prometheus 포트 포워딩을 실행합니다.

kubectl port-forward -n monitoring svc/kube-prometheus-stack-prometheus 19090:9090

포트 포워딩을 실행한 터미널은 그대로 두고 다른 터미널에서 메트릭을 조회합니다. 결과가 없으면 Prometheus가 새 수집 대상을 인식할 때까지 잠시 기다렸다가 다시 조회합니다.

메트릭 수집 상태
$ curl -sS --get http://127.0.0.1:19090/api/v1/query \
  --data-urlencode 'query=up{service="rbln-metrics-exporter-service"}' | \
  jq -r '.data.result[] | [.metric.pod, .value[1]] | @tsv'
rbln-metrics-exporter-k6rs8 1
rbln-metrics-exporter-frs5x 1
온도가 수집된 NPU 수
$ curl -sS --get http://127.0.0.1:19090/api/v1/query \
  --data-urlencode 'query=count by (hostname) (rbln_npu_temperature)' | \
  jq -r '.data.result[] | [.metric.hostname, .value[1]] | @tsv'
node-rebel100   1
노드별 평균 온도 (°C)
$ curl -sS --get http://127.0.0.1:19090/api/v1/query \
  --data-urlencode 'query=avg by (hostname) (rbln_npu_temperature)' | \
  jq -r '.data.result[] | [.metric.hostname, .value[1]] | @tsv'
node-rebel100   42
온도가 수집된 NPU 수
$ curl -sS --get http://127.0.0.1:19090/api/v1/query \
  --data-urlencode 'query=count by (hostname) (rbln_npu_temperature)' | \
  jq -r '.data.result[] | [.metric.hostname, .value[1]] | @tsv'
node-atom   16
노드별 평균 온도 (°C)
$ curl -sS --get http://127.0.0.1:19090/api/v1/query \
  --data-urlencode 'query=avg by (hostname) (rbln_npu_temperature)' | \
  jq -r '.data.result[] | [.metric.hostname, .value[1]] | @tsv'
node-atom   28.375

각 Exporter의 up이 1이고 각 노드의 NPU 온도가 수집되면 성공입니다. 장치 수와 온도는 환경에 따라 달라집니다.

메트릭이 조회되지 않는 경우

ServiceMonitor의 레이블, 네임스페이스, 포트 이름을 확인합니다. Prometheus의 Targets 화면에 오류가 있는지도 확인합니다.

정리

포트 포워딩을 실행한 터미널에서 Ctrl+C를 누른 뒤 ServiceMonitor를 삭제합니다.

kubectl delete servicemonitor -n monitoring npu-tutorial-metrics