Commit 44c265e1 authored by 陈子龙's avatar 陈子龙

主机状态检测 fix

parent d41c21a7
...@@ -462,7 +462,7 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err ...@@ -462,7 +462,7 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
fail := make([]int, 0) fail := make([]int, 0)
for i := 0; i < len(hostManageList); i++ { for i := 0; i < len(hostManageList); i++ {
go func(i int) { go func(i int) {
//修改状态 //检测ip连通性
connStatus := StatusDetection(hostManageList[i].Ip) connStatus := StatusDetection(hostManageList[i].Ip)
if connStatus == 1 { if connStatus == 1 {
lock.Lock() lock.Lock()
...@@ -587,13 +587,27 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL ...@@ -587,13 +587,27 @@ func (h *HostManageSvc) SaveStateHostManage(hostManageList []request.HostManageL
return return
} }
//状态检测 // 使用协程批量执行 ping 命令
var wg sync.WaitGroup
wg.Add(len(hostManageListCaches))
id = uuid.New().String() id = uuid.New().String()
for k, v := range hostManageListCaches { for i := 0; i < len(hostManageListCaches); i++ {
//调用状态检测函数 go func(i int) {
hostManageListCaches[k].ConnStatus = StatusDetection(v.Ip) //检测ip连通性
hostManageListCaches[k].Id = id hostManageListCaches[i].ConnStatus = StatusDetection(hostManageListCaches[i].Ip)
hostManageListCaches[i].Id = id
defer wg.Done()
}(i)
} }
wg.Wait()
//状态检测
//id = uuid.New().String()
//for k, v := range hostManageListCaches {
// //调用状态检测函数
// hostManageListCaches[k].ConnStatus = StatusDetection(v.Ip)
// hostManageListCaches[k].Id = id
//}
//存入数据库 //存入数据库
_, err = db.Table("host_manage_list_cache").Insert(&hostManageListCaches) _, err = db.Table("host_manage_list_cache").Insert(&hostManageListCaches)
......
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