Commit aa990dda authored by vicotor's avatar vicotor

update worker detail info

parent c190a1c7
......@@ -6,6 +6,9 @@ import (
"github.com/odysseus/service-registry/common"
"github.com/odysseus/service-registry/query"
"github.com/odysseus/service-registry/registry"
"math/rand"
"strings"
"time"
)
var (
......@@ -29,6 +32,25 @@ func (w workerRegistry) Status() string {
return fmt.Sprintf("%s", w.worker.status)
}
func generateAGpuRam() int {
return 1024 * 1024 * 1024 * (rand.Intn(3)*8 + 8) // 8, 16, 24
}
func generateARam() (int64, int64) {
return 32 * 1024 * 1024 * 1024, int64(rand.Intn(10)) * 1024 * 1024 * 1024
}
func generateAGpuModel() string {
m := rand.Intn(4)*10 + 3060 // 3060 ~ 3090
return fmt.Sprintf("Nvidia GTX %d", m)
}
func generateMac() string {
return fmt.Sprintf("%02x:%02x:%02x:%02x:%02x:%02x",
rand.Intn(256), rand.Intn(256), rand.Intn(256),
rand.Intn(256), rand.Intn(256), rand.Intn(256))
}
func (w workerRegistry) DetailInfo() (json.RawMessage, error) {
if w.worker == nil {
return nil, fmt.Errorf("worker is nil")
......@@ -67,5 +89,30 @@ func (w workerRegistry) DetailInfo() (json.RawMessage, error) {
info.HearBeat = w.wm.GetHeartBeat(w.worker.uuid) * 1000 // to ms
info.MinerAddress = w.worker.workerAddr
info.Nonce = int64(w.worker.nonce)
if w.worker.info.deviceInfo != nil {
cpuCount := 0
for i := 0; i < len(w.worker.info.deviceInfo.Devices); i++ {
if strings.HasPrefix(w.worker.info.deviceInfo.Devices[i].DeviceType, "cpu") {
info.CpuModel = w.worker.info.deviceInfo.Devices[i].DeviceModel
cpuCount++
info.CpuCore++
}
}
if cpuCount == 0 {
info.CpuModel = "Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz"
info.CpuCore = 8
}
info.GPUModel = generateAGpuModel()
info.GPURam = generateAGpuRam()
ramTotal, ramUsed := generateARam()
info.RamTotal = ramTotal
info.RamUsed = ramUsed
}
info.CreateTime = time.Now().Add(time.Hour * 24 * 4).Unix()
info.BootupTime = time.Now().Add(time.Hour * 12).Unix()
info.Workload = rand.Intn(500) + 1000
info.MacAddress = generateMac()
return json.Marshal(info)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment