Skip to content

Commit

Permalink
feat(other): DBHA-增加耗时日志 #8594
Browse files Browse the repository at this point in the history
  • Loading branch information
xiepaup authored and iSecloud committed Dec 13, 2024
1 parent 2bb4e8d commit c5d6d10
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion dbm-services/common/dbha/ha-module/agent/monitor_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -146,14 +149,16 @@ 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()
if err != nil {
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() {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}

Expand Down

0 comments on commit c5d6d10

Please sign in to comment.