起因:看到 check_nt 可以看 Windows Client 的 memory usage ...Linux預設沒有...
由於預設沒有此command可處理,所以開始…
小記:實作記錄見下篇
*在 /usr/lib64/nagios/plugins/ 新增command用的shell script,
記得chmod 755(權限要跟其它plugin一樣)
*在 /etc/nagios/objects/commands.cfg 新增 command
*在 /etc/nagios/nrpe.cfg 新增 command
*在 /etc/nagios/objects/對象設定檔.cfg 新增 service
先貼大致用上的 link
做一個 .sh 檔來 check memory
========================================================================
其它版本
http://www.linuxquestions.org/questions/linux-software-2/nagios-check-ram-usage-on-remote-server-747531/
http://www.linuxquestions.org/questions/linux-software-2/check_log-nrpe-error-connection-refused-by-host-889073/
http://www.linuxquestions.org/questions/linux-software-2/nagios-check-ram-usage-on-remote-server-747531/
http://www.linuxquestions.org/questions/linux-software-2/check_log-nrpe-error-connection-refused-by-host-889073/
Service definition on the server in the host config:
define service {
use generic-service
host_name
service_description Memory Usage
check_command check_nrpe_1arg!check_memory
}
This needs to be defined in /etc/nagios/nrpe.cfg on the client, amended for the values you want to check for:
command[check_memory]=/usr/lib/nagios/plugins/check_memory.sh -w 85 -c 90
Example output:
#:~$ ./check_memory.sh -w 80 -c 90
Memory OK. 44% used.
#:~$ ./check_memory.sh -w 40 -c 50
Memory WARNING. 44% used.
The script:
#!/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
沒有留言:
張貼留言