为什么80%的码农都做不了架构师?>>>
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""Nagios plugin to report Memory usage by parsing /proc/meminfoby L.S. Keijser
import syscheckmemver = '0.1'# Parse commandline options:
parser = OptionParser(usage="%prog -w
parser.add_option("-w", "--warning",action="store", type="string", dest="warn_threshold", help="Warning threshold in percentage")
parser.add_option("-c", "--critical",action="store", type="string", dest="crit_threshold", help="Critical threshold in percentage")
(options, args) &#61; parser.parse_args()def readLines(filename):f &#61; open(filename, "r")lines &#61; f.readlines()return linesdef readMemValues():global memTotal, memCached, memFreefor line in readLines(&#39;/proc/meminfo&#39;):if line.split()[0] &#61;&#61; &#39;MemTotal:&#39;:memTotal &#61; line.split()[1]if line.split()[0] &#61;&#61; &#39;MemFree:&#39;:memFree &#61; line.split()[1]if line.split()[0] &#61;&#61; &#39;Cached:&#39;:memCached &#61; line.split()[1]def percMem():readMemValues()return (((int(memFree) &#43; int(memCached)) * 100) / int(memTotal))def realMem():readMemValues()return (int(memFree) &#43; int(memCached)) / 1024def go():if not options.crit_threshold:print "UNKNOWN: Missing critical threshold value."sys.exit(3)if not options.warn_threshold:print "UNKNOWN: Missing warning threshold value."sys.exit(3)if int(options.crit_threshold) >&#61; int(options.warn_threshold):print "UNKNOWN: Critical percentage can&#39;t be equal to or bigger than warning percentage."sys.exit(3)trueFree &#61; percMem()trueMemFree &#61; realMem()if int(trueFree) <&#61; int(options.crit_threshold):print "CRITICAL: Free memory percentage is less than or equal to %s%% %s %sMB | mem &#61; %sMB;6546;3273;0;32732" %(str(options.crit_threshold),str(trueFree),str(trueMemFree),str(trueMemFree))sys.exit(2)if int(trueFree) <&#61; int(options.warn_threshold):print "WARNING: Free memory percentage is less than or equal to %s%% %s %sMB | mem &#61; %sMB;6546;3273;0;32732" %(str(options.warn_threshold),str(trueFree),str(trueMemFree),str(trueMemFree))sys.exit(1)else:print "OK: Free memory percentage is %s%% %sMB | mem &#61; %sMB;6546;3273;0;32732" %(str(trueFree),str(trueMemFree),str(trueMemFree))sys.exit(0)if __name__ &#61;&#61; &#39;__main__&#39;:go()