31 lines
1020 B
Python
Executable File
31 lines
1020 B
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# free
|
|
# total used free shared buff/cache available
|
|
# Mem: 5904284 353696 190204 3524 5360384 5238048
|
|
# Swap: 2097148 248064 1849084
|
|
|
|
|
|
re3 = re.compile(r"\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 'Mem:' in line:
|
|
mems = re3.findall(line)
|
|
# save('mem_', ";".join(mems))
|
|
print('N:{0}:{1}:{2}:{3}'.format( mems[0], mems[2], mems[1], int(mems[0])-int(mems[5])))
|
|
ret = rrd_update(os.path.join(SUBFOLDER, 'mem.rrd'), 'N:{0}:{1}:{2}:{3}'.format( mems[0], mems[2], mems[1], int(mems[0])-int(mems[5])) )
|
|
|