Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions cmd/vGPUmonitor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ var (
hostGPUdesc = prometheus.NewDesc(
"hami_host_gpu_memory_used_bytes",
"GPU device memory usage in bytes",
[]string{"device_index", "device_uuid", "device_type"}, nil,
[]string{"node", "device_index", "device_uuid", "device_type"}, nil,
)

hostGPUUtilizationdesc = prometheus.NewDesc(
"hami_host_gpu_utilization_ratio",
"GPU core utilization ratio (0-100)",
[]string{"device_index", "device_uuid", "device_type"}, nil,
[]string{"node", "device_index", "device_uuid", "device_type"}, nil,
)

ctrvGPUdesc = prometheus.NewDesc(
Expand Down Expand Up @@ -133,12 +133,12 @@ func initLegacyDescriptors() {
legacyHostGPUdesc = prometheus.NewDesc(
"HostGPUMemoryUsage",
"GPU device memory usage",
[]string{"deviceidx", "deviceuuid", "devicetype"}, nil,
[]string{"nodeid", "deviceidx", "deviceuuid", "devicetype"}, nil,
)
legacyHostGPUUtilizationdesc = prometheus.NewDesc(
"HostCoreUtilization",
"GPU core utilization",
[]string{"deviceidx", "deviceuuid", "devicetype"}, nil,
[]string{"nodeid", "deviceidx", "deviceuuid", "devicetype"}, nil,
)
legacyCtrvGPUdesc = prometheus.NewDesc(
"vGPU_device_memory_usage_in_bytes",
Expand Down Expand Up @@ -310,22 +310,26 @@ func (cc ClusterManagerCollector) collectGPUMemoryMetrics(ch chan<- prometheus.M

deviceName = "NVIDIA-" + deviceName

nodeName := os.Getenv(util.NodeNameEnvName)
Comment thread
SK8-infi marked this conversation as resolved.
Resolved

ch <- prometheus.MustNewConstMetric(
hostGPUdesc,
prometheus.GaugeValue,
float64(memory.Used),
fmt.Sprint(index), uuid, deviceName,
nodeName, fmt.Sprint(index), uuid, deviceName,
)

sendLegacyMetric(ch, legacyHostGPUdesc, prometheus.GaugeValue, float64(memory.Used),
fmt.Sprint(index), uuid, deviceName,
nodeName, fmt.Sprint(index), uuid, deviceName,
)

return nil
}

func (cc ClusterManagerCollector) collectGPUUtilizationMetrics(ch chan<- prometheus.Metric, hdev nvml.Device, index int) error {
util, nvret := hdev.GetUtilizationRates()
nodeName := os.Getenv(util.NodeNameEnvName)
Comment thread
SK8-infi marked this conversation as resolved.
Resolved

utilRates, nvret := hdev.GetUtilizationRates()
Comment thread
SK8-infi marked this conversation as resolved.
Resolved
if nvret != nvml.SUCCESS {
return fmt.Errorf("nvml GetUtilizationRates err: %s", nvml.ErrorString(nvret))
}
Expand All @@ -345,12 +349,12 @@ func (cc ClusterManagerCollector) collectGPUUtilizationMetrics(ch chan<- prometh
ch <- prometheus.MustNewConstMetric(
hostGPUUtilizationdesc,
prometheus.GaugeValue,
float64(util.Gpu),
fmt.Sprint(index), uuid, deviceName,
float64(utilRates.Gpu),
nodeName, fmt.Sprint(index), uuid, deviceName,
)

sendLegacyMetric(ch, legacyHostGPUUtilizationdesc, prometheus.GaugeValue, float64(util.Gpu),
fmt.Sprint(index), uuid, deviceName,
sendLegacyMetric(ch, legacyHostGPUUtilizationdesc, prometheus.GaugeValue, float64(utilRates.Gpu),
nodeName, fmt.Sprint(index), uuid, deviceName,
)

return nil
Expand Down
27 changes: 27 additions & 0 deletions cmd/vGPUmonitor/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package main

import (
"strings"
"testing"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -68,3 +69,29 @@ func TestDescribeCollectSync(t *testing.T) {
t.Errorf("Gather failed (legacy): %v", err)
}
}

func TestHostGPUMetricsDescriptorsIncludeNodeLabel(t *testing.T) {
initLegacyDescriptors()

// Verify standard host GPU descriptors include "node" label
hostGPUString := hostGPUdesc.String()
if !strings.Contains(hostGPUString, `"node"`) && !strings.Contains(hostGPUString, `node`) {
t.Errorf("hostGPUdesc does not contain 'node' label: %s", hostGPUString)
}

hostGPUUtilString := hostGPUUtilizationdesc.String()
if !strings.Contains(hostGPUUtilString, `"node"`) && !strings.Contains(hostGPUUtilString, `node`) {
t.Errorf("hostGPUUtilizationdesc does not contain 'node' label: %s", hostGPUUtilString)
}

// Verify legacy host GPU descriptors include "nodeid" label
legacyHostGPUString := legacyHostGPUdesc.String()
if !strings.Contains(legacyHostGPUString, `"nodeid"`) && !strings.Contains(legacyHostGPUString, `nodeid`) {
t.Errorf("legacyHostGPUdesc does not contain 'nodeid' label: %s", legacyHostGPUString)
}

legacyHostGPUUtilString := legacyHostGPUUtilizationdesc.String()
if !strings.Contains(legacyHostGPUUtilString, `"nodeid"`) && !strings.Contains(legacyHostGPUUtilString, `nodeid`) {
t.Errorf("legacyHostGPUUtilizationdesc does not contain 'nodeid' label: %s", legacyHostGPUUtilString)
}
}
Loading