一、监控本地(localhost)内存
1、上传监控脚本 check_mem 到/usr/local/nagios/libexec# chown -R nagios.nagios check_mem
# chmod +x check_mem
2、修改commands配置# vim /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_mem
command_line $USER1$/check_mem -w $ARG1$ -c $ARG2$
}
3、修改localhost.cfg# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service
host_name localhost
service_description check_mem
check_command check_mem!20!10
}
4、重启nagios服务# service nagios restart
5、check_mem 脚本#!/bin/bash
USAGE="`basename $0` [-w|--warning] [-c|--critical]"
THRESHOLD_USAGE="WARNING threshold must be greater than CRITICAL: `basename $0` $*"
calc=/tmp/memcalc
percent_free=/tmp/mempercent
critical=""
warning=""
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
# print usage
if [[ $# -lt 4 ]]
then
echo ""
echo "Wrong Syntax: `basename $0` $*"
echo ""
echo "Usage: $USAGE"
echo ""
exit 0
fi
# read input
while [[ $# -gt 0 ]]
do
case "$1" in
-w|--warning)
shift
warning=$1
;;
-c|--critical)
shift
critical=$1
;;
esac
shift
done
# verify input
if [[ $warning -eq $critical || $warning -lt $critical ]]
then
echo