Files

31 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-03-24 21:33:34 +00:00
#!/usr/bin/python3
import sys
import re
import datetime
import os
from rrdtool import update as rrd_update # pylint: disable=no-name-in-module
from addEvent import send_event
SUBFOLDER = ''
#print(datetime.datetime.now().strftime("%V"))
# top - 13:35:26 up 2 days, 23:46, 2 users, load average: 0,00, 0,03, 0,050
# top - 13:44:48 up 187 days, 38 min, 1 user, load average: 0.02, 0.08, 0.24
re1 = re.compile('load average:\s?(\d{1,2}\.\d{1,2}),\s?(\d{1,2}\.\d{1,2}),\s?(\d{1,2}\.\d{1,2})')
re2 = re.compile("\d+\.\d+")
re3 = re.compile("\d+")
def save(filename, string):
fo = open(os.path.join(SUBFOLDER, filename+'_'+datetime.datetime.now().strftime("%V"))+'.log', "a")
fo.writelines( string + "\n" )
fo.close()
for line in sys.stdin:
if 'Cpu(s):' in line:
cpus = re2.findall(line)
# print(";".join(cpus))
ret = rrd_update(os.path.join(SUBFOLDER, 'cpu.rrd'), 'N:{0}:{1}:{2}:{3}:{4}:{5}:{6}:{7}'.format( cpus[0], cpus[1], cpus[2], cpus[3], cpus[4], cpus[5], cpus[6], cpus[7]) )
if float(cpus[0]) > 20.0: # 20 of 100%
send_event("ERROR,cpus,3,7,Unexpected high cpu for the last few minutes: {}".format(cpus[0]))