31 lines
1.1 KiB
Python
Executable File
31 lines
1.1 KiB
Python
Executable File
#!/usr/bin/python3
|
|
import sys
|
|
import re
|
|
import datetime
|
|
import os
|
|
from rrdtool import update as rrd_update # pylint: disable=no-name-in-module
|
|
|
|
SUBFOLDER = ''
|
|
#print(datetime.datetime.now().strftime("%V"))
|
|
|
|
# root@plex:/opt/monitor# mpstat
|
|
# Linux 5.4.0-125-generic (plex) 01/16/2024 _x86_64_ (4 CPU)
|
|
# 03:57:00 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
|
|
# 03:57:00 PM all 0.72 0.01 0.14 0.28 0.00 0.03 0.00 0.00 0.00 98.82
|
|
|
|
re2 = re.compile(r"\d+\.\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 'all' 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[2], cpus[1], 0,0,0,0,0) )
|
|
if float(cpus[0]) > 5.0:
|
|
send_event("ERROR,cpus,3,7,Unexpected high cpu for the last few minutes: {}".format(cpus[0]))
|
|
|