Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
enoch
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
enoch
Commits
07e09137
Commit
07e09137
authored
Feb 21, 2020
by
vrg0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
5s延时问题监控(初版)
parent
e9a989da
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
106 additions
and
3 deletions
+106
-3
go.mod
go.mod
+1
-0
global.go
pkg/global/global.go
+5
-3
delayed5s.go
pkg/points/delayed5s.go
+91
-0
trace_msg.go
pkg/points/trace_msg.go
+9
-0
No files found.
go.mod
View file @
07e09137
...
@@ -14,6 +14,7 @@ require (
...
@@ -14,6 +14,7 @@ require (
github.com/valyala/fasthttp v1.6.0
github.com/valyala/fasthttp v1.6.0
github.com/vrg0/go-common v0.0.0-20191213082238-e4e6080702f1
github.com/vrg0/go-common v0.0.0-20191213082238-e4e6080702f1
go.uber.org/zap v1.13.0
go.uber.org/zap v1.13.0
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
)
)
pkg/global/global.go
View file @
07e09137
...
@@ -48,6 +48,8 @@ var (
...
@@ -48,6 +48,8 @@ var (
ConsulDc
=
""
ConsulDc
=
""
ConsulAddress
=
""
ConsulAddress
=
""
ReportFormDir
=
""
ReportFormDir
=
""
LogPath
=
""
LogLevel
=
zapcore
.
DebugLevel
HttpPort
=
9091
HttpPort
=
9091
)
)
...
@@ -92,9 +94,9 @@ func init() {
...
@@ -92,9 +94,9 @@ func init() {
}
}
//初始化日志
//初始化日志
logPath
:
=
Config
.
GetOrDefault
(
NamespaceApplication
,
"log.path"
,
"/dev/stdout"
)
LogPath
=
Config
.
GetOrDefault
(
NamespaceApplication
,
"log.path"
,
"/dev/stdout"
)
logLevel
:
=
getLoggerLevel
(
Config
.
GetOrDefault
(
NamespaceApplication
,
"log.level"
,
"info"
))
LogLevel
=
getLoggerLevel
(
Config
.
GetOrDefault
(
NamespaceApplication
,
"log.level"
,
"info"
))
Logger
=
logger
.
New
(
logPath
,
l
ogLevel
)
Logger
=
logger
.
New
(
LogPath
,
L
ogLevel
)
//初始化kafka
//初始化kafka
kafkaLogger
:=
Logger
.
GetStandardLogger
()
kafkaLogger
:=
Logger
.
GetStandardLogger
()
...
...
pkg/points/delayed5s.go
0 → 100644
View file @
07e09137
package
points
import
(
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"github.com/vrg0/go-common/logger"
"go.uber.org/zap/zapcore"
"sync"
"time"
)
type
Node
struct
{
CreateTime
time
.
Time
Points
TraceMsg
}
type
Delayed5s
struct
{
Server
map
[
string
]
Node
Client
map
[
string
]
Node
lock
*
sync
.
Mutex
save
*
logger
.
Logger
}
func
NewDelayed5s
()
*
Delayed5s
{
savePath
:=
global
.
LogPath
if
savePath
!=
"/dev/stdout"
{
savePath
+=
"_delayed5s"
}
return
&
Delayed5s
{
Server
:
make
(
map
[
string
]
Node
),
Client
:
make
(
map
[
string
]
Node
),
lock
:
new
(
sync
.
Mutex
),
save
:
logger
.
New
(
savePath
,
zapcore
.
DebugLevel
),
}
}
func
(
d
*
Delayed5s
)
Run
()
{
d
.
save
.
Info
(
"5s延时监控程序启动"
)
go
func
()
{
for
{
time
.
Sleep
(
time
.
Second
*
30
)
now
:=
time
.
Now
()
d
.
lock
.
Lock
()
//1、删除过期的client
for
id
,
node
:=
range
d
.
Client
{
if
now
.
Unix
()
>
node
.
CreateTime
.
Add
(
time
.
Minute
*
10
)
.
Unix
()
{
delete
(
d
.
Client
,
id
)
}
}
//2、删除过期的server
for
id
,
node
:=
range
d
.
Server
{
if
now
.
Unix
()
>
node
.
CreateTime
.
Add
(
time
.
Minute
*
10
)
.
Unix
()
{
delete
(
d
.
Server
,
id
)
}
}
//3、记录&删除延时请求
for
id
,
clientNode
:=
range
d
.
Client
{
serverNode
,
ok
:=
d
.
Server
[
id
]
if
!
ok
{
continue
}
if
clientNode
.
Points
.
Duration
-
serverNode
.
Points
.
Duration
>
int
(
1
*
time
.
Second
)
{
d
.
save
.
Info
(
clientNode
.
Points
,
serverNode
.
Points
)
delete
(
d
.
Client
,
id
)
delete
(
d
.
Server
,
id
)
}
}
d
.
lock
.
Unlock
()
}
}()
}
func
(
d
*
Delayed5s
)
AddNode
(
point
TraceMsg
)
{
d
.
lock
.
Lock
()
defer
d
.
lock
.
Unlock
()
switch
point
.
Kind
{
case
"SERVER"
:
d
.
Server
[
point
.
Id
]
=
Node
{
time
.
Now
(),
point
}
case
"CLIENT"
:
d
.
Client
[
point
.
Id
]
=
Node
{
time
.
Now
(),
point
}
default
:
//位置类型,不处理
}
}
pkg/points/trace_msg.go
View file @
07e09137
...
@@ -71,8 +71,17 @@ func TraceBaseInfoToPoint(data []byte) ([]*client.Point, error) {
...
@@ -71,8 +71,17 @@ func TraceBaseInfoToPoint(data []byte) ([]*client.Point, error) {
return
rtn
,
nil
return
rtn
,
nil
}
}
var
d5sObj
=
NewDelayed5s
()
func
init
()
{
d5sObj
.
Run
()
}
//失败返回nil
//失败返回nil
func
buildTraceInfluxMsg
(
traceInfo
TraceMsg
)
*
client
.
Point
{
func
buildTraceInfluxMsg
(
traceInfo
TraceMsg
)
*
client
.
Point
{
//临时:统计5s延时问题
d5sObj
.
AddNode
(
traceInfo
)
if
traceInfo
.
Kind
!=
"SERVER"
{
if
traceInfo
.
Kind
!=
"SERVER"
{
return
nil
return
nil
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment