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
d4eba168
Commit
d4eba168
authored
Dec 05, 2019
by
jingbo.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
生成分表
parent
4f5a2280
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
125 additions
and
5 deletions
+125
-5
regular_report.go
pkg/report-form/regular_report.go
+11
-0
report_form.go
pkg/report-form/report_form.go
+58
-5
service.go
pkg/report-form/service.go
+56
-0
No files found.
pkg/report-form/regular_report.go
View file @
d4eba168
...
...
@@ -74,6 +74,17 @@ func run(now time.Time, dir string) {
glog
.
Info
(
"每周总表报表完成:"
,
fileName
)
//分表
for
name
,
service
:=
range
sm
.
serviceMap
{
fileName
:=
dir
+
"/"
+
fileNamePrefix
+
"_"
+
name
+
"_week.txt"
if
!
util
.
Exists
(
fileName
)
{
body
:=
SubTableRun
(
service
)
if
err
:=
ioutil
.
WriteFile
(
fileName
,
[]
byte
(
body
),
0644
);
err
!=
nil
{
glog
.
Error
(
"报表写入文件失败:"
,
fileName
,
err
)
glog
.
Info
(
body
)
}
//发送给服务负责人
}
}
//TODO
}
...
...
pkg/report-form/report_form.go
View file @
d4eba168
...
...
@@ -32,8 +32,8 @@ func NewTable(name string, keys ...string) *Table {
func
strFormatLen
(
s
string
)
int
{
l
:=
0
for
i
:=
0
;
i
<
len
(
s
);
{
_
,
size
:=
utf8
.
DecodeRuneInString
(
s
[
i
:
])
if
size
!=
1
{
c
,
size
:=
utf8
.
DecodeRuneInString
(
s
[
i
:
])
if
size
!=
1
&&
c
!=
'µ'
{
l
+=
2
}
else
{
l
++
...
...
@@ -118,6 +118,59 @@ func (t *Table) AddRecord(values ...interface{}) error {
return
nil
}
//body := ServiceTableRun(service)
func
SubTableRun
(
s
*
Service
)
string
{
rtn
:=
new
(
strings
.
Builder
)
//标题
rtn
.
WriteString
(
" 服务健康状态表:"
+
s
.
Name
()
+
"
\n
"
)
//时间
rtn
.
WriteString
(
fmt
.
Sprintf
(
"时间:%s ~ %s
\n
"
,
s
.
startTime
.
Format
(
time
.
RFC3339
),
s
.
endTime
.
Format
(
time
.
RFC3339
)))
//访问量
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%v 总响应时间:%v 平均响应时间:%v
\n
"
,
s
.
GetCount
(),
s
.
GetSumDuration
(),
s
.
GetAverageDuration
()))
//基本信息
rtn
.
WriteString
(
fmt
.
Sprintf
(
"常规CPU使用率:%v 峰值CPU使用率:%v 峰值内存使用率:%v 峰值硬盘使用率:%v
\n\n
"
,
s
.
GetRemoveN100MaxCpu
(),
s
.
GetMaxCpu
(),
s
.
GetMaxMem
(),
s
.
GetMaxDisk
()))
//接口中位响应时间排行
medianDurationTable
:=
NewTable
(
"接口中位响应时间排行"
,
"duration"
,
"path"
,
"traffic_volume"
)
plist
:=
s
.
GetMedianDurationPathList
()
for
_
,
p
:=
range
plist
{
_
=
medianDurationTable
.
AddRecord
(
p
.
GetMedianDuration
(),
p
.
GetPath
(),
p
.
GetCount
())
}
rtn
.
WriteString
(
medianDurationTable
.
ToString
())
rtn
.
WriteString
(
"
\n
"
)
//接口平均响应时间排行
averageDurationTable
:=
NewTable
(
"接口平均响应时间排行"
,
"duration"
,
"path"
,
"traffic_volume"
)
plist
=
s
.
GetAverageDurationPathList
()
for
_
,
p
:=
range
plist
{
_
=
averageDurationTable
.
AddRecord
(
p
.
GetAverageDuration
(),
p
.
GetPath
(),
p
.
GetCount
())
}
rtn
.
WriteString
(
averageDurationTable
.
ToString
())
rtn
.
WriteString
(
"
\n
"
)
//接口峰值响应时间排行
maxDurationTable
:=
NewTable
(
"接口峰值响应时间排行"
,
"duration"
,
"path"
,
"timestamp"
,
"trace_id"
)
plist
=
s
.
GetAverageDurationPathList
()
for
_
,
p
:=
range
plist
{
maxPoint
:=
p
.
GetMaxDurationTracePoint
()
_
=
maxDurationTable
.
AddRecord
(
maxPoint
.
Duration
,
maxPoint
.
Path
,
maxPoint
.
Timestamp
,
maxPoint
.
TraceId
)
}
rtn
.
WriteString
(
maxDurationTable
.
ToString
())
rtn
.
WriteString
(
"
\n
"
)
return
rtn
.
String
()
}
//总表报表
func
GeneralTableRun
(
sm
*
ServiceMap
)
string
{
const
(
cpuMin
=
1
...
...
@@ -149,7 +202,7 @@ func GeneralTableRun(sm *ServiceMap) string {
rtn
.
WriteString
(
"
\n
"
)
//服务响应时间中位值排行
medianTable
:=
NewTable
(
"服务接口
响应时间中位值
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"traffic_volume"
)
medianTable
:=
NewTable
(
"服务接口
中位响应时间
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"traffic_volume"
)
medianList
:=
sm
.
GetMedianDurationPathList
()
for
_
,
m
:=
range
medianList
{
_
=
medianTable
.
AddRecord
(
m
.
GetMedianDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
(),
m
.
GetCount
())
...
...
@@ -158,7 +211,7 @@ func GeneralTableRun(sm *ServiceMap) string {
rtn
.
WriteString
(
"
\n
"
)
//服务响应时间平均值排行
averageTable
:=
NewTable
(
"服务接口
响应时间平均值
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"traffic_volume"
)
averageTable
:=
NewTable
(
"服务接口
平均响应时间
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"traffic_volume"
)
averageList
:=
sm
.
GetAverageDurationPathList
()
for
_
,
m
:=
range
averageList
{
_
=
averageTable
.
AddRecord
(
m
.
GetAverageDuration
(),
m
.
GetServiceName
(),
m
.
GetPath
(),
m
.
GetCount
())
...
...
@@ -167,7 +220,7 @@ func GeneralTableRun(sm *ServiceMap) string {
rtn
.
WriteString
(
"
\n
"
)
//响应时间最长的请求排行
maxTable
:=
NewTable
(
"服务接口
响应时间最高值
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"timestamp"
,
"trace_id"
)
maxTable
:=
NewTable
(
"服务接口
最高响应时间
排行"
,
"duration"
,
"sys_name"
,
"path"
,
"timestamp"
,
"trace_id"
)
maxList
:=
sm
.
GetMaxDurationTracePointList
()
for
_
,
m
:=
range
maxList
{
_
=
maxTable
.
AddRecord
(
m
.
Duration
,
m
.
ServiceName
,
m
.
Path
,
m
.
Timestamp
,
m
.
TraceId
)
...
...
pkg/report-form/service.go
View file @
d4eba168
...
...
@@ -3,6 +3,7 @@ package report_form
import
(
"fmt"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"sort"
"strings"
"time"
)
...
...
@@ -194,6 +195,61 @@ func (s *Service) initDuration() {
}
}
//获取 MaxDuration Path 排行
func
(
s
*
Service
)
GetAverageDurationPathList
()
[]
*
Path
{
rtn
:=
make
([]
*
Path
,
0
)
for
_
,
path
:=
range
s
.
pathMap
{
rtn
=
append
(
rtn
,
path
)
}
sort
.
Slice
(
rtn
,
func
(
i
,
j
int
)
bool
{
if
rtn
[
i
]
.
GetAverageDuration
()
>
rtn
[
j
]
.
GetAverageDuration
()
{
return
true
}
return
false
})
return
rtn
}
//获取 MedianDuration Path 排行
func
(
s
*
Service
)
GetMedianDurationPathList
()
[]
*
Path
{
rtn
:=
make
([]
*
Path
,
0
)
for
_
,
path
:=
range
s
.
pathMap
{
rtn
=
append
(
rtn
,
path
)
}
sort
.
Slice
(
rtn
,
func
(
i
,
j
int
)
bool
{
if
rtn
[
i
]
.
GetMedianDuration
()
>
rtn
[
j
]
.
GetMedianDuration
()
{
return
true
}
return
false
})
return
rtn
}
//获取 MaxDuration Path 排行
func
(
s
*
Service
)
GetMaxDurationPathList
()
[]
*
Path
{
rtn
:=
make
([]
*
Path
,
0
)
for
_
,
path
:=
range
s
.
pathMap
{
rtn
=
append
(
rtn
,
path
)
}
sort
.
Slice
(
rtn
,
func
(
i
,
j
int
)
bool
{
if
rtn
[
i
]
.
GetMaxDurationTracePoint
()
.
Duration
>
rtn
[
j
]
.
GetMaxDurationTracePoint
()
.
Duration
{
return
true
}
return
false
})
return
rtn
}
//获取总访问时间
func
(
s
*
Service
)
GetSumDuration
()
time
.
Duration
{
return
s
.
sumDuration
...
...
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