Gerenciador de GPU do data center da NVIDIA (DCGM)

Neste documento, descrevemos como configurar a implantação do Google Kubernetes Engine para que você possa usar o Google Cloud Managed Service para Prometheus para coletar métricas do NVIDIA Data Center GPU Manager. Esta página mostra como fazer o seguinte:

  • Configure o exportador do DCGM para gerar relatórios de métricas.
  • Configurar um recurso PodMonitoring para o serviço gerenciado para Prometheus a fim de coletar as métricas exportadas.

Estas instruções se aplicam somente ao usar a coleção gerenciada com o serviço gerenciado para Prometheus. Se você estiver usando a coleção autoimplantada, consulte o repositório de origem do exportador do DCGM para ver informações da instalação.

Estas instruções são um exemplo e devem funcionar na maioria dos ambientes do Kubernetes. Se você estiver com problemas para instalar um aplicativo ou exportador devido a políticas restritivas de segurança ou da organização, recomendamos consultar a documentação de código aberto para receber suporte.

Para mais informações sobre o DCGM, consulte NVIDIA DCGM.

Pré-requisitos

Para coletar métricas do DCGM usando o Managed Service para Prometheus e a coleção gerenciada, sua implantação precisa atender aos seguintes requisitos:

  • Seu cluster precisa executar a versão 1.21.4-gke.300 ou posterior do Google Kubernetes Engine.
  • É necessário executar o Managed Service para Prometheus com a coleta gerenciada ativada. Para mais informações, consulte Começar a usar a coleta gerenciada.

  • Verifique se você tem uma cota suficiente para GPUs NVIDIA.

  • Para enumerar os nós da GPU no cluster do GKE e os respectivos tipos no cluster relevante, execute o seguinte 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}'
    
  • Se a instalação automática estiver desativada ou não for compatível com sua versão do GKE, talvez seja necessário instalar um driver da GPU NVIDIA compatível nos nós. Para verificar se o plug-in do dispositivo GPU NVIDIA está em execução, execute o seguinte comando:

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

Instalar o exportador do DCGM

Recomendamos que você instale o exportador DCGM, DCGM-Exporter usando a seguinte configuração:

# 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
      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
      - 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.
Para verificar se o exportador do DCGM está emitindo métricas nos endpoints esperados, faça o seguinte:

  1. Configure o encaminhamento de portas com o seguinte comando:

    kubectl -n gmp-public port-forward POD_NAME 9400
    
  2. Acesse o endpoint localhost:9400/metrics usando o navegador ou o utilitário curl em outra sessão de terminal.

Personalize a seção do ConfigMap para selecionar quais métricas da GPU emitir.

Como alternativa, use o gráfico oficial do Helm para instalar o exportador do DCGM.

Para aplicar as alterações de configuração de um arquivo local, execute o seguinte comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Também é possível usar o Terraform para gerenciar as configurações.

Definir um recurso do PodMonitoring

Para descobrir o destino, o operador do Managed Service para Prometheus, é necessário um recurso PodMonitoring que corresponde ao exportador do DCGM no mesmo namespace.

É possível usar a seguinte configuração do 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: PodMonitoring
metadata:
  name: nvidia-dcgm-exporter
  namespace: gmp-public
  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

Para aplicar as alterações de configuração de um arquivo local, execute o seguinte comando:

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Também é possível usar o Terraform para gerenciar as configurações.

Verificar a configuração

Use o Metrics Explorer para verificar se você configurou corretamente o exportador do DCGM. Pode levar um ou dois minutos para que o Cloud Monitoring ingira as métricas.

Para verificar se as métricas foram transferidas, faça o seguinte:

  1. No painel de navegação do console do Google Cloud, selecione Monitoramento e  Metrics Explorer:

    Acesse o Metrics explorer

  2. Na barra de ferramentas do painel do criador de consultas, selecione o botão  MQL ou  PromQL.
  3. Verifique se PromQL está selecionado na opção de ativar/desativar Idioma. A alternância de idiomas está na mesma barra de ferramentas que permite formatar sua consulta.
  4. Digite e execute a seguinte consulta:
    DCGM_FI_DEV_GPU_UTIL{cluster="CLUSTER_NAME", namespace="gmp-public"}
    

Solução de problemas

Para resolver problemas de transferências de métricas, consulte Problemas com a coleta de exportadores em Resolver problemas no processamento.