前提:把check_mem.sh放到/usr/local/nagios/libexec下,并赋予 户执行权限就可以
chmod 755 check_mem.sh
一,监控本地(监控端本身)内存使用:
#修改commands配置
vim /usr/local/nagios/etc/objects/commands.cfg
#增加以下内容
define command{
command_name check_mem
command_line $USER1$/check_mem.sh -w $ARG1$ -c $ARG2$
}
#修改localhost.cfg
vim /usr/local/nagios/etc/objects/localhost.cfg
#增加以下内容
define service{
use local-service
host_name localhost
service_description memory
check_command check_mem!20!10!
}
二,监控客户端内存使用情况:
1,#修改客户端配置文件
vim /usr/local/nagios/etc/nrpe.cfg
#增加以下内容
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 10 -c 5
2,#修改主控制端相关配置文件
vim /usr/local/nagios/etc/service/liguxk.cfg #主控端定义的被控端的配置文件
#增加以下内容
define service{
use generic-service
host_name liguxk
service_description Memory
check_command check_nrpe!check_mem
}
chechk_mem.sh:
#script to check real memory usage
# L.Gill 02/05/06 - V.1.0
# ------------------------------------------
# ######## Script Modifications ##########
# ------------------------------------------
# Who When What
# --- ---- ----
# LGill 17/05/06 "$percent" lt 1% fix - sed edits dc result beggining with "."
#
#
#!/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 ""
echo "$THRESHOLD_USAGE"
echo ""
echo "Usage: $USAGE"
echo ""
exit 0
fi
# Total memory available
total=`free -m | head -2 |tail -1 |gawk '{print $2}'`
# Total memory used
used=`free -m | head -2 |tail -1 |gawk '{print $3}'`
# Calc total minus used
free=`free -m | head -2 |tail -1 |gawk '{print $2-$3}'`
# normal values
#echo "$total"MB total
#echo "$used"MB used
#echo "$free"MB free
# make it into % percent free = ((free mem / total mem) * 100)
echo "5" > $calc # decimal accuracy
echo "k" >> $calc # commit
echo "100" >> $calc # multiply
echo "$free" >> $calc # division integer
echo "$total" >> $calc # division integer
echo "/" >> $calc # division sign
echo "*" >> $calc # multiplication sign
echo "p" >> $calc # print
percent=`/usr/bin/dc $calc|/bin/sed 's/^\./0./'|/usr/bin/tr "." " "|/usr/bin/gawk {'print $1'}`
#percent1=`/usr/bin/dc $calc`
#echo "$percent1"
if [[ "$percent" -le $critical ]]
then
echo "CRITICAL - $free MB ($percent%) Free Memory"
exit 2
fi
if [[ "$percent" -le $warning ]]
then
echo "WARNING - $free MB ($percent%) Free Memory"
exit 1
fi
if [[ "$percent" -gt $warning ]]
then
echo "OK - $free MB ($percent%) Free Memory"
exit 0
fi
另一种方法:
由于LINUX使用内存的机制,监控内存没多大必要,还是记录下来
在被监控机/usr/local/nagios/etc/nrpe.cfg里添加
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 150 -c 200
把check_mem(见附件)放到/usr/local/nagios/libexec/下,并赋予权限
chmod +x /usr/local/nagios/libexec/check_mem
chown nagios.nagios /usr/local/nagios/libexec/check_mem
监控端/usr/local/nagios/etc/objects/commands.cfg添加
define command{
command_name check_mem
command_line $USER1$/check_mem -w $ARG1$ -c $ARG2$
}
/usr/local/nagios/etc/servers/252.cfg添加
define service{
use generic-service ; Name of service template to use
host_name 252
service_description memory
check_command check_nrpe!check_mem!110,80!150,100
}
重启nagios服务
说实话nagios监控内存没什么意思,你还要分析数据什么的不如直接利用cacti图形那样比较清晰,cacti的内存监控 是自己带的功能比较好实现的!
附件:http://down.运维网.com/data/2357720
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com