Skip to content

Commit

Permalink
Merge pull request #5 from sratcliffe/add_fan_speed
Browse files Browse the repository at this point in the history
Add fan speed and swap C and F
  • Loading branch information
tankbusta authored Nov 16, 2017
2 parents 43e5122 + 4741872 commit 235fa46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nvidia_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var (
help: "Power Usage of an NVIDIA GPU in Watts",
labels: []string{"device_id", "device_uuid", "device_name"},
},
"fan_speed": &VecInfo{
help: "Device Fan Speed in Percent of Maximum",
labels: []string{"device_id", "device_uuid", "device_name"},
},
"gpu_percent": &VecInfo{
help: "Percent of GPU Utilized",
labels: []string{"device_id", "device_uuid", "device_name"},
Expand Down Expand Up @@ -113,6 +117,7 @@ func (e *Exporter) GetTelemetryFromNVML() {
var (
gpuMem *NVMLMemory
powerUsage int
fanSpeed int
gpuPercent, memoryPercent int
err error
tempF, tempC int
Expand All @@ -126,7 +131,7 @@ func (e *Exporter) GetTelemetryFromNVML() {
e.gauges["gpu_percent"].WithLabelValues(id, device.DeviceUUID, device.DeviceName).Set(float64(gpuPercent))
e.gauges["memory_percent"].WithLabelValues(id, device.DeviceUUID, device.DeviceName).Set(float64(memoryPercent))

if tempF, tempC, err = device.GetTemperature(); err != nil {
if tempC, tempF, err = device.GetTemperature(); err != nil {
goto ErrorFetching
}
e.gauges["temperature_celsius"].WithLabelValues(id, device.DeviceUUID, device.DeviceName).Set(float64(tempC))
Expand All @@ -137,6 +142,11 @@ func (e *Exporter) GetTelemetryFromNVML() {
}
e.gauges["power_watts"].WithLabelValues(id, device.DeviceUUID, device.DeviceName).Set(float64(powerUsage))

if fanSpeed, err = device.GetFanSpeed(); err != nil {
goto ErrorFetching
}
e.gauges["fan_speed"].WithLabelValues(id, device.DeviceUUID, device.DeviceName).Set(float64(fanSpeed))

if gpuMem, err = device.GetMemoryInfo(); err != nil {
goto ErrorFetching
}
Expand Down
9 changes: 9 additions & 0 deletions nvml.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ func (s *Device) GetPowerUsage() (int, error) {
return usage / 1000, nil
}

// GetFanSpeed returns the fan speed in percent
func (s *Device) GetFanSpeed() (int, error) {
speed, err := s.callGetIntFunc(C.getNvmlIntProperty(C.nvmlDeviceGetFanSpeed))
if err != nil {
return 0, err
}
return speed, nil
}

// GetTemperature returns the Device's temperature in Farenheit and celsius
func (s *Device) GetTemperature() (int, int, error) {
var tempc C.uint
Expand Down

0 comments on commit 235fa46

Please sign in to comment.