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
4f5a2280
Commit
4f5a2280
authored
Dec 05, 2019
by
jingbo.wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
报表代码优化
parent
128da8d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
50 additions
and
34 deletions
+50
-34
regular_report.go
pkg/report-form/regular_report.go
+29
-19
report_form.go
pkg/report-form/report_form.go
+19
-14
report_form_test.go
pkg/report-form/report_form_test.go
+2
-1
No files found.
pkg/report-form/regular_report.go
View file @
4f5a2280
...
@@ -43,26 +43,9 @@ func RegularReport(dir string) {
...
@@ -43,26 +43,9 @@ func RegularReport(dir string) {
for
{
for
{
<-
timer
.
C
<-
timer
.
C
now
:=
time
.
Now
()
now
:=
time
.
Now
()
fileNamePrefix
:=
now
.
Format
(
"2006-01-02"
)
//周表
//报表
if
now
.
Weekday
()
==
time
.
Monday
{
run
(
now
,
dir
)
fileName
:=
dir
+
"/"
+
fileNamePrefix
+
"_week.txt"
if
!
util
.
Exists
(
fileName
)
{
body
:=
GeneralTableRun
(
7
)
if
err
:=
ioutil
.
WriteFile
(
fileName
,
[]
byte
(
body
),
0644
);
err
!=
nil
{
glog
.
Error
(
"报表写入文件失败:"
,
fileName
,
err
)
glog
.
Info
(
body
)
}
email
.
SendEmail
(
"服务监控状态总表-"
+
fileNamePrefix
,
body
,
receiverList
...
)
}
glog
.
Info
(
"每周总表报表完成:"
,
fileName
)
}
//日表
//TODO
//fmt.Println("如果文件不存在,则报表:", fileNamePrefix)
next
:=
now
.
Add
(
time
.
Hour
*
24
)
next
:=
now
.
Add
(
time
.
Hour
*
24
)
next
=
time
.
Date
(
next
.
Year
(),
next
.
Month
(),
next
.
Day
(),
10
,
0
,
0
,
0
,
next
.
Location
())
next
=
time
.
Date
(
next
.
Year
(),
next
.
Month
(),
next
.
Day
(),
10
,
0
,
0
,
0
,
next
.
Location
())
...
@@ -70,3 +53,30 @@ func RegularReport(dir string) {
...
@@ -70,3 +53,30 @@ func RegularReport(dir string) {
}
}
}()
}()
}
}
func
run
(
now
time
.
Time
,
dir
string
)
{
fileNamePrefix
:=
now
.
Format
(
"2006-01-02"
)
//周表
if
now
.
Weekday
()
==
time
.
Monday
{
sm
:=
GeneralTableNewSM
(
7
)
//总表
fileName
:=
dir
+
"/"
+
fileNamePrefix
+
"_week.txt"
if
!
util
.
Exists
(
fileName
)
{
body
:=
GeneralTableRun
(
sm
)
if
err
:=
ioutil
.
WriteFile
(
fileName
,
[]
byte
(
body
),
0644
);
err
!=
nil
{
glog
.
Error
(
"报表写入文件失败:"
,
fileName
,
err
)
glog
.
Info
(
body
)
}
email
.
SendEmail
(
"服务监控状态总表-"
+
fileNamePrefix
,
body
,
receiverList
...
)
}
glog
.
Info
(
"每周总表报表完成:"
,
fileName
)
//分表
//TODO
}
//日表
//TODO
}
pkg/report-form/report_form.go
View file @
4f5a2280
...
@@ -118,25 +118,13 @@ func (t *Table) AddRecord(values ...interface{}) error {
...
@@ -118,25 +118,13 @@ func (t *Table) AddRecord(values ...interface{}) error {
return
nil
return
nil
}
}
func
GeneralTableRun
(
n
int
)
string
{
func
GeneralTableRun
(
sm
*
ServiceMap
)
string
{
const
(
const
(
cpuMin
=
1
cpuMin
=
1
memMin
=
1
memMin
=
1
diskMin
=
1
diskMin
=
1
)
)
//求前n天的数据,按天取整
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
,
-
n
)
endTime
:=
startTime
.
AddDate
(
0
,
0
,
n
)
//查询
sm
:=
NewServiceMap
(
startTime
,
endTime
)
//生成报表
//生成报表
rtn
:=
new
(
strings
.
Builder
)
rtn
:=
new
(
strings
.
Builder
)
...
@@ -144,7 +132,8 @@ func GeneralTableRun(n int) string {
...
@@ -144,7 +132,8 @@ func GeneralTableRun(n int) string {
rtn
.
WriteString
(
" 服务健康状态总表
\n
"
)
rtn
.
WriteString
(
" 服务健康状态总表
\n
"
)
//时间
//时间
rtn
.
WriteString
(
fmt
.
Sprintf
(
"时间:%s ~ %s
\n
"
,
startTime
.
Format
(
time
.
RFC3339
),
endTime
.
Format
(
time
.
RFC3339
)))
rtn
.
WriteString
(
fmt
.
Sprintf
(
"时间:%s ~ %s
\n
"
,
sm
.
startTime
.
Format
(
time
.
RFC3339
),
sm
.
endTime
.
Format
(
time
.
RFC3339
)))
//访问量
//访问量
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%v 总响应时间:%v 平均响应时间:%v
\n\n
"
,
rtn
.
WriteString
(
fmt
.
Sprintf
(
"总访问量:%v 总响应时间:%v 平均响应时间:%v
\n\n
"
,
...
@@ -236,3 +225,19 @@ func GeneralTableRun(n int) string {
...
@@ -236,3 +225,19 @@ func GeneralTableRun(n int) string {
return
rtn
.
String
()
return
rtn
.
String
()
}
}
func
GeneralTableNewSM
(
n
int
)
*
ServiceMap
{
//求前n天的数据,按天取整
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
,
-
n
)
endTime
:=
startTime
.
AddDate
(
0
,
0
,
n
)
//查询
sm
:=
NewServiceMap
(
startTime
,
endTime
)
return
sm
}
pkg/report-form/report_form_test.go
View file @
4f5a2280
...
@@ -7,7 +7,8 @@ import (
...
@@ -7,7 +7,8 @@ import (
)
)
func
TestRun
(
t
*
testing
.
T
)
{
func
TestRun
(
t
*
testing
.
T
)
{
fmt
.
Println
(
GeneralTableRun
(
10
))
sm
:=
GeneralTableNewSM
(
10
)
fmt
.
Println
(
GeneralTableRun
(
sm
))
}
}
func
TestUtf8StringLen
(
t
*
testing
.
T
)
{
func
TestUtf8StringLen
(
t
*
testing
.
T
)
{
...
...
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