NVIDIA Data Center GPU Manager (DCGM)

Questo documento descrive come configurare il tuo deployment Google Kubernetes Engine in modo da poter utilizzare Google Cloud Managed Service per Prometheus per raccogliere Gestore GPU NVIDIA Data Center. Questo documento illustra come:

  • Configura l'esportatore per DCGM per generare report sulle metriche.
  • Configura una risorsa PodMonitoring per Managed Service per Prometheus per raccogliere le metriche esportate.

Queste istruzioni sono valide solo se utilizzi raccolta gestita con Managed Service per Prometheus. Se utilizzi una raccolta di cui è stato eseguito il deployment autonomo, controlla repository di codice sorgente per l'esportatore DCGM per informazioni sull'installazione.

Queste istruzioni sono fornite a titolo di esempio e dovrebbero funzionare in la maggior parte degli ambienti Kubernetes. Per informazioni su un'offerta DCGM gestita, vedi Raccogliere e visualizzare le metriche DCGM.

Se hai difficoltà a installare un un'applicazione o un esportatore a causa di criteri restrittivi di sicurezza o dell'organizzazione, ti consigliamo di consultare la documentazione open source per ricevere assistenza.

Per informazioni su DCGM, vedi NVIDIA DCGM.

Prerequisiti

Per raccogliere metriche da DCGM utilizzando Managed Service per Prometheus e la raccolta gestita, il deployment deve devono soddisfare i seguenti requisiti:

  • Nel cluster deve essere in esecuzione la versione di Google Kubernetes Engine 1.21.4-gke.300 o versioni successive.
  • Devi eseguire Managed Service per Prometheus con la raccolta gestita abilitata. Per ulteriori informazioni, vedi Inizia a utilizzare la raccolta gestita.

  • Verifica di avere quota sufficiente per le GPU NVIDIA.

  • Per elencare i nodi GPU nel cluster GKE e i relativi tipi di GPU nel cluster pertinente, esegui questo comando:

    kubectl get nodes -l cloud.google.com/gke-gpu -o jsonpath='{range .items[*]}{@.metadata.name}{" "}{@.metadata.labels.cloud\.google\.com/gke-accelerator}{"\n"}{end}'
    
  • Tieni presente che potrebbe essere necessario installa un driver GPU NVIDIA compatibile sui nodi se è automatico l'installazione è stata disabilitata o non è supportata per la tua versione di GKE. Per verificare il plug-in del dispositivo GPU NVIDIA è in esecuzione, esegui questo comando:

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

Installare l'esportatore DCGM

Ti consigliamo di installare l'esportazione DCGM, DCGM-Exporter, utilizzando la seguente configurazione:

# 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.
Per verificare che DCGM Exporter stia emettendo metriche sugli endpoint previsti, procedi nel seguente modo:

  1. Configura il port forwarding con il seguente comando:

    kubectl -n gmp-public port-forward POD_NAME 9400
    
  2. Accedi all'endpoint localhost:9400/metrics utilizzando browser o l'utilità curl in un'altra sessione del terminale.

Puoi personalizzare la sezione ConfigMap in modo da selezionare le metriche GPU che emettono.

In alternativa, valuta la possibilità di utilizzare il grafico Helm ufficiale per installare DCGM Exporter.

Per applicare le modifiche alla configurazione da un file locale, esegui questo comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Puoi anche utilizza Terraform per gestire le configurazioni.

Definisci una risorsa PodMonitoring

Per il rilevamento del target, l'operatore Managed Service per Prometheus richiede una risorsa PodMonitoring che corrisponda Esportatore DCGM nello stesso spazio dei nomi.

Puoi utilizzare la seguente configurazione di 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: []

Per applicare le modifiche alla configurazione da un file locale, esegui questo comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Puoi anche utilizza Terraform per gestire le configurazioni.

Verificare la configurazione

Puoi utilizzare Metrics Explorer per verificare di aver configurato correttamente Esportatore DCGM. Potrebbero essere necessari uno o due minuti Cloud Monitoring per importare le tue metriche.

Per verificare che le metriche siano importate:

  1. Nella console Google Cloud, vai alla Pagina Esplora metriche:

    Vai a Esplora metriche

    Se utilizzi la barra di ricerca per trovare questa pagina, seleziona il risultato con il sottotitolo Monitoraggio.

  2. Nella barra degli strumenti della riquadro Query Builder, seleziona il pulsante con  MQL o  PromQL.
  3. Verifica che PromQL sia selezionato con l'opzione Lingua. Il pulsante di attivazione/disattivazione della lingua si trova nella stessa barra degli strumenti. consente di formattare la query.
  4. Inserisci ed esegui questa query:
    DCGM_FI_DEV_GPU_UTIL{cluster="CLUSTER_NAME", namespace="gmp-public"}
    

Risoluzione dei problemi

Per informazioni sulla risoluzione dei problemi di importazione delle metriche, consulta Problemi con la raccolta dagli esportatori in Risoluzione dei problemi lato importazione.