[Agent][Operator] - bug fix
This commit is contained in:
@@ -250,8 +250,7 @@ func refreshAgentInfoByStatusInfo(agentInfo *a_status.AgentInfo, agentServerInfo
|
||||
// cpu part
|
||||
agentServerInfo.CPUCore = strconv.FormatInt(int64(agentInfo.CPUInfo.NumCores), 10)
|
||||
if len(agentInfo.CPUInfo.CPUInfo) > 0 {
|
||||
marshal, _ := json.Marshal(agentInfo.CPUInfo.CPUInfo[0].ModelName)
|
||||
agentServerInfo.CPUBrand = string(marshal)
|
||||
agentServerInfo.CPUBrand = agentInfo.CPUInfo.CPUInfo[0].ModelName
|
||||
}
|
||||
|
||||
// os info
|
||||
@@ -289,6 +288,9 @@ func refreshAgentInfoByStatusInfo(agentInfo *a_status.AgentInfo, agentServerInfo
|
||||
agentServerInfo.ServerName = uniformAgentServerName(agentInfo, agentServerInfo)
|
||||
agentServerInfo.MachineID = agentInfo.HostInfo.HostID
|
||||
|
||||
// io test
|
||||
agentServerInfo.IoSpeed = testDiskIO()
|
||||
|
||||
log.DebugF("[refreshAgentInfoByStatusInfo] - ok !")
|
||||
}
|
||||
|
||||
@@ -310,12 +312,16 @@ func uniformAgentServerName(agentInfo *a_status.AgentInfo, agentServerInfo *a_ag
|
||||
if strings.Contains(city, " ") {
|
||||
city = strings.Join(strings.Split(city, " "), "")
|
||||
}
|
||||
// uniform city format
|
||||
agentServerInfo.City = city
|
||||
|
||||
// linux host architecture
|
||||
arch := getMachineType(agentInfo.HostInfo.KernelArch)
|
||||
|
||||
var numS string
|
||||
if agentServerInfo.ServerIPInV4 != "" {
|
||||
split := strings.Split(agentServerInfo.ServerIPInV4, ".")
|
||||
numS = fmt.Sprintf("%03d", split[3])
|
||||
numS = split[3]
|
||||
} else {
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
@@ -330,6 +336,55 @@ func uniformAgentServerName(agentInfo *a_status.AgentInfo, agentServerInfo *a_ag
|
||||
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 {
|
||||
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user