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
f97a304a
Commit
f97a304a
authored
Feb 25, 2020
by
vrg0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path_list OK
parent
b5f98256
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
150 additions
and
1 deletion
+150
-1
delayed5s.go
pkg/points/delayed5s.go
+0
-1
path_statistics.go
pkg/points/path_statistics.go
+142
-0
trace_msg.go
pkg/points/trace_msg.go
+8
-0
No files found.
pkg/points/delayed5s.go
View file @
f97a304a
...
...
@@ -90,7 +90,6 @@ func (d *Delayed5s) Run() {
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
}
...
...
pkg/points/path_statistics.go
0 → 100644
View file @
f97a304a
package
points
import
(
"fmt"
"sync"
)
//服务A 的 X 接口 被 那些服务访问? 那些节点访问
type
PathNode
struct
{
ServiceName
string
Path
string
RemoteServiceMap
map
[
string
]
struct
{}
}
func
NewPathNode
(
path
string
,
serviceName
string
)
PathNode
{
return
PathNode
{
Path
:
path
,
ServiceName
:
serviceName
,
RemoteServiceMap
:
make
(
map
[
string
]
struct
{}),
}
}
type
ServiceNode
struct
{
ServiceName
string
PathMap
map
[
string
]
PathNode
IpMap
map
[
string
]
struct
{}
}
func
NewServiceNode
(
serviceName
string
)
ServiceNode
{
return
ServiceNode
{
ServiceName
:
serviceName
,
PathMap
:
make
(
map
[
string
]
PathNode
),
IpMap
:
make
(
map
[
string
]
struct
{}),
}
}
type
Statistics
struct
{
ServiceMap
map
[
string
]
ServiceNode
lock
*
sync
.
Mutex
}
func
(
s
*
Statistics
)
String
()
string
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
rtn
:=
""
for
_
,
service
:=
range
s
.
ServiceMap
{
rtn
+=
fmt
.
Sprintf
(
"%s: "
,
service
.
ServiceName
)
for
ip
:=
range
service
.
IpMap
{
rtn
+=
ip
+
" "
}
rtn
+=
"
\n
"
for
_
,
path
:=
range
service
.
PathMap
{
rtn
+=
path
.
Path
+
" "
for
remoteService
:=
range
path
.
RemoteServiceMap
{
rtn
+=
remoteService
+
" "
}
rtn
+=
"
\n
"
}
rtn
+=
"
\n
"
}
return
rtn
}
func
NewStatistics
()
*
Statistics
{
return
&
Statistics
{
ServiceMap
:
make
(
map
[
string
]
ServiceNode
),
lock
:
new
(
sync
.
Mutex
),
}
}
func
(
s
*
Statistics
)
addServer
(
local
localEndpoint
,
remote
remoteEndpoint
,
tag
tags
)
{
if
_
,
ok
:=
s
.
ServiceMap
[
local
.
ServiceName
];
!
ok
{
s
.
ServiceMap
[
local
.
ServiceName
]
=
NewServiceNode
(
local
.
ServiceName
)
}
if
_
,
ok
:=
s
.
ServiceMap
[
local
.
ServiceName
]
.
IpMap
[
local
.
Ipv4
];
!
ok
{
s
.
ServiceMap
[
local
.
ServiceName
]
.
IpMap
[
local
.
Ipv4
]
=
struct
{}{}
}
path
:=
tag
.
HttpMethod
+
"-"
+
tag
.
HttpPath
_
,
ok
:=
s
.
ServiceMap
[
local
.
ServiceName
]
.
PathMap
[
path
]
if
!
ok
{
s
.
ServiceMap
[
local
.
ServiceName
]
.
PathMap
[
path
]
=
NewPathNode
(
path
,
local
.
ServiceName
)
}
}
func
(
s
*
Statistics
)
addClient
(
local
localEndpoint
,
remote
remoteEndpoint
,
tag
tags
)
{
for
_
,
service
:=
range
s
.
ServiceMap
{
for
ip
:=
range
service
.
IpMap
{
if
ip
==
remote
.
Ipv4
{
//添加服务
path
:=
tag
.
HttpMethod
+
"-"
+
tag
.
HttpPath
if
_
,
ok
:=
service
.
PathMap
[
path
];
!
ok
{
service
.
PathMap
[
path
]
=
NewPathNode
(
path
,
service
.
ServiceName
)
}
//service.PathMap[path].
service
.
PathMap
[
path
]
.
RemoteServiceMap
[
local
.
ServiceName
]
=
struct
{}{}
}
}
}
}
func
(
s
*
Statistics
)
AddNode
(
point
TraceMsg
)
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
switch
point
.
Kind
{
case
"SERVER"
:
s
.
addServer
(
point
.
LocalEndpoint
,
point
.
RemoteEndpoint
,
point
.
Tags
)
case
"CLIENT"
:
s
.
addClient
(
point
.
LocalEndpoint
,
point
.
RemoteEndpoint
,
point
.
Tags
)
default
:
//位置类型,不处理
}
}
/*
type PathNode struct {
ServiceName string
Path string
SrcServiceList map[string]struct{}
SrcNodeIp map[string]struct{}
}
type Statistics struct {
PathMap map[string]PathNode
lock *sync.Mutex
}
func NewStatistics() *Statistics {
return &Statistics{
PathMap: make(map[string]PathNode),
lock: new(sync.Mutex),
}
}
*/
pkg/points/trace_msg.go
View file @
f97a304a
...
...
@@ -2,8 +2,10 @@ package points
import
(
"encoding/json"
api_server
"git.quantgroup.cn/DevOps/enoch/pkg/api-server"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"github.com/influxdata/influxdb/client/v2"
"github.com/valyala/fasthttp"
"github.com/vrg0/go-common/util"
"strings"
"time"
...
...
@@ -72,15 +74,21 @@ func TraceBaseInfoToPoint(data []byte) ([]*client.Point, error) {
}
var
d5sObj
=
NewDelayed5s
()
var
pathObj
=
NewStatistics
()
func
init
()
{
d5sObj
.
Run
()
api_server
.
HandlerFunc
(
api_server
.
GET
,
"/path/list"
,
func
(
ctx
*
fasthttp
.
RequestCtx
)
{
ctx
.
Response
.
SetBodyString
(
pathObj
.
String
())
})
}
//失败返回nil
func
buildTraceInfluxMsg
(
traceInfo
TraceMsg
)
*
client
.
Point
{
//临时:统计5s延时问题
d5sObj
.
AddNode
(
traceInfo
)
//临时:统计服务间访问
pathObj
.
AddNode
(
traceInfo
)
if
traceInfo
.
Kind
!=
"SERVER"
{
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