exporter@nvidia-gpu监控

NVIDIA 的 dcgm-exporter 是一个开源工具,基于 **NVIDIA Data Center GPU Manager (DCGM)**,用于收集 GPU 的运行指标,并以 Prometheus 格式暴露这些数据,方便进行监控和分析。

DCGM Exporter: NVIDIA’s Data Center GPU Manager (DCGM) exporter, often used to collect GPU metrics for Prometheus.

  • Metrics include: memory usage, temperature, utilization, power draw, etc.

  • Installation typically involves running a containerized exporter on systems with NVIDIA GPUs.


🧩 工具简介

dcgm-exporter 通过 Go 语言开发,利用 DCGM API 获取 GPU 的性能数据,如利用率、显存使用量、温度和功耗等,并通过 HTTP 端点(默认端口为 9400)以 Prometheus 可识别的格式提供这些指标。

该工具支持在 Kubernetes 集群中以 DaemonSet 的形式部署,也可以在本地通过 Docker 容器运行,适用于深度学习、高性能计算(HPC)等 GPU 密集型应用场景。


🚀 安装与使用

✅ 前提条件

  • 已安装 NVIDIA GPU 驱动程序。
  • 已安装 NVIDIA DCGM。
  • 已安装 Docker(用于容器化部署)。

📦 Docker 部署示例

1.常规默认全部采集指标

1
2
3
4
5
6
docker run --rm -d \
--gpus all \
-p 9400:9400 \
--cap-add SYS_ADMIN \
--cap-add DAC_READ_SEARCH \
nvcr.io/nvidia/k8s/dcgm-exporter:3.3.5-3.1.7-ubuntu20.04

运行后,可通过以下命令访问 GPU 指标

1
curl http://localhost:9400/metrics

2.自定义采集指标(metrics)

dcgm-exporter 支持使用 CSV 格式的配置文件(如 dcp-metrics-included.csv)来自定义需要收集的 GPU 指标。

在 Docker 部署中,可以通过 -f 参数指定配置文件:

1
2
3
4
5
6
docker run -d --rm \
--gpus all \
--net host \
--cap-add SYS_ADMIN \
nvcr.io/nvidia/k8s/dcgm-exporter:3.0.4-3.0.0-ubuntu20.04 \
-f /etc/dcgm-exporter/dcp-metrics-included.csv

☸️ Kubernetes 部署示例

在 Kubernetes 集群中,可以使用 Helm 部署 dcgm-exporte

1
2
3
helm repo add gpu-helm-charts https://nvidia.github.io/gpu-monitoring-tools/helm-charts
helm repo update
helm install --generate-name gpu-helm-charts/dcgm-exporter

部署后,dcgm-exporter 将作为 DaemonSet 在每个 GPU 节点上运行,并通过 Prometheus 进行指标收集。


📊 集成 Prometheus 和 Grafana

dcgm-exporter 提供的指标可被 Prometheus 采集,并通过 Grafana 进行可视化展示。

🔧 Prometheus 配置示例

在 Prometheus 的配置文件中添加以下 job:

1
2
3
4
5
6
7
8
9
10
11
scrape_configs:
- job_name: 'dcgm-exporter'
static_configs:
- targets: ['localhost:9400']

#or

scrape_configs:
- job_name: 'nvidia-gpu'
static_configs:
- targets: ['localhost:9400']

📈 Grafana 仪表盘

在 Grafana 中,您可以导入 NVIDIA 提供的官方仪表盘模板,或根据需要自定义仪表盘,以展示 GPU 的各项性能指标。

仪表板 ID: 12239
仪表板 ID: 22515

在 Grafana 中导入该仪表板步骤

  • 1.登录 Grafana 控制台。
  • 2.导航至 “仪表板” > “导入”。
  • 3.输入仪表板 ID 12239 或上传下载的 JSON 文件。
  • 4.选择相应的 Prometheus 数据源。