Minimal plugin
This commit is contained in:
parent
95c28baf29
commit
0aadac0c65
|
@ -1,27 +1,48 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from pprint import pprint
|
||||
import sys
|
||||
|
||||
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)
|
||||
ratio = float(mem['OverallUsed']) / float(mem['MemTotal']) * 100.0
|
||||
|
||||
|
||||
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) )
|
||||
#print('MemTotal: %8.2f MB' % (mem['MemTotal']/1024) )
|
||||
#print('OverallUsed: %8.2f MB' % (mem['OverallUsed']/1024) )
|
||||
#print('Ratio: %8.2f %%' % ratio )
|
||||
#print('MemUsed: %8.2f MB' % (mem['MemUsed']/1024) )
|
||||
#print('SwapUsed: %8.2f MB' % (mem['SwapUsed']/1024) )
|
||||
|
||||
out = 'MemRatio: %.1f%% of %.1fGB RAM (%.1fGB Swap)' % ( ratio, (mem['MemTotal']/1024.0/1024.0), (mem['SwapTotal']/1024.0/1024.0) )
|
||||
|
||||
if ratio > 150.0:
|
||||
exitcode = 2
|
||||
exitstr = 'CRITICAL'
|
||||
elif ratio > 100.0:
|
||||
exitcode = 1
|
||||
exitstr = 'WARNING'
|
||||
else:
|
||||
exitcode = 0
|
||||
exitstr = 'OK'
|
||||
|
||||
multiout = []
|
||||
for label in ['MemTotal', 'OverallUsed', 'MemUsed', 'SwapTotal', 'SwapUsed']:
|
||||
multiout.append('%s: %.4fGB' % (label, float(mem[label])/1024.0/1024.0))
|
||||
|
||||
perfdata = []
|
||||
for label in ['MemTotal', 'OverallUsed', 'MemUsed', 'SwapTotal', 'SwapUsed']:
|
||||
perfdata.append('%s=%dB;;;;' % (label, mem[label]*1024) )
|
||||
|
||||
|
||||
print(exitstr + ' ' + out + '|' + ' '.join(perfdata))
|
||||
print('\n'.join(multiout))
|
||||
sys.exit(exitcode)
|
||||
|
||||
|
|
Loading…
Reference in a new issue