#!/usr/bin/perl #### ## check_mem v0.1 :: nagios plugin for free memory checks # Copyright (c) 2006 by Stephan Schmieder, ssc@unixgu.ru # # Usage: check_mem -w -c # check_mem [-h|--help] use utf8; use strict; use warnings; use diagnostics; use lib '/usr/local/libexec/nagios'; use utils qw (%ERRORS); if( $ARGV[3] and "$ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3]"=~/^\-w\ (\d+)\ \-c\ (\d+)$/ ){ $_=(split(/[M\s\/]+/, (split(/\n/, `/usr/bin/top -d 1` ))[3]))[4]; $_='0' unless $_; print "OK: $_ mb used|tot=$_\n" and exit($ERRORS{OK}) if $_ <= $1 and $_ <= $2; print "CRITICAL: $_ mb used|tot=$_\n" and exit($ERRORS{CRITICAL}) if $_ >= $2; print "WARNING: $_ mb used|tot=$_\n" and exit($ERRORS{WARNING}) if $_ >= $1; print "UNKNOWN: $_ mb used|tot=$_\n" and exit($ERRORS{UNKNOWN}); } else { print `/usr/bin/grep -A 5 '##\##' '$0'`; }