[Work][Python]Collect sensor reading and plot it

Key technique: matplotlib

Task:

Collect sensor reading from system and try to analysis. We can use ipmitool and get sensor reading through BMC. The data is as below and we collect it in every 5 second. We need let our customer know the GPU temperature behavior (S2_T4_temp and S3_T4_temp) in our system.

Raw data:

Every 5 second get below data. We need get “40".

Solution:

import matplotlib.pyplot as plt
f = open('d:/gpu.txt', 'r')
lines = f.readlines()
gpu1="S2_T4_temp"
l=len(lines)
gpu_s1=[]
gpu=[]
z=0
for i in range(l):
if gpu1 in lines[i]:
gpu.append(lines[i][19:21])
if 'no' in lines[i]:
gpu_s1.append(z)
else:
gpu_s1.append(int(lines[i][19:21]))
plt.plot(gpu_s1,color='blue')
plt.savefig('gpu.jpeg')

with open ("gpu_s2.txt","w")as fp:
for line in gpu:
fp.write(line+"\n")
fp.close()

Output:

  1. line chart

2. Collect data log.