Commit c5d37f24 authored by lkx33's avatar lkx33

新增每秒发送消息次数统计图表

parent 014ce6dd
...@@ -3,6 +3,7 @@ import time ...@@ -3,6 +3,7 @@ import time
import datetime import datetime
import math import math
import numpy as np import numpy as np
import pandas as pd
from reader import initData from reader import initData
# def sendReport(): # def sendReport():
...@@ -37,7 +38,7 @@ def formatData(sortType=0): ...@@ -37,7 +38,7 @@ def formatData(sortType=0):
logData.append([i['logId'], i['msgSendTime'], logData.append([i['logId'], i['msgSendTime'],
i['msgSendReplyTime'], i['msgReceiveTime'], replyLag, msgLag]) i['msgSendReplyTime'], i['msgReceiveTime'], replyLag, msgLag])
# print(sorted(logData, key=lambda x: x[3])) # print(sorted(logData, key=lambda x: x[3]))
logData.sort(key=lambda x: x[sortType]) logData.sort(key=lambda x: x[sortType])
return logData return logData
...@@ -88,7 +89,16 @@ def lagReport(sortType=5): ...@@ -88,7 +89,16 @@ def lagReport(sortType=5):
return lagData 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(): # def errorReport():
......
import datetime import datetime
import math import math
import numpy as np import numpy as np
import pandas as pd
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
from matplotlib import ticker as tk from matplotlib import ticker as tk
from matplotlib import dates as dt from matplotlib import dates as dt
from analyzer import formatData, lagReport from analyzer import formatData, lagReport, perSecondReport
def chartByPercent(): def chartByPercent():
# 绘制图表(延迟从小到大走向) # 绘制图表(延迟从小到大走向)
plt.title("Message receive log")
plt.xlabel("Percentage")
plt.ylabel("Lag")
y1 = lagReport(4) y1 = lagReport(4)
y2 = lagReport(5) y2 = lagReport(5)
x = np.arange(1/len(y1), 1+1/len(y1), 1/len(y1)) 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.xlim(0, None) # 设置起点
plt.xticks(range(0, 101, 10)) # 设置x轴间隔 plt.xticks(range(0, 101, 10)) # 设置x轴间隔
...@@ -28,7 +29,11 @@ def chartByPercent(): ...@@ -28,7 +29,11 @@ def chartByPercent():
plt.plot(x*100, y1, label='reply') plt.plot(x*100, y1, label='reply')
plt.text(90, y2[math.floor(0.9*len(y2))-1], "%0.2fms \n90%%" % y2[math.floor(0.9*len(y2))-1], fontsize=10, color="r", style="italic", plt.text(90, y2[math.floor(0.9*len(y2))-1], "%0.2fms \n90%%" % 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.2f%%" % (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() # 显示标注 plt.legend() # 显示标注
...@@ -37,6 +42,10 @@ def chartByPercent(): ...@@ -37,6 +42,10 @@ def chartByPercent():
def chartByTime(): def chartByTime():
# 绘制图表(时间走向) # 绘制图表(时间走向)
plt.title("Message receive log")
plt.xlabel("SendTime")
plt.ylabel("Lag")
logData = formatData(1) # 获取日志,按照发送时间排序 logData = formatData(1) # 获取日志,按照发送时间排序
time = [i[1] for i in logData] # 获取时间 time = [i[1] for i in logData] # 获取时间
...@@ -47,10 +56,6 @@ def chartByTime(): ...@@ -47,10 +56,6 @@ def chartByTime():
# t/1000).strftime("%Y-%m-%d %H:%M:%S.%f") for t in time] # t/1000).strftime("%Y-%m-%d %H:%M:%S.%f") for t in time]
x = [datetime.datetime.fromtimestamp(t/1000) 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.xlim(0, None)
# plt.xticks(range(0, 10, 1)) # plt.xticks(range(0, 10, 1))
...@@ -60,10 +65,35 @@ def chartByTime(): ...@@ -60,10 +65,35 @@ def chartByTime():
plt.plot(x, y2, label='receive') plt.plot(x, y2, label='receive')
plt.plot(x, y1, label='reply') plt.plot(x, y1, label='reply')
plt.axhline(y=2000, c='red', ls='-', lw=1)
plt.legend() # 显示标注 plt.legend() # 显示标注
plt.show() 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() # chartByPercent()
chartByTime() # chartByTime()
chartByPerSecond()
www.runoob.com!
Very good site!
...@@ -38,6 +38,8 @@ def initData(): ...@@ -38,6 +38,8 @@ def initData():
# else: # else:
# print(i) # print(i)
# 这段代码写的好nm蠢,先凑合用
for i in rc: for i in rc:
for index, j in enumerate(rp): for index, j in enumerate(rp):
if i['logId'] == j['logId']: if i['logId'] == j['logId']:
......
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')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment