From c5d6d100348933b70b64d3e6e5f5d79ffc9f3bd0 Mon Sep 17 00:00:00 2001 From: xiepaup Date: Fri, 13 Dec 2024 11:46:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(other):=20DBHA-=E5=A2=9E=E5=8A=A0=E8=80=97?= =?UTF-8?q?=E6=97=B6=E6=97=A5=E5=BF=97=20#8594?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/dbha/ha-module/agent/monitor_agent.go | 9 ++++++++- .../dbha/ha-module/dbmodule/redis/predixy_detect.go | 4 +++- .../common/dbha/ha-module/dbmodule/redis/redis_base.go | 2 ++ .../common/dbha/ha-module/dbmodule/redis/redis_detect.go | 3 ++- .../dbha/ha-module/dbmodule/redis/rediscluster_detect.go | 3 ++- .../dbha/ha-module/dbmodule/redis/tendisplus_detect.go | 3 ++- .../dbha/ha-module/dbmodule/redis/twemproxy_detect.go | 4 +++- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/dbm-services/common/dbha/ha-module/agent/monitor_agent.go b/dbm-services/common/dbha/ha-module/agent/monitor_agent.go index 229a30417e..24200836da 100644 --- a/dbm-services/common/dbha/ha-module/agent/monitor_agent.go +++ b/dbm-services/common/dbha/ha-module/agent/monitor_agent.go @@ -100,6 +100,7 @@ func NewMonitorAgent(conf *config.Config, detectType string) (*MonitorAgent, err // report agent's heartbeat info. func (a *MonitorAgent) Process(instances map[string]dbutil.DataBaseDetect) { var wg sync.WaitGroup + startTime := time.Now().Unix() sem := make(chan struct{}, a.MaxConcurrency) // 创建一个有缓冲的通道,容量为 maxConcurrency log.Logger.Debugf("[%s] need to detect instances number:%d", a.DetectType, len(a.DBInstance)) for _, ins := range instances { @@ -112,6 +113,8 @@ func (a *MonitorAgent) Process(instances map[string]dbutil.DataBaseDetect) { }(ins) } wg.Wait() + log.Logger.Debugf("[%s] detected instances number:%d ,cost: %d", + a.DetectType, len(a.DBInstance), time.Now().Unix()-startTime) a.DetectPostProcess() time.Sleep(time.Second) } @@ -146,6 +149,7 @@ func (a *MonitorAgent) RefreshInstanceCache() { // DoDetectSingle do single instance detect func (a *MonitorAgent) DoDetectSingle(ins dbutil.DataBaseDetect) { + startTime := time.Now().Unix() ip, port := ins.GetAddress() log.Logger.Debugf("begin detect [%s] instance:%s#%d", ins.GetClusterType(), ip, port) err := ins.Detection() @@ -153,7 +157,8 @@ func (a *MonitorAgent) DoDetectSingle(ins dbutil.DataBaseDetect) { log.Logger.Warnf("Detect db instance failed. ins:[%s:%d],dbType:%s status:%s,DeteckErr=%s", ip, port, ins.GetDBType(), ins.GetStatus(), err.Error()) } - log.Logger.Debugf("finish detect [%s] instance:%s#%d", ins.GetClusterType(), ip, port) + log.Logger.Debugf("finish detect [%s] instance:%s#%d , cost: %d", ins.GetClusterType(), + ip, port, time.Now().Unix()-startTime) a.reportMonitor(ins, err) if ins.NeedReportAgent() { @@ -175,6 +180,8 @@ func (a *MonitorAgent) DoDetectSingle(ins dbutil.DataBaseDetect) { err.Error(), ip, port, ins.GetDBType(), ins.GetStatus()) } } + log.Logger.Debugf("finish report [%s] instance:%s#%d , cost: %d", ins.GetClusterType(), + ip, port, time.Now().Unix()-startTime) } // DetectPostProcess post agent heartbeat diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go index b09d1c6310..b5f2fd0e26 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/predixy_detect.go @@ -3,6 +3,7 @@ package redis import ( "encoding/json" "fmt" + "time" "dbm-services/common/dbha/ha-module/client" "dbm-services/common/dbha/ha-module/config" @@ -18,9 +19,10 @@ type PredixyDetectInstance struct { // Detection detect predixy instance func (ins *PredixyDetectInstance) Detection() error { + startTime := time.Now().Unix() err := ins.DoPredixyDetection() + log.Logger.Debugf("finsh detect instance [%s#%d] ,cost: %d", ins.Ip, ins.Port, time.Now().Unix()-startTime) if err == nil && ins.Status == constvar.DBCheckSuccess { - log.Logger.Debugf("predixy check ok and return ok . %s#%d", ins.Ip, ins.Port) return nil } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go index 0aa64f785b..c7e49b779a 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_base.go @@ -70,6 +70,8 @@ type RedisProxySwitchInfo struct { // CheckSSH redis do ssh check func (ins *RedisDetectBase) CheckSSH() error { + sshStart := time.Now().Unix() + defer log.Logger.Debugf("finish ssh detect [%s] , cost: %d", ins.Ip, time.Now().Unix()-sshStart) touchFile := fmt.Sprintf("%s_%s_%d", ins.SshInfo.Dest, "agent", ins.Port) touchStr := fmt.Sprintf("touch %s && if [ -d \"/data1/dbha\" ]; then touch /data1/dbha/%s ; fi "+ diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go index 6e58b7e97a..91a2e1e573 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/redis_detect.go @@ -20,9 +20,10 @@ type RedisDetectInstance struct { // Detection detection api func (ins *RedisDetectInstance) Detection() error { + startTime := time.Now().Unix() err := ins.DoRedisDetection() + log.Logger.Debugf("finsh detect instance [%s#%d] ,cost: %d", ins.Ip, ins.Port, time.Now().Unix()-startTime) if err == nil && ins.Status == constvar.DBCheckSuccess { - log.Logger.Debugf("redis check ok and return ok . %s#%d", ins.Ip, ins.Port) return nil } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_detect.go index 00b6be16b6..f8f5b09074 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/rediscluster_detect.go @@ -20,9 +20,10 @@ type RedisClusterDetectInstance struct { // Detection detect tendisplus instance func (ins *RedisClusterDetectInstance) Detection() error { + startTime := time.Now().Unix() err := ins.DoTendisDetection() + log.Logger.Debugf("finsh detect instance [%s#%d] ,cost: %d", ins.Ip, ins.Port, time.Now().Unix()-startTime) if err == nil && ins.Status == constvar.DBCheckSuccess { - log.Logger.Debugf("redisC check ok and return ok . %s#%d", ins.Ip, ins.Port) return nil } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go index ad4f713b4f..1280e6cab7 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/tendisplus_detect.go @@ -20,9 +20,10 @@ type TendisplusDetectInstance struct { // Detection detect tendisplus instance func (ins *TendisplusDetectInstance) Detection() error { + startTime := time.Now().Unix() err := ins.DoTendisDetection() + log.Logger.Debugf("finsh detect instance [%s#%d] ,cost: %d", ins.Ip, ins.Port, time.Now().Unix()-startTime) if err == nil && ins.Status == constvar.DBCheckSuccess { - log.Logger.Debugf("tendisplus check ok and return ok . %s#%d", ins.Ip, ins.Port) return nil } diff --git a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go index 5e6c56834c..b3db8fcccf 100644 --- a/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go +++ b/dbm-services/common/dbha/ha-module/dbmodule/redis/twemproxy_detect.go @@ -3,6 +3,7 @@ package redis import ( "encoding/json" "fmt" + "time" "dbm-services/common/dbha/ha-module/client" "dbm-services/common/dbha/ha-module/config" @@ -18,9 +19,10 @@ type TwemproxyDetectInstance struct { // Detection detect twemproxy instance func (ins *TwemproxyDetectInstance) Detection() error { + startTime := time.Now().Unix() err := ins.DoTwemproxyDetection() + log.Logger.Debugf("finsh detect instance [%s#%d] ,cost: %d", ins.Ip, ins.Port, time.Now().Unix()-startTime) if err == nil && ins.Status == constvar.DBCheckSuccess { - log.Logger.Debugf("Twemproxy check ok and return ok . %s#%d", ins.Ip, ins.Port) return nil }