[Agent][Operator] - bug fix

This commit is contained in:
zeaslity
2024-04-29 15:21:54 +08:00
parent aba731e719
commit ed29a457a3

View File

@@ -250,8 +250,7 @@ func refreshAgentInfoByStatusInfo(agentInfo *a_status.AgentInfo, agentServerInfo
// cpu part // cpu part
agentServerInfo.CPUCore = strconv.FormatInt(int64(agentInfo.CPUInfo.NumCores), 10) agentServerInfo.CPUCore = strconv.FormatInt(int64(agentInfo.CPUInfo.NumCores), 10)
if len(agentInfo.CPUInfo.CPUInfo) > 0 { if len(agentInfo.CPUInfo.CPUInfo) > 0 {
marshal, _ := json.Marshal(agentInfo.CPUInfo.CPUInfo[0].ModelName) agentServerInfo.CPUBrand = agentInfo.CPUInfo.CPUInfo[0].ModelName
agentServerInfo.CPUBrand = string(marshal)
} }
// os info // os info
@@ -289,6 +288,9 @@ func refreshAgentInfoByStatusInfo(agentInfo *a_status.AgentInfo, agentServerInfo
agentServerInfo.ServerName = uniformAgentServerName(agentInfo, agentServerInfo) agentServerInfo.ServerName = uniformAgentServerName(agentInfo, agentServerInfo)
agentServerInfo.MachineID = agentInfo.HostInfo.HostID agentServerInfo.MachineID = agentInfo.HostInfo.HostID
// io test
agentServerInfo.IoSpeed = testDiskIO()
log.DebugF("[refreshAgentInfoByStatusInfo] - ok !") log.DebugF("[refreshAgentInfoByStatusInfo] - ok !")
} }
@@ -310,12 +312,16 @@ func uniformAgentServerName(agentInfo *a_status.AgentInfo, agentServerInfo *a_ag
if strings.Contains(city, " ") { if strings.Contains(city, " ") {
city = strings.Join(strings.Split(city, " "), "") city = strings.Join(strings.Split(city, " "), "")
} }
// uniform city format
agentServerInfo.City = city
// linux host architecture
arch := getMachineType(agentInfo.HostInfo.KernelArch) arch := getMachineType(agentInfo.HostInfo.KernelArch)
var numS string var numS string
if agentServerInfo.ServerIPInV4 != "" { if agentServerInfo.ServerIPInV4 != "" {
split := strings.Split(agentServerInfo.ServerIPInV4, ".") split := strings.Split(agentServerInfo.ServerIPInV4, ".")
numS = fmt.Sprintf("%03d", split[3]) numS = split[3]
} else { } else {
// Seed the random number generator // Seed the random number generator
rand.Seed(time.Now().UnixNano()) rand.Seed(time.Now().UnixNano())
@@ -330,6 +336,55 @@ func uniformAgentServerName(agentInfo *a_status.AgentInfo, agentServerInfo *a_ag
return city + "-" + arch + "-" + numS return city + "-" + arch + "-" + numS
} }
func testDiskIO() string {
log.InfoF("testDiskIO - start !")
// Create a temporary file to test disk I/O
f, err := os.CreateTemp("", "test_disk_io")
if err != nil {
fmt.Println(err)
return ""
}
defer func() {
f.Close()
os.Remove(f.Name())
}()
// Write data to the file
data := make([]byte, 10240*10240) // 10MB
for i := 0; i < 10; i++ {
_, err = f.Write(data)
if err != nil {
fmt.Println(err)
return ""
}
}
// Read data from the file
startTime := time.Now()
buf := make([]byte, 10240*10240) // 10MB
for {
n, err := f.Read(buf)
if err != nil {
break
}
if n == 0 {
break
}
}
elapsedTime := time.Since(startTime).Seconds()
// Calculate the disk I/O speed in MB/s
speed := float64(len(data)) / (elapsedTime * 10240 * 10240)
sprintf := fmt.Sprintf("%.2f MB/s", speed)
log.InfoF("testDiskIO - end io speed are => %s", sprintf)
return sprintf
}
func getMachineType(arch string) string { func getMachineType(arch string) string {
switch { switch {