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
463e2b06
Commit
463e2b06
authored
Dec 11, 2019
by
jingbo.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
总表完成
parent
f7a265d6
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
329 additions
and
219 deletions
+329
-219
main.go
main.go
+1
-2
email.go
pkg/email/email.go
+1
-1
path.go
pkg/report-form/path.go
+7
-7
regular_report.go
pkg/report-form/regular_report.go
+3
-12
regular_report_test.go
pkg/report-form/regular_report_test.go
+2
-2
report_form.go
pkg/report-form/report_form.go
+275
-186
report_form_test.go
pkg/report-form/report_form_test.go
+8
-1
service.go
pkg/report-form/service.go
+8
-6
service_map.go
pkg/report-form/service_map.go
+24
-2
No files found.
main.go
View file @
463e2b06
...
...
@@ -6,7 +6,6 @@ import (
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"git.quantgroup.cn/DevOps/enoch/pkg/points"
"git.quantgroup.cn/DevOps/enoch/pkg/report-form"
"github.com/Shopify/sarama"
_
"github.com/mkevac/debugcharts"
"net/http"
...
...
@@ -112,7 +111,7 @@ func main() {
dao
.
DbInit
()
//健康状态报表
report_form
.
RegularReport
(
global
.
ReportFormDir
)
//
report_form.RegularReport(global.ReportFormDir)
//TODO 告警策略
}
...
...
pkg/email/email.go
View file @
463e2b06
...
...
@@ -18,7 +18,7 @@ func SendEmail(title string, content string, receiver ...string) {
//m.SetHeader("To", []string{receiver})
m
.
SetHeader
(
"To"
,
receiver
...
)
m
.
SetHeader
(
"Subject"
,
title
)
m
.
SetBody
(
"text/html"
,
"<div><pre>"
+
content
+
"</pre></div>"
)
m
.
SetBody
(
"text/html"
,
content
)
userName
:=
"program@quantgroup.cn"
pwd
:=
"Fuck147999!!!"
...
...
pkg/report-form/path.go
View file @
463e2b06
...
...
@@ -24,7 +24,7 @@ type Path struct {
averageDuration
time
.
Duration
//平均响应时间
sumDuration
time
.
Duration
//总响应时间
medianDuration
time
.
Duration
//中位响应时间
qps
int
//每秒的访问量
qps
float64
//每秒的访问量
variance
float64
//标准差
maxDurationTracePoint
TracePoint
//最大响应时间的TracePoint
}
...
...
@@ -53,7 +53,7 @@ func (p *Path) initQps() {
if
p
.
startTime
.
Unix
()
>=
p
.
endTime
.
Unix
()
{
return
}
p
.
qps
=
p
.
count
/
int
(
p
.
endTime
.
Sub
(
p
.
startTime
)
.
Seconds
()
)
p
.
qps
=
float64
(
p
.
count
)
/
p
.
endTime
.
Sub
(
p
.
startTime
)
.
Seconds
(
)
}
//初始化访问次数
...
...
@@ -193,16 +193,16 @@ func (p *Path) GetCount() int {
return
p
.
count
}
//获取qps
func
(
p
*
Path
)
GetQps
()
float64
{
return
p
.
qps
}
//获取总响应时间
func
(
p
*
Path
)
GetSumDuration
()
time
.
Duration
{
return
p
.
sumDuration
}
//获取qps
func
(
p
*
Path
)
GetQps
()
int
{
return
p
.
qps
}
//获取平均响应时间
func
(
p
*
Path
)
GetAverageDuration
()
time
.
Duration
{
return
p
.
averageDuration
...
...
pkg/report-form/regular_report.go
View file @
463e2b06
package
report_form
import
(
"encoding/json"
"git.quantgroup.cn/DevOps/enoch/pkg/email"
"git.quantgroup.cn/DevOps/enoch/pkg/global"
"git.quantgroup.cn/DevOps/enoch/pkg/glog"
"github.com/vrg0/go-common/util"
"io/ioutil"
"runtime/debug"
"time"
)
/*
var (
receiverList = make([]string, 0)
serviceOwner = make(map[string][]string)
...
...
@@ -68,7 +58,7 @@ func run(now time.Time, dir string) {
fileNamePrefix := now.Format("2006-01-02")
//周表
if
now
.
Weekday
()
==
time
.
Mon
day
{
if now.Weekday() == time.
Tues
day {
sm := GeneralTableNewSM(7)
//总表
...
...
@@ -103,3 +93,4 @@ func run(now time.Time, dir string) {
}
}
}
*/
pkg/report-form/regular_report_test.go
View file @
463e2b06
package
report_form
import
"testing"
/*
func TestRegularReport(t *testing.T) {
RegularReport("/var/enoch_health_table")
select {}
}
*/
pkg/report-form/report_form.go
View file @
463e2b06
This diff is collapsed.
Click to expand it.
pkg/report-form/report_form_test.go
View file @
463e2b06
...
...
@@ -3,9 +3,15 @@ package report_form
import
(
"fmt"
"testing"
"
unicode/utf8
"
"
time
"
)
func
TestRun
(
t
*
testing
.
T
)
{
smForm
:=
ServiceMapReportForm
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
10
),
time
.
Now
())
fmt
.
Println
(
smForm
)
}
/*
func TestRun(t *testing.T) {
sm := GeneralTableNewSM(7)
fmt.Println(GeneralTableRun(sm))
...
...
@@ -19,3 +25,4 @@ func TestUtf8StringLen(t *testing.T) {
i += size
}
}
*/
pkg/report-form/service.go
View file @
463e2b06
...
...
@@ -24,7 +24,7 @@ type Service struct {
maxMedianPath
*
Path
//最大中位响应时间path
maxAveragePath
*
Path
//最大平均响应时间path
maxDurationTracePoint
*
TracePoint
//最大响应时间的tracePoint
qps
int
qps
float64
//QPS
//node相关
nodeMap
map
[
string
]
*
Node
//节点列表
}
...
...
@@ -225,7 +225,7 @@ func (s *Service) GetAverageDurationPathList() []*Path {
}
//获取qps
func
(
s
*
Service
)
GetQps
()
int
{
func
(
s
*
Service
)
GetQps
()
float64
{
return
s
.
qps
}
...
...
@@ -295,18 +295,20 @@ func (s *Service) GetMaxDurationTracePoint() (*TracePoint, bool) {
return
s
.
maxDurationTracePoint
,
s
.
maxDurationTracePoint
!=
nil
}
//求
平均
值
//求
最大
值
func
(
s
*
Service
)
getNodeMapValue
(
f
func
(
node
*
Node
)
int
)
int
{
if
len
(
s
.
nodeMap
)
==
0
{
return
0
}
sum
:=
0
max
:=
0
for
_
,
node
:=
range
s
.
nodeMap
{
sum
+=
f
(
node
)
if
f
(
node
)
>
max
{
max
=
f
(
node
)
}
}
return
sum
/
len
(
s
.
nodeMap
)
return
max
}
func
(
s
*
Service
)
GetAverageCpu
()
int
{
...
...
pkg/report-form/service_map.go
View file @
463e2b06
...
...
@@ -126,6 +126,23 @@ func (sm *ServiceMap) GetMaxMemServiceList() []*Service {
return
rtn
}
//获取平均内存使用率列表
func
(
sm
*
ServiceMap
)
GetAverageMemServiceList
()
[]
*
Service
{
rtn
:=
make
([]
*
Service
,
0
)
for
_
,
s
:=
range
sm
.
serviceMap
{
rtn
=
append
(
rtn
,
s
)
}
sort
.
Slice
(
rtn
,
func
(
i
,
j
int
)
bool
{
if
rtn
[
i
]
.
GetAverageMem
()
>
rtn
[
j
]
.
GetAverageMem
()
{
return
true
}
return
false
})
return
rtn
}
//获取峰值磁盘使用率列表
func
(
sm
*
ServiceMap
)
GetMaxDiskServiceList
()
[]
*
Service
{
rtn
:=
make
([]
*
Service
,
0
)
...
...
@@ -144,8 +161,8 @@ func (sm *ServiceMap) GetMaxDiskServiceList() []*Service {
}
//获取qps
func
(
sm
*
ServiceMap
)
GetQps
()
int
{
rtn
:=
0
func
(
sm
*
ServiceMap
)
GetQps
()
float64
{
rtn
:=
float64
(
0
)
for
_
,
s
:=
range
sm
.
serviceMap
{
rtn
+=
s
.
GetQps
()
}
...
...
@@ -245,6 +262,11 @@ func (sm *ServiceMap) GetCount() int {
return
sum
}
//获取service map
func
(
sm
*
ServiceMap
)
GetServiceMap
()
map
[
string
]
*
Service
{
return
sm
.
serviceMap
}
//获取总响应时间
func
(
sm
*
ServiceMap
)
GetSumDuration
()
time
.
Duration
{
sum
:=
time
.
Duration
(
0
)
...
...
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