Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Check_Memory.py

Rating
3 votes
Favoured:
0
Current Version
1.0
Last Release Date
2012-02-06
Compatible With
  • Nagios 3.x
Owner
License
GPL
Hits
83503
Files:
FileDescription
check_memory.pycheck_memory.py
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Check_Memory.py
>>> This Script checks Your Unix Memory Utilization & Returns Output

>>> Use Command Line Arguments in MB [Megabytes]

>>> Use script as ./memory.py 'Warning Limit' 'Critical Limit'

>>> Use script as ./memory.py 600 500

>>> Where Argument 600 is Memory Warning Limit in MB [Megabytes] & Argument 500 is Memory Critical Limit in MB [Megabytes]
>>> Use Command Line Arguments in MB [Megabytes]

>>> Use script as ./memory.py 'Warning Limit' 'Critical Limit'

>>> Use script as ./memory.py 600 500

>>> Where Argument 600 is Memory Warning Limit in MB [Megabytes] & Argument 500 is Memory Critical Limit in MB [Megabytes]
Reviews (2)
bymartinb, February 11, 2016
I modified this slightly to report on free space and not used space. I also added a 3rd argument for Swap.

import commands
import sys

def checkmem():
mem = "Mem"
memprint = "Memory"
if(len(sys.argv) > 3):
if(sys.argv[3] == "s"):
mem = "Swap"
memprint = "Swap"
a = commands.getstatusoutput("free -m | grep " + mem)
b = a[1]
c = b.split()
t = c[1]
u = c[2]
f = c[3]
if (len(sys.argv) > 2):
if( int(sys.argv[2]) >= int(f) ):
print "CRITICAL -- Total " + memprint, t+"MB", "Current "+memprint+" Usage is", u+"MB", "Free " + memprint, f+"MB"
sys.exit(2)
elif( int(sys.argv[1]) >= int(f) ):
print "WARNING -- Total " + memprint, t+"MB", "Current "+memprint+" Usage is", u+"MB", "Free " + memprint, f+"MB"
sys.exit(1)
else:
print "OK -- Total "+memprint, t+"MB", "Current "+memprint+" Usage is", u+"MB", "Free " + memprint, f+"MB"
sys.exit(0)

def checkargv():
if (len(sys.argv) == 1 ):
print ""
print "Enter Warning Limit & Critical Limit"
print "Use --help For Help"
print ""
else:
check()

def check():
if ((sys.argv[1]) == "--help"):
print ""
print "This Script checks Your Unix Memory Utilization & Returns Output"
print "Use Command Line Arguments in MB [Megabytes]"
print "Use script as ./memory.py 'Warning Limit' 'Critical Limit'"
print "Use script as ./memory.py 600 500 (s)"
print "Where Argument 600 is Memory Warning Limit in MB [Megabytes] & Argument 500 is Memory Critical Limit in MB [Megabytes]"
print "And optional s argument is Swap reporting"
else:
checkmem()

def main():
checkargv()

if __name__ == '__main__':
main()
Hi,
I get the below error while using the arguments as -w 28000 -c 30000

/usr/local/nagios/libexec/check_memory.py -w 28000 -c 30000
Traceback (most recent call last):
File "/usr/local/nagios/libexec/check_memory.py", line 67, in ?
main()
File "/usr/local/nagios/libexec/check_memory.py", line 64, in main
checkargv()
File "/usr/local/nagios/libexec/check_memory.py", line 49, in checkargv
check()
File "/usr/local/nagios/libexec/check_memory.py", line 61, in check
checkmem()
File "/usr/local/nagios/libexec/check_memory.py", line 35, in checkmem
elif( int(sys.argv[1])