add json
This commit is contained in:
5
pkg/constant/constant.go
Normal file
5
pkg/constant/constant.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package constant
|
||||
|
||||
const (
|
||||
Version = "0.1-alpha"
|
||||
)
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user