From f5aaee24f00579f2df874e45fe049e96115ab0cd Mon Sep 17 00:00:00 2001 From: srstack Date: Tue, 4 Jan 2022 12:00:08 +0800 Subject: [PATCH 1/4] add check --- pkg/cluster/operation/check.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index a306752231..8ced0ad474 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -202,6 +202,12 @@ func checkNTP(ntpInfo *insight.TimeStat) *CheckResult { return result } + if ntpInfo.Sync == "none" { + result.Err = fmt.Errorf("The NTPd daemon may be not start") + result.Warn = true + return result + } + // check if time offset greater than +- 500ms if math.Abs(ntpInfo.Offset) >= 500 { result.Err = fmt.Errorf("time offet %fms too high", ntpInfo.Offset) From 5b7ec5ed401553c518ea50ad658dbf1ba60950b1 Mon Sep 17 00:00:00 2001 From: srstack Date: Wed, 5 Jan 2022 16:04:12 +0800 Subject: [PATCH 2/4] update check --- go.mod | 8 +++---- go.sum | 17 +++++++------- pkg/cluster/operation/check.go | 42 +++++++++++++++++++++++++++++++--- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 4ef19c83b7..211df1bd73 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ replace ( ) require ( - github.com/AstroProfundis/sysinfo v0.0.0-20210901042104-765f00aa1304 + github.com/AstroProfundis/sysinfo v0.0.0-20211201040748-b52c88acb418 github.com/AstroProfundis/tabby v1.1.1-color github.com/BurntSushi/toml v0.4.1 github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5 @@ -42,7 +42,7 @@ require ( github.com/pingcap/failpoint v0.0.0-20210918120811-547c13e3eb00 github.com/pingcap/fn v0.0.0-20200306044125-d5540d389059 github.com/pingcap/kvproto v0.0.0-20210915062418-0f5764a128ad - github.com/pingcap/tidb-insight/collector v0.0.0-20210923072556-14ae4968ce78 + github.com/pingcap/tidb-insight/collector v0.0.0-20220104095042-8dad166491c2 github.com/prometheus/client_model v0.2.0 github.com/prometheus/common v0.30.0 github.com/prometheus/prom2json v1.3.0 @@ -50,7 +50,7 @@ require ( github.com/relex/aini v1.5.0 github.com/sergi/go-diff v1.2.0 github.com/sethvargo/go-password v0.2.0 - github.com/shirou/gopsutil v3.21.8+incompatible + github.com/shirou/gopsutil v3.21.10+incompatible github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 github.com/spf13/cobra v1.2.1 github.com/spf13/pflag v1.0.5 @@ -64,7 +64,7 @@ require ( golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 golang.org/x/mod v0.5.1 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c - golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 + golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 golang.org/x/term v0.0.0-20210916214954-140adaaadfaf google.golang.org/genproto v0.0.0-20210921142501-181ce0d877f6 google.golang.org/grpc v1.40.0 diff --git a/go.sum b/go.sum index 11635b8c8e..73950f1d86 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/AstroProfundis/easyssh-proxy v1.3.10-0.20211209071554-9910ebdf514e h1:4j6hTmpAhrJYt8XhG/mLJYywzsclH6pqAim1H7HBM/o= github.com/AstroProfundis/easyssh-proxy v1.3.10-0.20211209071554-9910ebdf514e/go.mod h1:SnOlkuIAoaj8FvRIGcWp2BbLOwvHZnNNOva+DBMbHWU= -github.com/AstroProfundis/sysinfo v0.0.0-20210901042104-765f00aa1304 h1:xjoJdgLCgiPv8CNEnsHP+W6UJ/JiNbALll6csqw3hbg= -github.com/AstroProfundis/sysinfo v0.0.0-20210901042104-765f00aa1304/go.mod h1:4m15VhW6ZffaqJNAK/HtN3Qvf97aCe1T39u3UXaA2lA= +github.com/AstroProfundis/sysinfo v0.0.0-20211201040748-b52c88acb418 h1:mBWbJ+qSooaOMIAaSOtzA8PYDfhwyUWAJYT4AM8Rtoc= +github.com/AstroProfundis/sysinfo v0.0.0-20211201040748-b52c88acb418/go.mod h1:WP2xTB42TPPFNpTmPiOm4Zjm9jdHwhi8wrMYGAv1BRA= github.com/AstroProfundis/tabby v1.1.1-color h1:gi/Fs4W2KVcC1m29lqa39tDnsGfZG/PYvZmwOhAH5m0= github.com/AstroProfundis/tabby v1.1.1-color/go.mod h1:Wcm+uinH1saEOFGLK2LdY37lAOts8HLevz64Y3y3M3Q= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -430,8 +430,8 @@ github.com/pingcap/kvproto v0.0.0-20210915062418-0f5764a128ad h1:suBPTeuY6yVF7xv github.com/pingcap/kvproto v0.0.0-20210915062418-0f5764a128ad/go.mod h1:IOdRDPLyda8GX2hE/jO7gqaCV/PNFh8BZQCQZXfIOqI= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9 h1:AJD9pZYm72vMgPcQDww9rkZ1DnWfl0pXV3BOWlkYIjA= github.com/pingcap/log v0.0.0-20191012051959-b742a5d432e9/go.mod h1:4rbK1p9ILyIfb6hU7OG2CiWSqMXnp3JMbiaVJ6mvoY8= -github.com/pingcap/tidb-insight/collector v0.0.0-20210923072556-14ae4968ce78 h1:JN3fWkxAJ78atG2uo2dcTN8sleJhsr+TrnsMfrlu0do= -github.com/pingcap/tidb-insight/collector v0.0.0-20210923072556-14ae4968ce78/go.mod h1:k+GJKVPIdlV/J6hGJy7VKsxRVWV99BJfDKXGVrs4vH4= +github.com/pingcap/tidb-insight/collector v0.0.0-20220104095042-8dad166491c2 h1:r+nBxodqYUS1cEZh3MQfy3R5WEmnIC9yLAJbrwlFtHM= +github.com/pingcap/tidb-insight/collector v0.0.0-20220104095042-8dad166491c2/go.mod h1:w04Qnjn8hiTNR4fTMgm4+TfXtDBcCq2i1SKlXwqX69o= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -485,8 +485,8 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sethvargo/go-password v0.2.0 h1:BTDl4CC/gjf/axHMaDQtw507ogrXLci6XRiLc7i/UHI= github.com/sethvargo/go-password v0.2.0/go.mod h1:Ym4Mr9JXLBycr02MFuVQ/0JHidNetSgbzutTr3zsYXE= -github.com/shirou/gopsutil v3.21.8+incompatible h1:sh0foI8tMRlCidUJR+KzqWYWxrkuuPIGiO6Vp+KXdCU= -github.com/shirou/gopsutil v3.21.8+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil v3.21.10+incompatible h1:AL2kpVykjkqeN+MFe1WcwSBVUjGjvdU8/ubvCuXAjrU= +github.com/shirou/gopsutil v3.21.10+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= @@ -782,9 +782,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210816074244-15123e1e1f71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210921065528-437939a70204/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 h1:c20P3CcPbopVp2f7099WLOqSNKURf30Z0uq66HpijZY= -golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc= +golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210916214954-140adaaadfaf h1:Ihq/mm/suC88gF8WFcVwk+OV6Tq+wyA1O0E5UEvDglI= diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index 8ced0ad474..13b800d8bb 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -45,6 +45,7 @@ type CheckOptions struct { var ( CheckNameGeneral = "general" // errors that don't fit any specific check CheckNameNTP = "ntp" + CheckNameChrony = "chrony" CheckNameOSVer = "os-version" CheckNameSwap = "swap" CheckNameSysctl = "sysctl" @@ -112,8 +113,21 @@ func CheckSystemInfo(opt *CheckOptions, rawData []byte) []*CheckResult { // check basic system info results = append(results, checkSysInfo(opt, &insightInfo.SysInfo)...) - // check NTP sync status - results = append(results, checkNTP(&insightInfo.NTP)) + // check time sync status + switch { + case insightInfo.ChronyStat.LeapStatus != "none": + results = append(results, checkChrony(&insightInfo.ChronyStat)) + case insightInfo.NTP.Status != "none": + results = append(results, checkNTP(&insightInfo.NTP)) + default: + results = append(results, + &CheckResult{ + Name: CheckNameNTP, + Err: fmt.Errorf("The NTPd daemon or Chronyd daemon may be not installed"), + Warn: true, + }, + ) + } epollResult := &CheckResult{ Name: CheckNameEpoll, @@ -210,7 +224,29 @@ func checkNTP(ntpInfo *insight.TimeStat) *CheckResult { // check if time offset greater than +- 500ms if math.Abs(ntpInfo.Offset) >= 500 { - result.Err = fmt.Errorf("time offet %fms too high", ntpInfo.Offset) + result.Err = fmt.Errorf("time offset %fms too high", ntpInfo.Offset) + } else { + result.Msg = fmt.Sprintf("time offset is %fms", ntpInfo.Offset) + } + + return result +} + +func checkChrony(chronyInfo *insight.ChronyStat) *CheckResult { + result := &CheckResult{ + Name: CheckNameChrony, + } + + if chronyInfo.LeapStatus == "none" { + zap.L().Info("The NTPd daemon may be not installed, skip.") + return result + } + + // check if time offset greater than +- 500ms + if math.Abs(chronyInfo.LastOffset) >= 500 { + result.Err = fmt.Errorf("time offset %fms too high", chronyInfo.LastOffset) + } else { + result.Msg = fmt.Sprintf("time offset is %fms", chronyInfo.LastOffset) } return result From ca0c86b8b83906572f3bf394591b9808624c2dd2 Mon Sep 17 00:00:00 2001 From: srstack Date: Mon, 10 Jan 2022 12:10:03 +0800 Subject: [PATCH 3/4] perfect tips --- pkg/cluster/operation/check.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index 13b800d8bb..bcbec98f11 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -225,10 +225,7 @@ func checkNTP(ntpInfo *insight.TimeStat) *CheckResult { // check if time offset greater than +- 500ms if math.Abs(ntpInfo.Offset) >= 500 { result.Err = fmt.Errorf("time offset %fms too high", ntpInfo.Offset) - } else { - result.Msg = fmt.Sprintf("time offset is %fms", ntpInfo.Offset) } - return result } @@ -245,10 +242,7 @@ func checkChrony(chronyInfo *insight.ChronyStat) *CheckResult { // check if time offset greater than +- 500ms if math.Abs(chronyInfo.LastOffset) >= 500 { result.Err = fmt.Errorf("time offset %fms too high", chronyInfo.LastOffset) - } else { - result.Msg = fmt.Sprintf("time offset is %fms", chronyInfo.LastOffset) } - return result } From d212365b9cf6fff968343fe2d50eb8b5f52c0faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qi=CE=BC=24hi=D0=AFu=C3=AD?= <39378935+srstack@users.noreply.github.com> Date: Mon, 10 Jan 2022 14:24:20 +0800 Subject: [PATCH 4/4] Update pkg/cluster/operation/check.go Co-authored-by: Allen Zhong --- pkg/cluster/operation/check.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/cluster/operation/check.go b/pkg/cluster/operation/check.go index bcbec98f11..d0c3b20e8c 100644 --- a/pkg/cluster/operation/check.go +++ b/pkg/cluster/operation/check.go @@ -235,7 +235,7 @@ func checkChrony(chronyInfo *insight.ChronyStat) *CheckResult { } if chronyInfo.LeapStatus == "none" { - zap.L().Info("The NTPd daemon may be not installed, skip.") + zap.L().Info("The Chrony daemon may be not installed, skip.") return result }