Commit ef521f35 authored by vrg0's avatar vrg0

5s延时监控门限可配置

parent 8c99c8ce
......@@ -4,6 +4,7 @@ import (
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"github.com/vrg0/go-common/logger"
"go.uber.org/zap/zapcore"
"strconv"
"sync"
"time"
)
......@@ -14,10 +15,11 @@ type Node struct {
}
type Delayed5s struct {
Server map[string]Node
Client map[string]Node
lock *sync.Mutex
save *logger.Logger
Server map[string]Node
Client map[string]Node
lock *sync.Mutex
save *logger.Logger
duration int
}
func NewDelayed5s() *Delayed5s {
......@@ -26,16 +28,24 @@ func NewDelayed5s() *Delayed5s {
savePath += "_delayed5s"
}
durationString := global.Config.GetOrDefault(global.NamespaceApplication, "delayed5s.duration", "1000000000")
durationInt, err := strconv.Atoi(durationString)
if err != nil {
durationInt = 1000000000
}
return &Delayed5s{
Server: make(map[string]Node),
Client: make(map[string]Node),
lock: new(sync.Mutex),
save: logger.New(savePath, zapcore.DebugLevel),
Server: make(map[string]Node),
Client: make(map[string]Node),
lock: new(sync.Mutex),
save: logger.New(savePath, zapcore.DebugLevel),
duration: durationInt,
}
}
func (d *Delayed5s) Run() {
d.save.Info("5s延时监控程序启动")
d.save.Info("监控门限:", d.duration, "us")
go func() {
for {
time.Sleep(time.Second * 30)
......@@ -65,7 +75,7 @@ func (d *Delayed5s) Run() {
}
//Duration单位微妙,转化为纳秒
if (clientNode.Points.Duration-serverNode.Points.Duration)*1e3 > int(1*time.Second) {
if (clientNode.Points.Duration-serverNode.Points.Duration)*1e3 > d.duration {
d.save.Info(clientNode.Points, serverNode.Points)
delete(d.Client, id)
delete(d.Server, id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment