This commit is contained in:
2024-02-24 11:40:26 +01:00
parent 55ce327ff5
commit 74432b1929
6 changed files with 144 additions and 35 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
"github.com/NVIDIA/go-nvml/pkg/nvml"
)
@@ -16,43 +17,43 @@ type (
}
GPU struct {
Name string
UUID string
Index int
Name string `json:"name"`
UUID string `json:"uuid"`
Index int `json:"-"`
}
GPUDetail struct {
GPU
CoreTemperature int
Utilization Utilization
Processes []Process
Memory Memory
Fans []Fan
CoreTemperature int `json:"coreTemperature"`
Utilization Utilization `json:"usage"`
Processes []Process `json:"processes"`
Memory Memory `json:"memory"`
Fans []Fan `json:"fans"`
}
Memory struct {
Free int
Reserved int
Total int
Used int
Version int
Free int `json:"free"`
Reserved int `json:"reserved"`
Total int `json:"total"`
Used int `json:"used"`
Version int `json:"-"`
}
Process struct {
PID int
MemoryUsed int
Name string
Type string
PID int `json:"pid"`
MemoryUsed int `json:"memoryUsed"`
Name string `json:"commandLine"`
Type string `json:"type"`
}
Utilization struct {
Decode int
Encode int
Rate int
Decoder int `json:"decoder"`
Encoder int `json:"encoder"`
Compute int `json:"compute"`
}
Fan struct {
Speed int
Speed int `json:"speed"`
}
)
@@ -196,9 +197,10 @@ func (*Repository) GetGPU(ID int) (GPUDetail, error) {
}
// Find process command line
for _, process := range allProcess {
for i, process := range allProcess {
if cmdline, err := os.ReadFile("/proc/" + strconv.Itoa(process.PID) + "/cmdline"); err == nil {
process.Name = string(cmdline)
process.Name = strings.ReplaceAll(string(cmdline), "\u0000", " ")
allProcess[i] = process
}
}
@@ -211,9 +213,9 @@ func (*Repository) GetGPU(ID int) (GPUDetail, error) {
GPU: gpu,
CoreTemperature: int(temp),
Utilization: Utilization{
Decode: int(decUsage),
Encode: int(encUsage),
Rate: int(load.Gpu),
Decoder: int(decUsage),
Encoder: int(encUsage),
Compute: int(load.Gpu),
},
Processes: allProcess,
Memory: Memory{