想新增一項目來看Linux client端的記憶體使用情形(Windows的預設有此項目)
預設沒有此command可處理…
記錄改了多少東東…
實作完…問題在佈署
Client 端(安裝 nagios-nrpe ,nagios-nrpe-plugins)
*在 /usr/lib64/nagios/plugins/ 新增command用的shell script,
記得chmod 755(權限要跟其它plugin一樣)
實作時用的是下列討論區用的 script:
http://serverfault.com/questions/195815/nagios-memory-configuration
另有一版本可參考
http://www.linuxquestions.org/questions/linux-software-2/nagios-check-ram-usage-on-remote-server-747531/
vi /usr/lib64/nagios/plugins/check_memeory.sh
#!/bin/bash
#
# Script to check memory usage on Linux. Ignores memory used by disk cache.
#
# Requires the bc command
#
print_help() {
echo "Usage:"
echo "[-w] Warning level as a percentage"
echo "[-c] Critical level as a percentage"
exit 0
}
while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit 0
;;
-w)
warn_level=$2
shift
;;
-c)
critical_level=$2
shift
;;
*)
echo "Unknown Argument: $1"
print_help
exit 3
;;
esac
shift
done
if [ "$warn_level" == "" ]; then
echo "No Warning Level Specified"
print_help
exit 3;
fi
if [ "$critical_level" == "" ]; then
echo "No Critical Level Specified"
print_help
exit 3;
fi
free=`free -m | grep "buffers/cache" | awk '{print $4}'`
used=` free -m | grep "buffers/cache" | awk '{print $3}'`
total=$(($free+$used))
result=$(echo "$used / $total * 100" |bc -l|cut -c -2)
if [ "$result" -lt "$warn_level" ]; then
echo "Memory OK. $result% used."
exit 0;
elif [ "$result" -ge "$warn_level" ] && [ "$result" -le "$critical_level" ]; then
echo "Memory WARNING. $result% used."
exit 1;
elif [ "$result" -gt "$critical_level" ]; then
echo "Memory CRITICAL. $result% used."
exit 2;
fi
chmod 755 /usr/lib64/nagios/plugins/check_memeory.sh
Client本機端試用:
sh /usr/lib64/nagios/plugins/check_memory.sh
sh /usr/lib64/nagios/plugins/check_memory.sh -w 80 -c 95
*在 /etc/nagios/nrpe.cfg 新增 command
##self defined## MEMORY Check
# check_mem = MEMORY at defined warning and critical use %.
command[check_memory]=/usr/local/nagios/libexec/check_memory.sh -w $ARG1$ -c $ARG2$
service nrpe restart
Nagios Server端
*在 /etc/nagios/objects/commands.cfg 新定義 command
define command{
command_name check_memory
command_line $USER1$/check_memory.sh -w $ARG1$ -c $ARG2$
}
*在 對象設定檔.cfg 新增 service
測試對象:localhost.cfg
vi /etc/nagios/objects/localhost.cfg
define service{
use local-service;Name of service template to use
host_name localhost
service_description Memory Use
check_command check_memory!80!90
}
service nagios restart
沒有留言:
張貼留言