python3,脚本挂日志就能生成折线图
import numpy as np
import matplotlib.pyplot as plt
import sys
import re
x = []
y = []
x_start = 0
x_step = 5
fp =open(sys.argv[1], 'rb')
for line in fp.readlines():
text = line.decode()
if "%," in text:
#print(re.findall(r"(\d+)%",text)[0])
x.append(int(x_start))
x_start += x_step
y.append(int(re.findall(r"(\d+)%",text)[0]))#取%号前的数字
elif "interval time:" in text:
x_step = int(re.findall(r"(\d+).",text)[0])#取小数
print(x_step)
#print("x:"+str(x))
#print("y:"+str(y))
plt.ylim(0,100)
my_x_ticks = np.arange(0, x_start, 10)
my_y_ticks = np.arange(0, 100, 5)
plt.xticks(my_x_ticks)
plt.yticks(my_y_ticks)
plt.plot(x,y,'r--')
plt.plot(x,y,'ro-')
plt.title('load graph')
plt.xlabel('time(s)')
plt.ylabel('load(%)')
plt.grid(linestyle='-.')
plt.show()
interval time: 5.0, duration time: 100000
01-01-1970 00:04:32: 8%, < 25, 16, 9, 4, 2, 0, 0>
01-01-1970 00:04:37: 7%, < 25, 16, 8, 4, 2, 0, 0>
01-01-1970 00:04:42: 7%, < 23, 15, 8, 4, 1, 0, 0>
01-01-1970 00:04:47: 7%, < 24, 15, 9, 4, 1, 0, 0>
01-01-1970 00:04:52: 7%, < 25, 16, 8, 4, 1, 0, 0>
01-01-1970 00:04:57: 7%, < 24, 16, 8, 4, 1, 0, 0>
01-01-1970 00:05:02: 7%, < 23, 15, 8, 4, 1, 0, 0>
01-01-1970 00:05:07: 8%, < 25, 16, 9, 4, 1, 1, 0>
01-01-1970 00:05:12: 8%, < 25, 16, 9, 5, 2, 0, 0>
01-01-1970 00:05:17: 7%, < 23, 15, 8, 4, 2, 0, 0>
01-01-1970 00:05:22: 7%, < 24, 16, 9, 4, 2, 0, 0>
01-01-1970 00:05:27: 7%, < 23, 15, 8, 4, 1, 0, 0>
01-01-1970 00:05:33: 7%, < 22, 14, 8, 4, 1, 0, 0>
01-01-1970 00:05:38: 6%, < 21, 13, 8, 4, 1, 1, 0>
01-01-1970 00:05:43: 6%, < 20, 13, 7, 3, 1, 0, 0>
01-01-1970 00:05:48: 7%, < 22, 14, 8, 4, 1, 1, 0>