mirror of
https://github.com/newnius/YAO-scheduler.git
synced 2025-12-15 08:16:43 +00:00
update interface
This commit is contained in:
@@ -3,21 +3,21 @@ package main
|
|||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"strconv"
|
|
||||||
"fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResourcePool struct {
|
type ResourcePool struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
nodes map[string]NodeStatus
|
nodes map[string]NodeStatus
|
||||||
|
|
||||||
history []map[string]string
|
history []PoolStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pool *ResourcePool) start() {
|
func (pool *ResourcePool) start() {
|
||||||
go func() {
|
go func() {
|
||||||
|
/* waiting for data */
|
||||||
|
time.Sleep(time.Second * 30)
|
||||||
for {
|
for {
|
||||||
summary := map[string]string{}
|
summary := PoolStatus{}
|
||||||
|
|
||||||
UtilCPU := 0.0
|
UtilCPU := 0.0
|
||||||
TotalCPU := 0
|
TotalCPU := 0
|
||||||
@@ -41,19 +41,19 @@ func (pool *ResourcePool) start() {
|
|||||||
AvailableMemGPU += GPU.MemoryFree
|
AvailableMemGPU += GPU.MemoryFree
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
summary["ts"] = time.Now().Format("2006-01-02 15:04:05")
|
summary.TimeStamp = time.Now().Format("2006-01-02 15:04:05")
|
||||||
summary["cpu_util"] = fmt.Sprintf("%.2f", UtilCPU/(float64(len(pool.nodes))+0.001))
|
summary.UtilCPU = UtilCPU / (float64(len(pool.nodes)) + 0.001)
|
||||||
summary["cpu_total"] = strconv.Itoa(TotalCPU)
|
summary.TotalCPU = TotalCPU
|
||||||
summary["mem_total"] = strconv.Itoa(TotalMem)
|
summary.TotalMem = TotalMem
|
||||||
summary["mem_available"] = strconv.Itoa(AvailableMem)
|
summary.AvailableMem = AvailableMem
|
||||||
summary["gpu_total"] = strconv.Itoa(TotalGPU)
|
summary.TotalGPU = TotalGPU
|
||||||
if TotalGPU == 0 {
|
if TotalGPU == 0 {
|
||||||
summary["gpu_util"] = "0"
|
summary.UtilGPU = 0.0
|
||||||
} else {
|
} else {
|
||||||
summary["gpu_util"] = fmt.Sprintf("%2d", UtilGPU/TotalGPU)
|
summary.UtilGPU = UtilGPU / TotalGPU
|
||||||
}
|
}
|
||||||
summary["gpu_mem_total"] = strconv.Itoa(TotalMemGPU)
|
summary.TotalMemGPU = TotalMemGPU
|
||||||
summary["gpu_mem_available"] = strconv.Itoa(AvailableMemGPU)
|
summary.AvailableMemGPU = AvailableMemGPU
|
||||||
|
|
||||||
pool.history = append(pool.history, summary)
|
pool.history = append(pool.history, summary)
|
||||||
|
|
||||||
|
|||||||
18
src/util.go
18
src/util.go
@@ -16,15 +16,27 @@ const (
|
|||||||
Finished = 4
|
Finished = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PoolStatus struct {
|
||||||
|
TimeStamp string `json:"ts"`
|
||||||
|
UtilCPU float64 `json:"cpu_util"`
|
||||||
|
TotalCPU int `json:"cpu_total"`
|
||||||
|
TotalMem int `json:"mem_total"`
|
||||||
|
AvailableMem int `json:"mem_available"`
|
||||||
|
TotalGPU int `json:"TotalGPU"`
|
||||||
|
UtilGPU int `json:"gpu_util"`
|
||||||
|
TotalMemGPU int `json:"gpu_mem_total"`
|
||||||
|
AvailableMemGPU int `json:"gpu_mem_available"`
|
||||||
|
}
|
||||||
|
|
||||||
type MsgSubmit struct {
|
type MsgSubmit struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MsgPoolStatusHistory struct {
|
type MsgPoolStatusHistory struct {
|
||||||
Code int `json:"code"`
|
Code int `json:"code"`
|
||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
Data []map[string]string `json:"data"`
|
Data []PoolStatus `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MsgStop struct {
|
type MsgStop struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user