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
1e31f279
Commit
1e31f279
authored
Nov 27, 2019
by
jingbo.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
临时
parent
9c5806e6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
22 deletions
+77
-22
report_form.go
pkg/report-form/report_form.go
+45
-0
report_form_test.go
pkg/report-form/report_form_test.go
+7
-0
service.go
pkg/report-form/service.go
+22
-19
service_map_test.go
pkg/report-form/service_map_test.go
+3
-3
No files found.
pkg/report-form/report_form.go
0 → 100644
View file @
1e31f279
package
report_form
import
(
"fmt"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"time"
)
func
Run
()
{
now
:=
time
.
Now
()
startTime
:=
now
.
Add
(
-
1
*
time
.
Duration
(
now
.
Hour
())
*
time
.
Hour
)
startTime
=
startTime
.
Add
(
-
1
*
time
.
Duration
(
now
.
Minute
())
*
time
.
Minute
)
startTime
=
startTime
.
Add
(
-
1
*
time
.
Duration
(
now
.
Second
())
*
time
.
Second
)
startTime
=
startTime
.
Add
(
-
1
*
time
.
Duration
(
now
.
Nanosecond
()))
startTime
=
startTime
.
AddDate
(
0
,
0
,
-
7
)
endTime
:=
startTime
.
AddDate
(
0
,
0
,
7
)
glog
.
Info
(
"startTime:"
,
startTime
.
UnixNano
(),
" endTime:"
,
endTime
.
UnixNano
())
sm
:=
NewServiceMap
(
startTime
,
endTime
)
fmt
.
Println
(
sm
.
GetCount
())
/*
t.Log("访问量:", sm.GetCount())
t.Log("总访问时间:", sm.GetSumDuration())
t.Log("总平均访问时间:", sm.GetAverageDuration())
t.Log("------------------median-------------------")
medianList := sm.GetMedianDurationPathList()
t.Log("服务数量:", len(medianList))
for _, m := range medianList {
t.Log(m.GetMedianDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
}
t.Log("------------------average------------------")
averageList := sm.GetAverageDurationPathList()
t.Log("服务数量:", len(averageList))
for _, m := range averageList {
t.Log(m.GetAverageDuration(), m.GetServiceName(), m.GetPath(), m.GetCount())
}
t.Log("------------------max----------------------")
maxList := sm.GetMaxDurationTracePointList()
t.Log("服务数量:", len(maxList))
for _, m := range maxList {
t.Log(m.Duration, m.ServiceName, m.Path, m.Timestamp, m.TraceId)
}
*/
}
pkg/report-form/report_form_test.go
0 → 100644
View file @
1e31f279
package
report_form
import
"testing"
func
TestRun
(
t
*
testing
.
T
)
{
Run
()
}
pkg/report-form/service.go
View file @
1e31f279
...
@@ -7,6 +7,10 @@ import (
...
@@ -7,6 +7,10 @@ import (
"time"
"time"
)
)
const
(
MinCount
=
64
)
type
Service
struct
{
type
Service
struct
{
name
string
//服务名称
name
string
//服务名称
startTime
time
.
Time
//开始时间
startTime
time
.
Time
//开始时间
...
@@ -115,25 +119,24 @@ func (s *Service) initDuration() {
...
@@ -115,25 +119,24 @@ func (s *Service) initDuration() {
}
}
s
.
averageDuration
=
s
.
sumDuration
/
time
.
Duration
(
s
.
count
)
s
.
averageDuration
=
s
.
sumDuration
/
time
.
Duration
(
s
.
count
)
if
len
(
s
.
pathMap
)
!=
0
{
medianMax
:=
time
.
Duration
(
-
99999
)
medianMax
:=
time
.
Duration
(
-
99999
)
averageMax
:=
time
.
Duration
(
-
99999
)
averageMax
:=
time
.
Duration
(
-
99999
)
maxDuration
:=
time
.
Duration
(
-
99999
)
maxDuration
:=
time
.
Duration
(
-
99999
)
for
_
,
pathObj
:=
range
s
.
pathMap
{
for
_
,
pathObj
:=
range
s
.
pathMap
{
if
pathObj
.
GetMedianDuration
()
>
medianMax
{
if
pathObj
.
GetCount
()
>
MinCount
&&
pathObj
.
GetMedianDuration
()
>
medianMax
{
s
.
maxMedianPath
=
pathObj
s
.
maxMedianPath
=
pathObj
medianMax
=
pathObj
.
GetMedianDuration
()
medianMax
=
pathObj
.
GetMedianDuration
()
}
}
if
pathObj
.
GetAverageDuration
()
>
averageMax
{
if
pathObj
.
GetCount
()
>
MinCount
&&
pathObj
.
GetAverageDuration
()
>
averageMax
{
s
.
maxAveragePath
=
pathObj
s
.
maxAveragePath
=
pathObj
averageMax
=
pathObj
.
GetAverageDuration
()
averageMax
=
pathObj
.
GetAverageDuration
()
}
}
point
:=
pathObj
.
GetMaxDurationTracePoint
()
point
:=
pathObj
.
GetMaxDurationTracePoint
()
if
point
.
Duration
>
maxDuration
{
if
point
.
Duration
>
maxDuration
{
s
.
maxDurationTracePoint
=
&
point
s
.
maxDurationTracePoint
=
&
point
maxDuration
=
point
.
Duration
maxDuration
=
point
.
Duration
}
}
}
}
}
}
}
...
...
pkg/report-form/service_map_test.go
View file @
1e31f279
...
@@ -6,7 +6,7 @@ import (
...
@@ -6,7 +6,7 @@ import (
)
)
func
TestNewServiceMap
(
t
*
testing
.
T
)
{
func
TestNewServiceMap
(
t
*
testing
.
T
)
{
sm
:=
NewServiceMap
(
time
.
Now
()
.
Add
(
time
.
Hour
*
24
*-
1
),
time
.
Now
())
sm
:=
NewServiceMap
(
time
.
Now
()
.
Add
(
time
.
Hour
*
24
*-
7
),
time
.
Now
())
t
.
Log
(
"访问量:"
,
sm
.
GetCount
())
t
.
Log
(
"访问量:"
,
sm
.
GetCount
())
t
.
Log
(
"总访问时间:"
,
sm
.
GetSumDuration
())
t
.
Log
(
"总访问时间:"
,
sm
.
GetSumDuration
())
...
@@ -15,13 +15,13 @@ func TestNewServiceMap(t *testing.T) {
...
@@ -15,13 +15,13 @@ func TestNewServiceMap(t *testing.T) {
medianList
:=
sm
.
GetMedianDurationPathList
()
medianList
:=
sm
.
GetMedianDurationPathList
()
t
.
Log
(
"服务数量:"
,
len
(
medianList
))
t
.
Log
(
"服务数量:"
,
len
(
medianList
))
for
_
,
m
:=
range
medianList
{
for
_
,
m
:=
range
medianList
{
t
.
Log
(
m
.
GetMedianDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
())
t
.
Log
(
m
.
GetMedianDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
()
,
m
.
GetCount
()
)
}
}
t
.
Log
(
"------------------average------------------"
)
t
.
Log
(
"------------------average------------------"
)
averageList
:=
sm
.
GetAverageDurationPathList
()
averageList
:=
sm
.
GetAverageDurationPathList
()
t
.
Log
(
"服务数量:"
,
len
(
averageList
))
t
.
Log
(
"服务数量:"
,
len
(
averageList
))
for
_
,
m
:=
range
averageList
{
for
_
,
m
:=
range
averageList
{
t
.
Log
(
m
.
GetAverageDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
())
t
.
Log
(
m
.
GetAverageDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
()
,
m
.
GetCount
()
)
}
}
t
.
Log
(
"------------------max----------------------"
)
t
.
Log
(
"------------------max----------------------"
)
maxList
:=
sm
.
GetMaxDurationTracePointList
()
maxList
:=
sm
.
GetMaxDurationTracePointList
()
...
...
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