NVIDIA Data Center GPU Manager (DCGM)

Questo documento descrive come configurare il deployment di Google Kubernetes Engine in modo da poter utilizzare Google Cloud Managed Service per Prometheus per raccogliere le metriche da NVIDIA Data Center GPU Manager. Questo documento mostra come eseguire le seguenti operazioni:

  • Configurare l'esportatore per DCGM in modo che riporti le metriche.

Queste istruzioni si applicano solo se utilizzi la raccolta gestita con Managed Service per Prometheus. Se utilizzi la raccolta con deployment autonomo, consulta il repository di origine per DCGM Exporter per informazioni sull'installazione.

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

Se hai difficoltà a installare un'applicazione o un esportatore a causa di policy organizzative o di sicurezza restrittive, ti consigliamo di consultare la documentazione open source per ricevere assistenza.

Per informazioni su NVIDIA Data Center GPU Manager, consulta NVIDIA DCGM.

Prerequisiti

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

  • Verifica di avere una quota sufficiente per le GPU NVIDIA.

  • Per enumerare i nodi GPU nel cluster GKE e i relativi tipi di GPU nel cluster pertinente, esegui il seguente 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 potresti dover installare un driver GPU NVIDIA compatibile sui nodi se l'installazione automatica è stata disabilitata o non è supportata per la tua versione di GKE. Per verificare che il plug-in del dispositivo GPU NVIDIA sia in esecuzione, esegui il seguente comando:

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

Installare l'esportatore DCGM

Ti consigliamo di installare l'esportatore 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 come segue:

  1. Configura l'inoltro della porta con il seguente comando:

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

Puoi personalizzare la sezione ConfigMap per selezionare le metriche GPU da emettere.

In alternativa, puoi utilizzare il grafico Helm ufficiale per installare DCGM Exporter.

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

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Puoi anche utilizzare Terraform per gestire le configurazioni.

Definire una risorsa PodMonitoring

Per l'individuazione dei target, l'operatore Managed Service per Prometheus richiede una risorsa PodMonitoring che corrisponda a DCGM Exporter nello stesso spazio dei nomi.

Puoi utilizzare la seguente configurazione 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 il seguente comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Puoi anche utilizzare Terraform per gestire le configurazioni.

Verificare la configurazione

Puoi utilizzare Metrics Explorer per verificare di aver configurato correttamente DCGM Exporter. Cloud Monitoring potrebbe richiedere uno o due minuti per inserire le metriche.

Per verificare che le metriche siano state inserite, procedi come segue:

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

    Vai a Esplora metriche

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

  2. Nella barra degli strumenti del riquadro del generatore di query, seleziona il pulsante il cui nome è  PromQL.
  3. Inserisci ed esegui la seguente query:
    DCGM_FI_DEV_GPU_UTIL{cluster="CLUSTER_NAME", namespace="gmp-public"}
    

Risoluzione dei problemi

Per informazioni sulla risoluzione dei problemi di inserimento delle metriche, consulta Problemi con la raccolta dagli esportatori in Risoluzione dei problemi relativi all'inserimento.