[NVSentinel] gpu-health-monitor模块之dcgm_watcher

NVSentinel gpu-health-monitor模块之dcgm_watcher

dcgm.py 是 GPU Health Monitor 的核心:通过 DCGM 周期性检查 GPU/Switch 健康,并把结果异步通知回调(如 Platform Connector)。

整体定位

DCGMWatcher 负责:

  1. 连接 DCGM(远程服务或进程内 embedded hostengine)
  2. 创建包含所有 GPU + NVSwitch 的 monitoring group
  3. 按间隔跑 health check,可选评估热裕度
  4. 过滤需抑制的错误码
  5. 通过 CallbackInterface 把结果发出去

数据流大致是:

markdown 复制代码
DCGM ←→ DCGMWatcher.start() 轮询循环
              ↓
     health_status + gpu_ids
              ↓
     CallbackInterface(如 PlatformConnector)

模块组成

1. 连接方式:_create_dcgm_handle / _run_dcgm_server

两种 mode:

Mode 行为
local-managed 进程内起 embedded DCGM,再把 hostengine 暴露到 loopback TCP
默认 remote addr 连已有 DCGM(K8s DCGM Exporter/服务或本机地址)

_run_dcgm_server 兼容 DCGM 4.x(dcgmServerRun)和 3.3.7(dcgmEngineRun)。

2. 能力发现

构造时会扫描 DCGM Python bindings:

  • _get_available_health_watches:所有 DCGM_HEALTH_WATCH_*
  • _get_available_error_codes:所有 DCGM_FR_* 错误码(会绕过 bindings 里已知的重复定义 bug)

用于把 DCGM 数值映射成可读的 watch / error 名称。

3. 健康检查:_perform_health_check

核心逻辑:

  1. 调用 dcgm_group.health.Check()
  2. 遍历 incidents,按 watch + GPU 聚合错误信息(多条 message 用 ; 拼接)
  3. 输出 dict[watch_name → HealthDetails]
  4. timeout / 异常时标记 connectivity_success=False,触发重连

4. 可选热裕度监控:_evaluate_gpu_thermal_margin

若启用 thermal_margin_enabled 且 bindings 有 field 153(DCGM_FI_DEV_GPU_TEMP_TLIMIT):

  • 订阅该 field
  • MetadataReader 读每张卡的 HW slowdown T.Limit
  • margin < slowdown_threshold 时记为 GPU_TEMP_HW_SLOWDOWN_VIOLATION

这是独立于标准 DCGM_HEALTH_WATCH_* 的自定义监视,通过 DCGM_FIELDS_MONITORING 注册表扩展。

5. 错误抑制:_suppress_configured_error_codes

对配置里 suppressed_error_codes 中的高频、不可操作事件:从 failures 里删掉;若该 watch 不再有 failure,状态改回 PASS

6. 回调:_fire_callback_funcs

用线程池异步调用每个 callback,避免阻塞轮询;成功/失败记 Prometheus metrics。

接口在 types.py

  • health_event_occurred(health_details, gpu_ids)
  • dcgm_connectivity_failed()

7. 主循环:start

vbnet 复制代码
while not exit:
    wait(poll_interval)
    if 无 handle:
        连接 + 初始化 group / field watch
        失败 → dcgm_connectivity_failed
    else:
        health check
        连通失败 → 清理资源,置空 handle(下轮重连)
        成功 → 热裕度评估 → 抑制错误 → health_event_occurred
finally:
    cleanup + 关闭线程池

初始化失败会 rollback(unwatch / delete field group / delete group),避免 DCGM 服务端资源泄漏。


关键类型(types.py

  • HealthStatus:PASS / WARN / FAIL
  • HealthDetails:某 watch 的整体状态 + entity_failures[gpu_id]
  • ErrorDetails:错误码 + 消息
  • DCGMFieldMonitor:自定义 field 监视配置
  • CallbackInterface:下游消费方契约

一句话总结

这个文件把 DCGM 采数/健康检查 做成可重连的轮询 watcher,再通过回调把「哪些 GPU、哪些 watch 出了什么问题」交给上层(Platform Connector)去做事件上报与处置。

相关推荐
Cosolar1 小时前
从 ChatGPT 到 Astra:四年走完的路,AGI 真的来了吗?
人工智能·aigc·openai
ting94520001 小时前
Dograh 深度技术解析:开源自托管语音智能体平台架构、流水线与工程实践
人工智能·架构
思考着亮1 小时前
13.GraphRAG
人工智能
HappyEnding1 小时前
OpenSpec + Superpowers 搭建 SDD+TDD 工作流教学文档
人工智能
思考着亮1 小时前
12.Agentic RAG
人工智能
zed_231 小时前
让答案有出处:citations 引用溯源
人工智能
长江后浪博客1 小时前
Python + YOLOv8 疲劳驾驶 AI 视觉检测入门:从模型训练到 ONNX 实时摄像头检测完整实战
人工智能·python·yolo·疲劳驾驶检测·onnx·yolov8
聪明蛋子哟2 小时前
告别API“翻译”之苦:从OpenAPI到MCP,统一AI与工具集成的桥梁
人工智能
海上小飞龙2 小时前
大模型推理的两阶段:一次 Prefill,加上多次 Decode
人工智能·深度学习·语言模型