28 lines
778 B
Python
Executable file
28 lines
778 B
Python
Executable file
#!/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) )
|
|
|