From 49d1f089fd0a5960d1125b3b555b9d4db928b212 Mon Sep 17 00:00:00 2001 From: 9547 Date: Tue, 2 Feb 2021 08:32:16 +0800 Subject: [PATCH] feat(cluster): add check network --- pkg/cluster/operation/check.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index ae56fcc1a6..7325ec221e 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -54,6 +54,7 @@ var ( CheckNamePortListen = "listening-port" CheckNameEpoll = "epoll-exclusive" CheckNameMem = "memory" + CheckNameNet = "network" CheckNameLimits = "limits" CheckNameSysService = "service" CheckNameSELinux = "selinux" @@ -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 } @@ -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