Only show values

This commit is contained in:
Sven Velt 2021-06-24 11:56:19 +02:00
parent 6ab2bc8ebc
commit 95c28baf29

27
check_linux_memory.py Executable file
View file

@ -0,0 +1,27 @@
#!/usr/bin/python3
from pprint import pprint
with open('/proc/meminfo', 'r') as f:
lines = f.read().splitlines()
mem = {x.split(':',1)[0] : int( x.split(':',1)[1].replace('kB', '').lstrip().rstrip() ) for x in lines}
#pprint(mem)
mem['MemUsed'] = mem['MemTotal'] - mem['MemFree'] - mem ['Cached'] - mem['SReclaimable'] - mem['Buffers']
mem['SwapUsed'] = mem['SwapTotal'] - mem['SwapFree']
mem['OverallUsed'] = mem['MemUsed'] + mem['SwapUsed']
pprint(mem)
print('MemTotal: %8.2f MB' % (mem['MemTotal']/1024) )
print('OverallUsed: %8.2f MB' % (mem['OverallUsed']/1024) )
print('Ratio: %8.2f %%' % (mem['OverallUsed']/mem['MemTotal']*100.0) )
print('MemUsed: %8.2f MB' % (mem['MemUsed']/1024) )
print('SwapUsed: %8.2f MB' % (mem['SwapUsed']/1024) )