nezhahq-agent/pkg/gpu/stat/stat_windows.go
UUBulb fb7b45527b
service: logging to syslog (#33)
* service: logging to syslog

* chore: update gopsutil to v4

* chore: move println() to the util package

* gpu: only return 0 on failure
2024-07-05 22:31:56 +08:00

32 lines
659 B
Go

//go:build windows
package stat
import (
"os/exec"
"strconv"
"strings"
)
func GetGPUStat() (float64, error) {
shellPath, err := exec.LookPath("powershell.exe")
if err != nil || shellPath == "" {
return 0, err
}
cmd := exec.Command(
shellPath,
"-Command",
`Write-Output "$([math]::Round((((Get-Counter "\GPU Engine(*engtype_3D)\Utilization Percentage").CounterSamples | where CookedValue).CookedValue | measure -sum).sum,2))"`,
)
output, err1 := cmd.CombinedOutput()
if err1 != nil {
return 0, err1
}
t := strings.TrimSpace(string(output))
gs, err2 := strconv.ParseFloat(t, 64)
if err2 != nil {
return 0, err2
}
return gs, nil
}