percona monitoring plugin 可参见http://www.percona.com/software/percona-monitoring-plugins/ , can integrate with nagios
其实我就是一个网络搬运工
安装
in nagios server (ubuntu 12.04):
机器A, ip 172.16.21.119
apt-get install libssl-dev openssl
dpkg -L libssl-dev #see libssl.so real path
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so
apt-get install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev
useradd -m -s /bin/bash nagios
passwd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data
mkdir ~/downloads && cd ~/downloads
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
tar xvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure –with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
vim /usr/local/nagios/etc/objects/contacts.cfg #and change email address associated with nagiosadmin
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #and remember the password
/etc/init.d/apache2 reload
cd ..
tar xvf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start
cd ..
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure –prefix=/usr/local/nagios
make all
make install-plugin
/usr/local/nagios/libexec/check_nrpe -H xxx.xxx.xxx.xxx #after nagios client run nrpe deamon, use this to check, xxx.xxx.xxx.xxx is client ip
vim /usr/local/nagios/etc/objects/commands.cfg , add:
define host{
use generic-server ;is checkconfig error, use linux-server instead
host_name uts-app-2
alias uts-app-2
address 172.16.21.59
}
define service{
use generic-service
host_name uts-app-2
service_description load
check_command check_nrpe!check_load
}
echo “cfg_file=/usr/local/nagios/etc/objects/hostA.cfg” >> /usr/local/nagios/etc/nagios.cfg
service nagios reload
see nagios web interface at http://localhost/nagios/
in nagios client(ubuntu 12.04):
机器B, ip 172.16.21.59
apt-get install libssl-dev openssl
dpkg -L libssl-dev #see libssl.so real path
ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/libssl.so
groupadd nagios
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
tar xvf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure –with-nagios-user=nagios –with-nagios-group=nagios –prefix=/usr/local/nagios –with-ping-command=”/bin/ping”
make
make install
ls /usr/local/nagios/libexec #check
cd ..
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure –prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
chown -R nagios:nagios /usr/local/nagios
vi /usr/local/nagios/etc/nrpe.cfg
插件还能输出文本消息。默认情况下,该消息显示在Nagios web界面和Nagios邮件警报信息中。尽管消息并不是硬性要求,你通常还是可以在可用插件中找到它们,因为消息告诉用户出了什么岔子,而不会迫使用户查阅说明文档。
an simple example write by shell to check nginx
vim /usr/local/nagios/libexec/check_nginx
#! /bin/bash
ECHO="/bin/echo"
GREP="/bin/egrep"
DIFF="/usr/bin/diff"
TAIL="/usr/bin/tail"
CAT="/bin/cat"
RM="/bin/rm"
CHMOD="/bin/chmod"
TOUCH="/bin/touch"
PROGNAME=`/usr/bin/basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="0.1"
. $PROGPATH/utils.sh
print_usage() {
echo "Usage: $PROGNAME"
echo "Usage: $PROGNAME --help"
echo "Usage: $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "Check nginx Running or not"
echo ""
support
}
# Grab the command line arguments
exitstatus=$STATE_WARNING #default
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-x)
exitstatus=$2
shift
;;
--exitstatus)
exitstatus=$2
shift
;;
* )
echo "Unknown argument: $1"
print_usage
exit $STATE_UNKNOWN
;;
esac
shift
done
# If the source log file doesn't exist, exit
A=`ps -C nginx --no-header | wc -l`
if [ $A -eq 0 ];then
$ECHO "nginx is not running\n"
exit $STATE_CRITICAL
else
$ECHO "nginx is running with $A processes\n"
exit $STATE_OK
fi
exit $exitstatus
脚本需要可执行权限, 然后和上面添加权限一样添加入nagios即可
cd /usr/local/nagios/
vim etc/objects/contacts.cfg
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email yyy@gmail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
在email那里加上自己的邮箱,如果有多个可以用逗号隔开
修改etc/objects/commands.cfg中notify_host_by_email和notify_service_by_email: