NVIDIA Data Center GPU Manager (DCGM)

במאמר הזה מוסבר איך להגדיר את הפריסה של Google Kubernetes Engine כדי שתוכלו להשתמש בשירות מנוהל של Google Cloud ל-Prometheus כדי לאסוף מדדים מ-NVIDIA Data Center GPU Manager. במאמר הזה מוסבר איך:

  • מגדירים את הכלי לייצוא של DCGM כדי לדווח על מדדים.

ההוראות האלה רלוונטיות רק אם אתם משתמשים ב אוסף מנוהל עם השירות המנוהל ל-Prometheus. אם אתם משתמשים באיסוף שמוטמע באופן עצמאי, תוכלו למצוא מידע על ההתקנה במאגר המקור של DCGM Exporter.

ההוראות האלה הן דוגמה, והן אמורות לפעול ברוב סביבות Kubernetes. מידע על מוצר DCGM מנוהל זמין במאמר איסוף והצגה של מדדי DCGM.

אם נתקלתם בבעיה בהתקנת אפליקציה או כלי לייצוא בגלל מדיניות אבטחה או מדיניות ארגונית מגבילה, מומלץ לעיין במסמכי קוד פתוח לקבלת תמיכה.

מידע על NVIDIA Data Center GPU Manager זמין במאמר בנושא NVIDIA DCGM.

דרישות מוקדמות

כדי לאסוף מדדים מ-DCGM באמצעות שירות מנוהל ל-Prometheus ואיסוף מנוהל, הפריסה צריכה לעמוד בדרישות הבאות:

  • האשכול צריך להריץ את Google Kubernetes Engine בגרסה ‎1.28.15-gke.2475000 ואילך.
  • צריך להפעיל את השירות המנוהל ל-Prometheus עם איסוף מנוהל. מידע נוסף זמין במאמר תחילת השימוש באוסף מנוהל.

  • מוודאים שיש לכם מכסה מספקת למעבדי NVIDIA GPU.

  • כדי למנות את צמתי ה-GPU באשכול GKE ואת סוגי ה-GPU באשכול הרלוונטי, מריצים את הפקודה הבאה:

    kubectl get nodes -l cloud.google.com/gke-gpu -o jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.metadata.labels.cloud\.google\.com/gke-accelerator}{"\n"}{end}'
    
  • שימו לב: יכול להיות שתצטרכו להתקין דרייבר תואם של NVIDIA GPU בצמתים אם ההתקנה האוטומטית הושבתה או לא נתמכת בגרסת ה-GKE שלכם. כדי לוודא שהפלאגין של מכשיר ה-GPU של NVIDIA פועל, מריצים את הפקודה הבאה:

    kubectl get pods -n kube-system | grep nvidia-gpu-device-plugin
    

התקנה של DCGM exporter

מומלץ להתקין את כלי הייצוא של DCGM‏, DCGM-Exporter, באמצעות ההגדרה הבאה:

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nvidia-dcgm
  namespace: gmp-public
  labels:
    app: nvidia-dcgm
spec:
  selector:
    matchLabels:
      app: nvidia-dcgm
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        name: nvidia-dcgm
        app: nvidia-dcgm
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cloud.google.com/gke-accelerator
                operator: Exists
      tolerations:
      - operator: "Exists"
      volumes:
      - name: nvidia-install-dir-host
        hostPath:
          path: /home/kubernetes/bin/nvidia
          type: Directory
      containers:
      - image: "nvcr.io/nvidia/cloud-native/dcgm:3.3.0-1-ubuntu22.04"
        command: ["nv-hostengine", "-n", "-b", "ALL"]
        ports:
        - containerPort: 5555
          hostPort: 5555
        name: nvidia-dcgm
        securityContext:
          privileged: true
        volumeMounts:
        - name: nvidia-install-dir-host
          mountPath: /usr/local/nvidia
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nvidia-dcgm-exporter
  namespace: gmp-public
  labels:
    app.kubernetes.io/name: nvidia-dcgm-exporter
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: nvidia-dcgm-exporter
  updateStrategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/name: nvidia-dcgm-exporter
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: cloud.google.com/gke-accelerator
                operator: Exists
      tolerations:
      - operator: "Exists"
      volumes:
      - name: nvidia-dcgm-exporter-metrics
        configMap:
          name: nvidia-dcgm-exporter-metrics
      - name: nvidia-install-dir-host
        hostPath:
          path: /home/kubernetes/bin/nvidia
          type: Directory
      - name: pod-resources
        hostPath:
          path: /var/lib/kubelet/pod-resources
      containers:
      - name: nvidia-dcgm-exporter
        image: nvcr.io/nvidia/k8s/dcgm-exporter:3.3.0-3.2.0-ubuntu22.04
        command: ["/bin/bash", "-c"]
        args:
        - hostname $NODE_NAME; dcgm-exporter --remote-hostengine-info $(NODE_IP) --collectors /etc/dcgm-exporter/counters.csv
        ports:
        - name: metrics
          containerPort: 9400
        securityContext:
          privileged: true
        env:
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: "DCGM_EXPORTER_KUBERNETES_GPU_ID_TYPE"
          value: "device-name"
        - name: LD_LIBRARY_PATH
          value: /usr/local/nvidia/lib64
        - name: NODE_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        - name: DCGM_EXPORTER_KUBERNETES
          value: 'true'
        - name: DCGM_EXPORTER_LISTEN
          value: ':9400'
        volumeMounts:
        - name: nvidia-dcgm-exporter-metrics
          mountPath: "/etc/dcgm-exporter"
          readOnly: true
        - name: nvidia-install-dir-host
          mountPath: /usr/local/nvidia
        - name: pod-resources
          mountPath: /var/lib/kubelet/pod-resources
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nvidia-dcgm-exporter-metrics
  namespace: gmp-public
