@cryptotaxi247 / netdata-1 / commits / 2c494e1cc

fix(go.d/nvidia_smi): handle xml gpu_power_readings change (#19759)

Ilya Mashchenko committed Mar 3, 2025 at 23:37 UTC 2c494e1ccec1a56fbb66827334311cea1cec2618
3 files changed +22 -8
src/go/plugin/go.d/collector/nvidia_smi/charts.go
+5 -2
@@ -284,8 +284,11 @@ func (c *Collector) addGpuCharts(gpu gpuInfo, index int) {
284 if !isValidValue(gpu.FanSpeed) {
285 _ = charts.Remove(gpuFanSpeedPercChartTmpl.ID)
286 }
287 - if (gpu.PowerReadings == nil || !isValidValue(gpu.PowerReadings.PowerDraw)) &&
288 - (gpu.GPUPowerReadings == nil || !isValidValue(gpu.GPUPowerReadings.PowerDraw)) {
287 +
288 + mx := make(map[string]int64)
289 + addGPUPowerMetricsSwitch(mx, "", gpu)
290 +
291 + if len(mx) == 0 {
292 _ = charts.Remove(gpuPowerDrawChartTmpl.ID)
293 }
294 if !isValidValue(gpu.Voltage.GraphicsVolt) {
src/go/plugin/go.d/collector/nvidia_smi/collect.go
+14 -5
@@ -77,11 +77,7 @@ func (c *Collector) collectGPUInfo(mx map[string]int64) error {
77 addMetric(mx, px+"video_clock", gpu.Clocks.VideoClock, 0)
78 addMetric(mx, px+"sm_clock", gpu.Clocks.SmClock, 0)
79 addMetric(mx, px+"mem_clock", gpu.Clocks.MemClock, 0)
80 - if gpu.PowerReadings != nil {
81 - addMetric(mx, px+"power_draw", gpu.PowerReadings.PowerDraw, 0)
82 - } else if gpu.GPUPowerReadings != nil {
83 - addMetric(mx, px+"power_draw", gpu.GPUPowerReadings.PowerDraw, 0)
84 - }
80 + addGPUPowerMetricsSwitch(mx, px, gpu)
81 addMetric(mx, px+"voltage", gpu.Voltage.GraphicsVolt, 0)
82 for i := 0; i < 16; i++ {
83 s := "P" + strconv.Itoa(i)
@@ -134,6 +130,19 @@ func (c *Collector) collectGPUInfo(mx map[string]int64) error {
130 return nil
131 }
132
133 +func addGPUPowerMetricsSwitch(mx map[string]int64, px string, gpu gpuInfo) {
134 + switch true {
135 + case gpu.PowerReadings != nil && gpu.PowerReadings.PowerDraw != nil:
136 + addMetric(mx, px+"power_draw", *gpu.PowerReadings.PowerDraw, 0)
137 + case gpu.GPUPowerReadings != nil && gpu.GPUPowerReadings.PowerDraw != nil:
138 + addMetric(mx, px+"power_draw", *gpu.GPUPowerReadings.PowerDraw, 0)
139 + case gpu.GPUPowerReadings != nil && gpu.GPUPowerReadings.InstantPowerDraw != nil:
140 + addMetric(mx, px+"power_draw", *gpu.GPUPowerReadings.InstantPowerDraw, 0)
141 + case gpu.GPUPowerReadings != nil && gpu.GPUPowerReadings.AveragePowerDraw != nil:
142 + addMetric(mx, px+"power_draw", *gpu.GPUPowerReadings.AveragePowerDraw, 0)
143 + }
144 +}
145 +
146 func calcMaxPCIEBandwidth(gpu gpuInfo) float64 {
147 gen := gpu.PCI.PCIGPULinkInfo.PCIEGen.MaxLinkGen
148 width := strings.TrimSuffix(gpu.PCI.PCIGPULinkInfo.LinkWidths.MaxLinkWidth, "x")
src/go/plugin/go.d/collector/nvidia_smi/gpu_info.go
+3 -1
@@ -81,7 +81,9 @@ type (
81 gpuPowerReadings struct {
82 //PowerState string `xml:"power_state"`
83 //PowerManagement string `xml:"power_management"`
84 - PowerDraw string `xml:"power_draw"`
84 + PowerDraw *string `xml:"power_draw"`
85 + AveragePowerDraw *string `xml:"average_power_draw"`
86 + InstantPowerDraw *string `xml:"instant_power_draw"`
87 //PowerLimit string `xml:"power_limit"`
88 //DefaultPowerLimit string `xml:"default_power_limit"`
89 //EnforcedPowerLimit string `xml:"enforced_power_limit"`