|
@@ -31,38 +31,43 @@ func Ping(ctx context.Context) {
|
|
|
}
|
|
|
|
|
|
wg.Wait()
|
|
|
- go PingStatus(ctx)
|
|
|
+ //go PingStatus(ctx)
|
|
|
}
|
|
|
|
|
|
func PingStatus(ctx context.Context) {
|
|
|
-
|
|
|
+ var wg sync.WaitGroup
|
|
|
nodeList, err := service.Node().GetNode(ctx)
|
|
|
if err != nil {
|
|
|
glog.Debug(ctx, err.Error())
|
|
|
return
|
|
|
}
|
|
|
for _, target := range nodeList {
|
|
|
- CheckNodeStatus(ctx, target)
|
|
|
+ wg.Add(1)
|
|
|
+ go CheckNodeStatus(ctx, target, &wg)
|
|
|
}
|
|
|
-
|
|
|
+ wg.Wait()
|
|
|
}
|
|
|
|
|
|
func PingTask(ctx context.Context, t string, wg *sync.WaitGroup, pingType int, hostPort int, serverid int) {
|
|
|
//var ipSlice []string
|
|
|
//ipSlice = append(ipSlice, "kdvkr-02.xyz")
|
|
|
//ipSlice = append(ipSlice, "kdvkr-04.xyz")
|
|
|
- pingCount, err := g.Cfg().Get(ctx, "node.pingCount")
|
|
|
+ //pingCount, err := g.Cfg().Get(ctx, "node.pingCount")
|
|
|
+ //if err != nil {
|
|
|
+ // glog.Debug(ctx, err.Error())
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ pingconfig, err := service.PingConfig().Get(ctx)
|
|
|
if err != nil {
|
|
|
glog.Debug(ctx, err.Error())
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
stat := model.PingSt{}
|
|
|
stat.MinDelay = -1
|
|
|
lossPK := 0
|
|
|
addr, err := net.ResolveIPAddr("ip", t)
|
|
|
if err == nil {
|
|
|
- for i := 0; i < pingCount.Int(); i++ {
|
|
|
+ for i := 0; i < pingconfig.NodeCount; i++ {
|
|
|
starttime := time.Now().UnixNano()
|
|
|
|
|
|
var rest nettools.IPingResult
|
|
@@ -86,7 +91,7 @@ func PingTask(ctx context.Context, t string, wg *sync.WaitGroup, pingType int, h
|
|
|
}
|
|
|
stat.RevcPk = stat.RevcPk + 1
|
|
|
} else {
|
|
|
- //glog.Debug(ctx, "[func:StartPing IcmpPing] ID:", i, " IP:", addr, "| err:", rest.Error())
|
|
|
+ glog.Debug(ctx, "[func:StartPing IcmpPing] ID:", i, " IP:", addr, "| err:", rest.Error())
|
|
|
lossPK = lossPK + 1
|
|
|
}
|
|
|
stat.SendPk = stat.SendPk + 1
|
|
@@ -99,7 +104,7 @@ func PingTask(ctx context.Context, t string, wg *sync.WaitGroup, pingType int, h
|
|
|
} else {
|
|
|
stat.AvgDelay = 0.0
|
|
|
}
|
|
|
- //glog.Debug(ctx, "[func:IcmpPing] Finish Addr:", addr, " MaxDelay:", stat.MaxDelay, " MinDelay:", stat.MinDelay, " AvgDelay:", stat.AvgDelay, " Revc:", stat.RevcPk, " LossPK:", stat.LossPk)
|
|
|
+ glog.Debug(ctx, "[func:IcmpPing] Finish Addr:", addr, " MaxDelay:", stat.MaxDelay, " MinDelay:", stat.MinDelay, " AvgDelay:", stat.AvgDelay, " Revc:", stat.RevcPk, " LossPK:", stat.LossPk)
|
|
|
} else {
|
|
|
stat.AvgDelay = 0.00
|
|
|
stat.MinDelay = 0.00
|
|
@@ -107,7 +112,7 @@ func PingTask(ctx context.Context, t string, wg *sync.WaitGroup, pingType int, h
|
|
|
stat.SendPk = 0
|
|
|
stat.RevcPk = 0
|
|
|
stat.LossPk = 100
|
|
|
- //glog.Debug(ctx, "[func:IcmpPing] Finish Addr:", addr, " Unable to resolve destination host")
|
|
|
+ glog.Debug(ctx, "[func:IcmpPing] Finish Addr:", addr, " Unable to resolve destination host")
|
|
|
}
|
|
|
|
|
|
//添加到数据库
|
|
@@ -132,7 +137,7 @@ func AddPingLog(ctx context.Context, pingres model.PingSt, addr string, serverid
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-func CheckNodeStatus(ctx context.Context, target *entity.Node) {
|
|
|
+func CheckNodeStatus(ctx context.Context, target *entity.Node, wg *sync.WaitGroup) {
|
|
|
|
|
|
glog.Debug(ctx, "start url req .....")
|
|
|
//获取不通的IP进程url请求
|
|
@@ -167,6 +172,8 @@ func CheckNodeStatus(ctx context.Context, target *entity.Node) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ wg.Done()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func SSHTaskCommand(ctx context.Context, host string, port int) {
|