Skip to content

Commit

Permalink
feat(cluster): add check network
Browse files Browse the repository at this point in the history
  • Loading branch information
9547 committed Feb 4, 2021
1 parent 34aa43b commit 49d1f08
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ var (
CheckNamePortListen = "listening-port"
CheckNameEpoll = "epoll-exclusive"
CheckNameMem = "memory"
CheckNameNet = "network"
CheckNameLimits = "limits"
CheckNameSysService = "service"
CheckNameSELinux = "selinux"
Expand Down Expand Up @@ -135,6 +136,9 @@ func checkSysInfo(opt *CheckOptions, sysInfo *sysinfo.SysInfo) []*CheckResult {
// check memory size
results = append(results, checkMem(opt, &sysInfo.Memory)...)

// check network
results = append(results, checkNetwork(opt, sysInfo.Network)...)

return results
}

Expand Down Expand Up @@ -233,6 +237,29 @@ func checkMem(opt *CheckOptions, memInfo *sysinfo.Memory) []*CheckResult {
return results
}

func checkNetwork(opt *CheckOptions, networkDevices []sysinfo.NetworkDevice) []*CheckResult {
var results []*CheckResult
for _, netdev := range networkDevices {
// ignore the network devices that cannot be detected
if netdev.Speed == 0 {
continue
}
if netdev.Speed > 1000 {
results = append(results, &CheckResult{
Name: CheckNameNet,
Msg: fmt.Sprintf("network speed of %s is %dMB", netdev.Name, netdev.Speed),
})
} else {
results = append(results, &CheckResult{
Name: CheckNameNet,
Err: fmt.Errorf("network speed of %s is %dMB too low, needs 1GB or more", netdev.Name, netdev.Speed),
})
}
}

return results
}

// CheckSysLimits checks limits in /etc/security/limits.conf
func CheckSysLimits(opt *CheckOptions, user string, l []byte) []*CheckResult {
var results []*CheckResult
Expand Down

0 comments on commit 49d1f08

Please sign in to comment.