Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
chat33test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lkx33
chat33test
Commits
c5d37f24
Commit
c5d37f24
authored
Apr 23, 2021
by
lkx33
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增每秒发送消息次数统计图表
parent
014ce6dd
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
12 deletions
+69
-12
analyzer.py
analyzer.py
+11
-1
chart.py
chart.py
+41
-11
test.log
log/test.log
+3
-0
reader.py
reader.py
+2
-0
test.py
test.py
+12
-0
No files found.
analyzer.py
View file @
c5d37f24
...
...
@@ -3,6 +3,7 @@ import time
import
datetime
import
math
import
numpy
as
np
import
pandas
as
pd
from
reader
import
initData
# def sendReport():
...
...
@@ -88,7 +89,16 @@ def lagReport(sortType=5):
return
lagData
# lagReport()
def
perSecondReport
():
# 统计每秒发送的消息数量
secondCount
=
[]
source
=
initData
()
for
i
in
source
:
i
[
'msgSendTime'
]
//=
1000
secondCount
.
append
(
i
[
'msgSendTime'
])
data
=
list
(
zip
(
*
np
.
unique
(
secondCount
,
return_counts
=
True
)))
print
(
data
)
return
data
# def errorReport():
...
...
chart.py
View file @
c5d37f24
import
datetime
import
math
import
numpy
as
np
import
pandas
as
pd
from
matplotlib
import
pyplot
as
plt
from
matplotlib
import
ticker
as
tk
from
matplotlib
import
dates
as
dt
from
analyzer
import
formatData
,
lagReport
from
analyzer
import
formatData
,
lagReport
,
perSecondReport
def
chartByPercent
():
# 绘制图表(延迟从小到大走向)
plt
.
title
(
"Message receive log"
)
plt
.
xlabel
(
"Percentage"
)
plt
.
ylabel
(
"Lag"
)
y1
=
lagReport
(
4
)
y2
=
lagReport
(
5
)
x
=
np
.
arange
(
1
/
len
(
y1
),
1
+
1
/
len
(
y1
),
1
/
len
(
y1
))
plt
.
title
(
"Message receive log"
)
plt
.
xlabel
(
"Percentage"
)
plt
.
ylabel
(
"Lag"
)
plt
.
xlim
(
0
,
None
)
# 设置起点
plt
.
xticks
(
range
(
0
,
101
,
10
))
# 设置x轴间隔
...
...
@@ -28,7 +29,11 @@ def chartByPercent():
plt
.
plot
(
x
*
100
,
y1
,
label
=
'reply'
)
plt
.
text
(
90
,
y2
[
math
.
floor
(
0.9
*
len
(
y2
))
-
1
],
"
%0.2
fms
\n
90
%%
"
%
y2
[
math
.
floor
(
0.9
*
len
(
y2
))
-
1
],
fontsize
=
10
,
color
=
"r"
,
style
=
"italic"
,
weight
=
"light"
,
verticalalignment
=
'center'
,
horizontalalignment
=
'center'
,
rotation
=
0
)
weight
=
"light"
,
verticalalignment
=
'bottom'
,
horizontalalignment
=
'center'
,
rotation
=
0
)
# 标注样式
plt
.
text
((
math
.
floor
(
2000
/
np
.
amax
(
y2
)
*
100
)),
2000
,
"2000ms
\n
%0.2
f
%%
"
%
(
math
.
floor
(
2000
/
np
.
amax
(
y2
)
*
100
)),
fontsize
=
10
,
color
=
"r"
,
style
=
"italic"
,
weight
=
"light"
,
verticalalignment
=
'bottom'
,
horizontalalignment
=
'center'
,
rotation
=
0
)
# 标注样式
plt
.
axhline
(
y
=
2000
,
c
=
'red'
,
ls
=
'-'
,
lw
=
1
)
plt
.
legend
()
# 显示标注
...
...
@@ -37,6 +42,10 @@ def chartByPercent():
def
chartByTime
():
# 绘制图表(时间走向)
plt
.
title
(
"Message receive log"
)
plt
.
xlabel
(
"SendTime"
)
plt
.
ylabel
(
"Lag"
)
logData
=
formatData
(
1
)
# 获取日志,按照发送时间排序
time
=
[
i
[
1
]
for
i
in
logData
]
# 获取时间
...
...
@@ -47,10 +56,6 @@ def chartByTime():
# t/1000).strftime("%Y-%m-%d %H:%M:%S.%f") for t in time]
x
=
[
datetime
.
datetime
.
fromtimestamp
(
t
/
1000
)
for
t
in
time
]
plt
.
title
(
"Message receive log"
)
plt
.
xlabel
(
"SendTime"
)
plt
.
ylabel
(
"Lag"
)
# plt.xlim(0, None)
# plt.xticks(range(0, 10, 1))
...
...
@@ -60,10 +65,35 @@ def chartByTime():
plt
.
plot
(
x
,
y2
,
label
=
'receive'
)
plt
.
plot
(
x
,
y1
,
label
=
'reply'
)
plt
.
axhline
(
y
=
2000
,
c
=
'red'
,
ls
=
'-'
,
lw
=
1
)
plt
.
legend
()
# 显示标注
plt
.
show
()
def
chartByPerSecond
():
plt
.
title
(
"SendMessage per Second"
)
plt
.
xlabel
(
"SendTime"
)
plt
.
ylabel
(
"Times"
)
data
=
perSecondReport
()
time
=
[
i
[
0
]
for
i
in
data
]
counts
=
[
i
[
1
]
for
i
in
data
]
x
=
[
datetime
.
datetime
.
fromtimestamp
(
t
)
for
t
in
time
]
# x = pd.date_range(start=datetime.datetime.fromtimestamp(time[0]), end=datetime.datetime.fromtimestamp(time[-1]), freq="S")
y
=
counts
plt
.
gca
()
.
xaxis
.
set_major_formatter
(
dt
.
DateFormatter
(
'
%
H:
%
M:
%
S'
))
# plt.gca().xaxis.set_major_locator(dt.AutoDateLocator(minticks=10,maxticks=100)) #自动划分时间刻度
plt
.
gca
()
.
xaxis
.
set_major_locator
(
dt
.
SecondLocator
(
interval
=
2
))
#手动划分时间刻度
plt
.
plot
(
x
,
y
)
plt
.
show
()
# chartByPercent()
chartByTime
()
# chartByTime()
chartByPerSecond
()
log/test.log
0 → 100644
View file @
c5d37f24
www.runoob.com!
Very good site!
reader.py
View file @
c5d37f24
...
...
@@ -38,6 +38,8 @@ def initData():
# else:
# print(i)
# 这段代码写的好nm蠢,先凑合用
for
i
in
rc
:
for
index
,
j
in
enumerate
(
rp
):
if
i
[
'logId'
]
==
j
[
'logId'
]:
...
...
test.py
0 → 100644
View file @
c5d37f24
import
os
from
analyzer
import
formatData
logData
=
formatData
(
1
)
time
=
[[
i
[
1
],
i
[
5
]]
for
i
in
logData
]
# lag = [i[5] for i in logData]
print
(
time
[:
100
])
# with open("./log/test.log", 'w') as f:
# f.write("www.runoob.com!\nVery good site!\n" + '\n')
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