data:
  counters.csv: |
    # Utilization (the sample period varies depending on the product),,
    DCGM_FI_DEV_GPU_UTIL, gauge, GPU utilization (in %).
    DCGM_FI_DEV_MEM_COPY_UTIL, gauge, Memory utilization (in %).

    # Temperature and power usage,,
    DCGM_FI_DEV_GPU_TEMP, gauge, Current temperature readings for the device in degrees C.
    DCGM_FI_DEV_MEMORY_TEMP, gauge, Memory temperature for the device.
    DCGM_FI_DEV_POWER_USAGE, gauge, Power usage for the device in Watts.

    # Utilization of IP blocks,,
    DCGM_FI_PROF_SM_ACTIVE, gauge, The ratio of cycles an SM has at least 1 warp assigned
    DCGM_FI_PROF_SM_OCCUPANCY, gauge, The fraction of resident warps on a multiprocessor
    DCGM_FI_PROF_PIPE_TENSOR_ACTIVE, gauge, The ratio of cycles the tensor (HMMA) pipe is active (off the peak sustained elapsed cycles)
    DCGM_FI_PROF_PIPE_FP64_ACTIVE, gauge, The fraction of cycles the FP64 (double precision) pipe was active.
    DCGM_FI_PROF_PIPE_FP32_ACTIVE, gauge, The fraction of cycles the FP32 (single precision) pipe was active.
    DCGM_FI_PROF_PIPE_FP16_ACTIVE, gauge, The fraction of cycles the FP16 (half precision) pipe was active.

    # Memory usage,,
    DCGM_FI_DEV_FB_FREE, gauge, Framebuffer memory free (in MiB).
    DCGM_FI_DEV_FB_USED, gauge, Framebuffer memory used (in MiB).
    DCGM_FI_DEV_FB_TOTAL, gauge, Total Frame Buffer of the GPU in MB.

    # PCIE,,
    DCGM_FI_PROF_PCIE_TX_BYTES, gauge, Total number of bytes transmitted through PCIe TX
    DCGM_FI_PROF_PCIE_RX_BYTES, gauge, Total number of bytes received through PCIe RX

    # NVLink,,
    DCGM_FI_PROF_NVLINK_TX_BYTES, gauge, The number of bytes of active NvLink tx (transmit) data including both header and payload.
    DCGM_FI_PROF_NVLINK_RX_BYTES, gauge, The number of bytes of active NvLink rx (read) data including both header and payload.
כדי לוודא ש-DCGM Exporter שולח מדדים לנקודות הקצה הצפויות, פועלים לפי השלבים הבאים:

  1. מגדירים העברה ליציאה אחרת באמצעות הפקודה הבאה:

    kubectl -n gmp-public port-forward POD_NAME 9400
    
  2. אפשר לגשת לנקודת הקצה localhost:9400/metrics באמצעות הדפדפן או כלי השירות curl בסשן טרמינל אחר.

אפשר להתאים אישית את הקטע ConfigMap כדי לבחור אילו מדדי GPU לשלוח.

אפשר גם להשתמש בתרשים Helm הרשמי כדי להתקין את DCGM Exporter.

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

אפשר גם להשתמש ב-Terraform כדי לנהל את ההגדרות.

הגדרה של משאב PodMonitoring

כדי לגלות את היעד, ל-שירות מנוהל ל-Prometheus Operator נדרש משאב PodMonitoring שתואם ל-DCGM Exporter באותו מרחב שמות.

אפשר להשתמש בהגדרה הבאה של PodMonitoring:

# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

apiVersion: monitoring.googleapis.com/v1
kind: ClusterPodMonitoring
metadata:
  name: nvidia-dcgm-exporter
  labels:
    app.kubernetes.io/name: nvidia-dcgm-exporter
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: nvidia-dcgm-exporter
  endpoints:
  - port: metrics
    interval: 30s
  targetLabels:
    metadata: []

כדי להחיל שינויים בתצורה מקובץ מקומי, מריצים את הפקודה הבאה:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

אפשר גם להשתמש ב-Terraform כדי לנהל את ההגדרות.

אימות ההגדרה

אתם יכולים להשתמש ב-Metrics Explorer כדי לוודא שהגדרתם את DCGM Exporter בצורה נכונה. יכול להיות שיחלפו דקה או שתיים עד שמערכת Cloud Monitoring תעבד את המדדים.

כדי לוודא שהמדדים נאספים, מבצעים את הפעולות הבאות:

  1. במסוף Google Cloud , עוברים לדף  Metrics explorer:

    כניסה אל Metrics Explorer

    אם משתמשים בסרגל החיפוש כדי למצוא את הדף הזה, בוחרים בתוצאה שכותרת המשנה שלה היא Monitoring.

  2. בסרגל הכלים של חלונית הכלי ליצירת שאילתות, לוחצים על הלחצן ששמו הוא  MQL או  PromQL.
  3. מוודאים שהאפשרות PromQL נבחרה במתג שפה. המתג לשפה נמצא באותו סרגל כלים שבו אפשר לעצב את השאילתה.
  4. מזינים ומריצים את השאילתה הבאה:
    DCGM_FI_DEV_GPU_UTIL{cluster="CLUSTER_NAME", namespace="gmp-public"}
    

פתרון בעיות

מידע על פתרון בעיות בהוספת מדדים זמין במאמר פתרון בעיות שקשורות להוספה, בקטע בעיות באיסוף נתונים ממייצאים.