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
57b255fc
Commit
57b255fc
authored
Dec 24, 2019
by
jingbo.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
qps ok
parent
4e5c2fd4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
77 additions
and
40 deletions
+77
-40
path.go
pkg/report-form/path.go
+11
-6
report_form.go
pkg/report-form/report_form.go
+25
-23
service.go
pkg/report-form/service.go
+21
-6
service_map.go
pkg/report-form/service_map.go
+20
-5
No files found.
pkg/report-form/path.go
View file @
57b255fc
...
@@ -24,7 +24,7 @@ type Path struct {
...
@@ -24,7 +24,7 @@ type Path struct {
averageDuration
time
.
Duration
//平均响应时间
averageDuration
time
.
Duration
//平均响应时间
sumDuration
time
.
Duration
//总响应时间
sumDuration
time
.
Duration
//总响应时间
medianDuration
time
.
Duration
//中位响应时间
medianDuration
time
.
Duration
//中位响应时间
qps
float64
//每秒的访问量
maxqps
int
//每秒的访问量
variance
float64
//标准差
variance
float64
//标准差
maxDurationTracePoint
TracePoint
//最大响应时间的TracePoint
maxDurationTracePoint
TracePoint
//最大响应时间的TracePoint
}
}
...
@@ -50,10 +50,15 @@ func NewPath(serviceName string, path string, startTime time.Time, endTime time.
...
@@ -50,10 +50,15 @@ func NewPath(serviceName string, path string, startTime time.Time, endTime time.
//初始化qps
//初始化qps
func
(
p
*
Path
)
initQps
()
{
func
(
p
*
Path
)
initQps
()
{
if
p
.
startTime
.
Unix
()
>=
p
.
endTime
.
Unix
()
{
const
sqlMaxQps
=
"SELECT max(qps) as MAXQPS FROM "
+
return
"(SELECT count(
\"
traceId
\"
) AS qps FROM trace_info "
+
"WHERE sys_name = '%s' AND path = '%s' AND time >= %d AND time < %d "
+
"GROUP BY time(1s));"
sql
:=
fmt
.
Sprintf
(
sqlMaxQps
,
p
.
GetServiceName
(),
p
.
GetPath
(),
p
.
startTime
.
UnixNano
(),
p
.
endTime
.
UnixNano
())
maxqps
,
ok
:=
queryOneAndToInt
(
sql
)
if
ok
{
p
.
maxqps
=
maxqps
}
}
p
.
qps
=
float64
(
p
.
count
)
/
p
.
endTime
.
Sub
(
p
.
startTime
)
.
Seconds
()
}
}
//初始化访问次数
//初始化访问次数
...
@@ -194,8 +199,8 @@ func (p *Path) GetCount() int {
...
@@ -194,8 +199,8 @@ func (p *Path) GetCount() int {
}
}
//获取qps
//获取qps
func
(
p
*
Path
)
Get
Qps
()
float64
{
func
(
p
*
Path
)
Get
MaxQps
()
int
{
return
p
.
qps
return
p
.
max
qps
}
}
//获取总响应时间
//获取总响应时间
...
...
pkg/report-form/report_form.go
View file @
57b255fc
...
@@ -76,11 +76,12 @@ func (s *Service) ReportForm(long string) string {
...
@@ -76,11 +76,12 @@ func (s *Service) ReportForm(long string) string {
s
.
startTime
.
In
(
cstZone
)
.
Format
(
timeFormat
),
s
.
startTime
.
In
(
cstZone
)
.
Format
(
timeFormat
),
s
.
endTime
.
In
(
cstZone
)
.
Format
(
timeFormat
)),
s
.
endTime
.
In
(
cstZone
)
.
Format
(
timeFormat
)),
)
)
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%s 总响应时间:%s 平均响应时间:%s
QPS:%.2f
\n
"
,
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%s 总响应时间:%s 平均响应时间:%s
平均QPS:%.2f MAXQPS:%s
\n
"
,
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
s
.
GetSumDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
s
.
GetSumDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
s
.
GetAverageDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
s
.
GetAverageDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
s
.
GetQps
()),
s
.
GetQps
(),
hrn
(
s
.
GetMaxQps
())),
)
)
rtn
.
WriteString
(
fmt
.
Sprintf
(
"常规CPU使用率:%d%% 峰值CPU使用率:%d%% 平均内存使用率:%d%% 峰值内存使用率:%d%% 峰值硬盘使用率:%d%%
\n
"
,
rtn
.
WriteString
(
fmt
.
Sprintf
(
"常规CPU使用率:%d%% 峰值CPU使用率:%d%% 平均内存使用率:%d%% 峰值内存使用率:%d%% 峰值硬盘使用率:%d%%
\n
"
,
s
.
GetRemoveN100MaxCpu
(),
s
.
GetRemoveN100MaxCpu
(),
...
@@ -105,7 +106,7 @@ func (s *Service) ReportForm(long string) string {
...
@@ -105,7 +106,7 @@ func (s *Service) ReportForm(long string) string {
//服务接口中位响应时间TOP N
//服务接口中位响应时间TOP N
getMedianDurationPathList
:=
s
.
GetMedianDurationPathList
()
getMedianDurationPathList
:=
s
.
GetMedianDurationPathList
()
if
len
(
getMedianDurationPathList
)
!=
0
{
if
len
(
getMedianDurationPathList
)
!=
0
{
t
=
NewTable
(
fmt
.
Sprintf
(
"服务接口中位响应时间TOP%d"
,
topN
),
"排名"
,
"响应时间"
,
"接口"
,
"访问量"
,
"QPS"
)
t
=
NewTable
(
fmt
.
Sprintf
(
"服务接口中位响应时间TOP%d"
,
topN
),
"排名"
,
"响应时间"
,
"接口"
,
"访问量"
,
"
MAX
QPS"
)
for
i
,
p
:=
range
getMedianDurationPathList
{
for
i
,
p
:=
range
getMedianDurationPathList
{
color
:=
colorBlack
color
:=
colorBlack
if
p
.
GetMedianDuration
()
>
maxDuration
{
if
p
.
GetMedianDuration
()
>
maxDuration
{
...
@@ -117,7 +118,7 @@ func (s *Service) ReportForm(long string) string {
...
@@ -117,7 +118,7 @@ func (s *Service) ReportForm(long string) string {
fmt
.
Sprintf
(
"%v"
,
p
.
GetMedianDuration
()
/
1e6
*
1e6
),
//精确到微秒
fmt
.
Sprintf
(
"%v"
,
p
.
GetMedianDuration
()
/
1e6
*
1e6
),
//精确到微秒
p
.
GetPath
(),
p
.
GetPath
(),
hrn
(
p
.
GetCount
()),
hrn
(
p
.
GetCount
()),
fmt
.
Sprintf
(
"%.2f"
,
p
.
Get
Qps
()),
hrn
(
p
.
GetMax
Qps
()),
)
)
if
i
+
1
==
topN
{
if
i
+
1
==
topN
{
break
break
...
@@ -130,7 +131,7 @@ func (s *Service) ReportForm(long string) string {
...
@@ -130,7 +131,7 @@ func (s *Service) ReportForm(long string) string {
//服务接口平均响应时间TOP N
//服务接口平均响应时间TOP N
getAverageDurationPathList
:=
s
.
GetAverageDurationPathList
()
getAverageDurationPathList
:=
s
.
GetAverageDurationPathList
()
if
len
(
getAverageDurationPathList
)
!=
0
{
if
len
(
getAverageDurationPathList
)
!=
0
{
t
=
NewTable
(
fmt
.
Sprintf
(
"服务接口平均响应时间TOP%d"
,
topN
),
"排名"
,
"响应时间"
,
"接口"
,
"访问量"
,
"QPS"
)
t
=
NewTable
(
fmt
.
Sprintf
(
"服务接口平均响应时间TOP%d"
,
topN
),
"排名"
,
"响应时间"
,
"接口"
,
"访问量"
,
"
MAX
QPS"
)
for
i
,
p
:=
range
getAverageDurationPathList
{
for
i
,
p
:=
range
getAverageDurationPathList
{
color
:=
colorBlack
color
:=
colorBlack
if
p
.
GetAverageDuration
()
>
maxDuration
{
if
p
.
GetAverageDuration
()
>
maxDuration
{
...
@@ -142,7 +143,7 @@ func (s *Service) ReportForm(long string) string {
...
@@ -142,7 +143,7 @@ func (s *Service) ReportForm(long string) string {
fmt
.
Sprintf
(
"%v"
,
p
.
GetAverageDuration
()
/
1e6
*
1e6
),
//精确到微秒
fmt
.
Sprintf
(
"%v"
,
p
.
GetAverageDuration
()
/
1e6
*
1e6
),
//精确到微秒
p
.
GetPath
(),
p
.
GetPath
(),
hrn
(
p
.
GetCount
()),
hrn
(
p
.
GetCount
()),
fmt
.
Sprintf
(
"%.2f"
,
p
.
Get
Qps
()),
hrn
(
p
.
GetMax
Qps
()),
)
)
if
i
+
1
==
topN
{
if
i
+
1
==
topN
{
break
break
...
@@ -245,12 +246,13 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -245,12 +246,13 @@ func (sm *ServiceMap) ReportForm(long string) string {
sm
.
startTime
.
In
(
cstZone
)
.
Format
(
timeFormat
),
sm
.
startTime
.
In
(
cstZone
)
.
Format
(
timeFormat
),
sm
.
endTime
.
In
(
cstZone
)
.
Format
(
timeFormat
)),
sm
.
endTime
.
In
(
cstZone
)
.
Format
(
timeFormat
)),
)
)
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%s 总响应时间:%s 平均响应时间:%s
QPS:%.2f
\n
"
,
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%s 总响应时间:%s 平均响应时间:%s
平均QPS:%.2f MAXQPS:%s
\n
"
,
hrn
(
sm
.
GetCount
()),
hrn
(
sm
.
GetCount
()),
sm
.
GetSumDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
sm
.
GetSumDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
sm
.
GetAverageDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
sm
.
GetAverageDuration
()
/
1e6
*
1e6
,
//精度保留到毫秒
sm
.
GetQps
()),
sm
.
GetQps
(),
)
hrn
(
sm
.
GetMapQps
()),
))
url
:=
fmt
.
Sprintf
(
"http://%s:%d/show/%s/%s/%s
\n
"
,
global
.
LocalIp
,
global
.
HttpPort
,
url
:=
fmt
.
Sprintf
(
"http://%s:%d/show/%s/%s/%s
\n
"
,
global
.
LocalIp
,
global
.
HttpPort
,
long
,
sm
.
endTime
.
Add
(
time
.
Hour
*
-
24
)
.
In
(
cstZone
)
.
Format
(
"2006/01/02"
),
"all"
)
long
,
sm
.
endTime
.
Add
(
time
.
Hour
*
-
24
)
.
In
(
cstZone
)
.
Format
(
"2006/01/02"
),
"all"
)
rtn
.
WriteString
(
htmlStringA
(
url
,
url
))
rtn
.
WriteString
(
htmlStringA
(
url
,
url
))
...
@@ -267,7 +269,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -267,7 +269,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//服务平均响应时间排行
//服务平均响应时间排行
averageDurationServiceList
:=
sm
.
GetAverageDurationServiceList
()
averageDurationServiceList
:=
sm
.
GetAverageDurationServiceList
()
if
len
(
averageDurationServiceList
)
!=
0
{
if
len
(
averageDurationServiceList
)
!=
0
{
t
=
NewTable
(
"服务平均响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"访问量"
,
"QPS"
)
t
=
NewTable
(
"服务平均响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"访问量"
,
"
MAX
QPS"
)
for
i
,
s
:=
range
averageDurationServiceList
{
for
i
,
s
:=
range
averageDurationServiceList
{
color
:=
colorBlack
color
:=
colorBlack
if
s
.
GetAverageDuration
()
>
maxDuration
{
if
s
.
GetAverageDuration
()
>
maxDuration
{
...
@@ -281,7 +283,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -281,7 +283,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
//精度毫秒
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
//精度毫秒
htmlStringA
(
url
,
s
.
Name
()),
htmlStringA
(
url
,
s
.
Name
()),
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
fmt
.
Sprintf
(
"%.2f"
,
s
.
Get
Qps
()),
hrn
(
s
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -293,7 +295,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -293,7 +295,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//服务接口响应时间中位值排行
//服务接口响应时间中位值排行
getMedianDurationPathList
:=
sm
.
GetMedianDurationPathList
()
getMedianDurationPathList
:=
sm
.
GetMedianDurationPathList
()
if
len
(
getMedianDurationPathList
)
!=
0
{
if
len
(
getMedianDurationPathList
)
!=
0
{
t
=
NewTable
(
"服务接口中位响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"接口"
,
"访问量"
,
"QPS"
)
t
=
NewTable
(
"服务接口中位响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"接口"
,
"访问量"
,
"
MAX
QPS"
)
for
i
,
p
:=
range
getMedianDurationPathList
{
for
i
,
p
:=
range
getMedianDurationPathList
{
color
:=
colorBlack
color
:=
colorBlack
if
p
.
GetMedianDuration
()
>
maxDuration
{
if
p
.
GetMedianDuration
()
>
maxDuration
{
...
@@ -308,7 +310,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -308,7 +310,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
p
.
GetServiceName
()),
htmlStringA
(
url
,
p
.
GetServiceName
()),
p
.
GetPath
(),
p
.
GetPath
(),
hrn
(
p
.
GetCount
()),
hrn
(
p
.
GetCount
()),
fmt
.
Sprintf
(
"%.2f"
,
p
.
Get
Qps
()),
hrn
(
p
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -320,7 +322,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -320,7 +322,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//服务接口响应时间平均值排行
//服务接口响应时间平均值排行
getAverageDurationPathList
:=
sm
.
GetAverageDurationPathList
()
getAverageDurationPathList
:=
sm
.
GetAverageDurationPathList
()
if
len
(
getAverageDurationPathList
)
!=
0
{
if
len
(
getAverageDurationPathList
)
!=
0
{
t
=
NewTable
(
"服务接口平均响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"接口"
,
"访问量"
,
"QPS"
)
t
=
NewTable
(
"服务接口平均响应时间排行"
,
"排名"
,
"响应时间"
,
"服务名称"
,
"接口"
,
"访问量"
,
"
MAX
QPS"
)
for
i
,
p
:=
range
getAverageDurationPathList
{
for
i
,
p
:=
range
getAverageDurationPathList
{
color
:=
colorBlack
color
:=
colorBlack
if
p
.
GetAverageDuration
()
>
maxDuration
{
if
p
.
GetAverageDuration
()
>
maxDuration
{
...
@@ -335,7 +337,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -335,7 +337,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
p
.
GetServiceName
()),
htmlStringA
(
url
,
p
.
GetServiceName
()),
p
.
GetPath
(),
p
.
GetPath
(),
hrn
(
p
.
GetCount
()),
hrn
(
p
.
GetCount
()),
fmt
.
Sprintf
(
"%.2f"
,
p
.
Get
Qps
()),
hrn
(
p
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -376,7 +378,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -376,7 +378,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//常规cpu使用率排行
//常规cpu使用率排行
getRemoveN100MaxCpuServiceList
:=
sm
.
GetRemoveN100MaxCpuServiceList
()
getRemoveN100MaxCpuServiceList
:=
sm
.
GetRemoveN100MaxCpuServiceList
()
if
len
(
getRemoveN100MaxCpuServiceList
)
!=
0
{
if
len
(
getRemoveN100MaxCpuServiceList
)
!=
0
{
t
=
NewTable
(
"常规cpu使用率排行"
,
"排名"
,
"cpu使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"QPS"
)
t
=
NewTable
(
"常规cpu使用率排行"
,
"排名"
,
"cpu使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"
MAX
QPS"
)
for
i
,
s
:=
range
getRemoveN100MaxCpuServiceList
{
for
i
,
s
:=
range
getRemoveN100MaxCpuServiceList
{
if
s
.
GetRemoveN100MaxCpu
()
<
cpuMin
{
if
s
.
GetRemoveN100MaxCpu
()
<
cpuMin
{
break
break
...
@@ -394,7 +396,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -394,7 +396,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
s
.
Name
()),
htmlStringA
(
url
,
s
.
Name
()),
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%.2f"
,
s
.
Get
Qps
()),
hrn
(
s
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -406,7 +408,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -406,7 +408,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//峰值cpu使用率排行
//峰值cpu使用率排行
getMaxCpuServiceList
:=
sm
.
GetMaxCpuServiceList
()
getMaxCpuServiceList
:=
sm
.
GetMaxCpuServiceList
()
if
len
(
getMaxCpuServiceList
)
!=
0
{
if
len
(
getMaxCpuServiceList
)
!=
0
{
t
=
NewTable
(
"峰值cpu使用率排行"
,
"排名"
,
"cpu使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"QPS"
)
t
=
NewTable
(
"峰值cpu使用率排行"
,
"排名"
,
"cpu使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"
MAX
QPS"
)
for
i
,
s
:=
range
getMaxCpuServiceList
{
for
i
,
s
:=
range
getMaxCpuServiceList
{
if
s
.
GetMaxCpu
()
<
cpuMin
{
if
s
.
GetMaxCpu
()
<
cpuMin
{
break
break
...
@@ -424,7 +426,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -424,7 +426,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
s
.
Name
()),
htmlStringA
(
url
,
s
.
Name
()),
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%.2f"
,
s
.
Get
Qps
()),
hrn
(
s
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -436,7 +438,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -436,7 +438,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//平均内存使用率排行
//平均内存使用率排行
getAverageMemServiceList
:=
sm
.
GetAverageMemServiceList
()
getAverageMemServiceList
:=
sm
.
GetAverageMemServiceList
()
if
len
(
getAverageMemServiceList
)
!=
0
{
if
len
(
getAverageMemServiceList
)
!=
0
{
t
=
NewTable
(
"平均内存使用率排行"
,
"排名"
,
"内存使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"QPS"
)
t
=
NewTable
(
"平均内存使用率排行"
,
"排名"
,
"内存使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"
MAX
QPS"
)
for
i
,
s
:=
range
getAverageMemServiceList
{
for
i
,
s
:=
range
getAverageMemServiceList
{
if
s
.
GetAverageMem
()
<
memMin
{
if
s
.
GetAverageMem
()
<
memMin
{
break
break
...
@@ -454,7 +456,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -454,7 +456,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
s
.
Name
()),
htmlStringA
(
url
,
s
.
Name
()),
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%.2f"
,
s
.
Get
Qps
()),
hrn
(
s
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
@@ -466,7 +468,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -466,7 +468,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
//峰值内存使用率排行
//峰值内存使用率排行
getMaxMemServiceList
:=
sm
.
GetMaxMemServiceList
()
getMaxMemServiceList
:=
sm
.
GetMaxMemServiceList
()
if
len
(
getMaxMemServiceList
)
!=
0
{
if
len
(
getMaxMemServiceList
)
!=
0
{
t
=
NewTable
(
"峰值内存使用率排行"
,
"排名"
,
"内存使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"QPS"
)
t
=
NewTable
(
"峰值内存使用率排行"
,
"排名"
,
"内存使用率"
,
"服务名称"
,
"访问量"
,
"平均响应时间"
,
"
MAX
QPS"
)
for
i
,
s
:=
range
getMaxMemServiceList
{
for
i
,
s
:=
range
getMaxMemServiceList
{
if
s
.
GetMaxMem
()
<
memMin
{
if
s
.
GetMaxMem
()
<
memMin
{
break
break
...
@@ -484,7 +486,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
...
@@ -484,7 +486,7 @@ func (sm *ServiceMap) ReportForm(long string) string {
htmlStringA
(
url
,
s
.
Name
()),
htmlStringA
(
url
,
s
.
Name
()),
hrn
(
s
.
GetCount
()),
hrn
(
s
.
GetCount
()),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%v"
,
s
.
GetAverageDuration
()
/
1e6
*
1e6
),
fmt
.
Sprintf
(
"%.2f"
,
s
.
Get
Qps
()),
hrn
(
s
.
GetMax
Qps
()),
)
)
}
}
if
!
t
.
IsEmpty
()
{
if
!
t
.
IsEmpty
()
{
...
...
pkg/report-form/service.go
View file @
57b255fc
...
@@ -24,7 +24,7 @@ type Service struct {
...
@@ -24,7 +24,7 @@ type Service struct {
maxMedianPath
*
Path
//最大中位响应时间path
maxMedianPath
*
Path
//最大中位响应时间path
maxAveragePath
*
Path
//最大平均响应时间path
maxAveragePath
*
Path
//最大平均响应时间path
maxDurationTracePoint
*
TracePoint
//最大响应时间的tracePoint
maxDurationTracePoint
*
TracePoint
//最大响应时间的tracePoint
qps
float64
//QPS
maxqps
int
//QPS
//node相关
//node相关
nodeMap
map
[
string
]
*
Node
//节点列表
nodeMap
map
[
string
]
*
Node
//节点列表
}
}
...
@@ -47,7 +47,7 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
...
@@ -47,7 +47,7 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
endTime
:
endTime
,
endTime
:
endTime
,
pathMap
:
make
(
map
[
string
]
*
Path
),
pathMap
:
make
(
map
[
string
]
*
Path
),
nodeMap
:
make
(
map
[
string
]
*
Node
),
nodeMap
:
make
(
map
[
string
]
*
Node
),
qps
:
0
,
maxqps
:
0
,
}
}
//初始化path
//初始化path
...
@@ -89,8 +89,14 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
...
@@ -89,8 +89,14 @@ func NewService(name string, startTime time.Time, endTime time.Time) *Service {
//初始化qps
//初始化qps
func
(
s
*
Service
)
initQps
()
{
func
(
s
*
Service
)
initQps
()
{
for
_
,
p
:=
range
s
.
pathMap
{
const
sqlMaxQps
=
"SELECT max(qps) as MAXQPS FROM "
+
s
.
qps
+=
p
.
GetQps
()
"(SELECT count(
\"
traceId
\"
) AS qps FROM trace_info "
+
"WHERE sys_name = '%s' AND path != 'head /tech/health/check' "
+
"AND path != 'get /tech/health/check' AND time >= %d AND time < %d GROUP BY time(1s));"
sql
:=
fmt
.
Sprintf
(
sqlMaxQps
,
s
.
Name
(),
s
.
startTime
.
UnixNano
(),
s
.
endTime
.
UnixNano
())
maxqps
,
ok
:=
queryOneAndToInt
(
sql
)
if
ok
{
s
.
maxqps
=
maxqps
}
}
}
}
...
@@ -243,9 +249,18 @@ func (s *Service) GetAverageDurationPathList() []*Path {
...
@@ -243,9 +249,18 @@ func (s *Service) GetAverageDurationPathList() []*Path {
return
rtn
return
rtn
}
}
//获取qps
//获取
平均
qps
func
(
s
*
Service
)
GetQps
()
float64
{
func
(
s
*
Service
)
GetQps
()
float64
{
return
s
.
qps
t
:=
s
.
endTime
.
Unix
()
-
s
.
startTime
.
Unix
()
if
t
==
0
{
return
0
}
return
float64
(
s
.
GetCount
())
/
float64
(
t
)
}
//获取maxqps
func
(
s
*
Service
)
GetMaxQps
()
int
{
return
s
.
maxqps
}
}
//获取 MedianDuration Path 排行
//获取 MedianDuration Path 排行
...
...
pkg/report-form/service_map.go
View file @
57b255fc
package
report_form
package
report_form
import
(
import
(
"fmt"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"sort"
"sort"
"time"
"time"
...
@@ -20,7 +21,7 @@ func NewServiceMap(startTime time.Time, endTime time.Time, serviceList []string)
...
@@ -20,7 +21,7 @@ func NewServiceMap(startTime time.Time, endTime time.Time, serviceList []string)
}
}
//初始化service
//初始化service
// serviceList := rtn.getServiceList()
// serviceList := rtn.getServiceList()
for
_
,
serviceName
:=
range
serviceList
{
for
_
,
serviceName
:=
range
serviceList
{
glog
.
Info
(
"init service :"
,
serviceName
,
" start"
)
glog
.
Info
(
"init service :"
,
serviceName
,
" start"
)
rtn
.
serviceMap
[
serviceName
]
=
NewService
(
serviceName
,
startTime
,
endTime
)
rtn
.
serviceMap
[
serviceName
]
=
NewService
(
serviceName
,
startTime
,
endTime
)
...
@@ -162,11 +163,25 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
...
@@ -162,11 +163,25 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
//获取qps
//获取qps
func
(
sm
*
ServiceMap
)
GetQps
()
float64
{
func
(
sm
*
ServiceMap
)
GetQps
()
float64
{
rtn
:=
float64
(
0
)
t
:=
sm
.
endTime
.
Unix
()
-
sm
.
startTime
.
Unix
(
)
for
_
,
s
:=
range
sm
.
serviceMap
{
if
t
==
0
{
r
tn
+=
s
.
GetQps
()
r
eturn
0
}
}
return
rtn
return
float64
(
sm
.
GetCount
())
/
float64
(
t
)
}
//获取最大qps
func
(
sm
*
ServiceMap
)
GetMapQps
()
int
{
const
sqlMaxQps
=
"SELECT max(qps) as MAXQPS FROM "
+
"(SELECT count(
\"
traceId
\"
) AS qps FROM trace_info "
+
"WHERE time >= %d AND time < %d "
+
"GROUP BY time(1s));"
sql
:=
fmt
.
Sprintf
(
sqlMaxQps
,
sm
.
startTime
.
UnixNano
(),
sm
.
endTime
.
UnixNano
())
maxqps
,
ok
:=
queryOneAndToInt
(
sql
)
if
!
ok
{
return
0
}
return
maxqps
}
}
//服务平均响应时间排行
//服务平均响应时间排行
...
...
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