here is a simple demonstration of how nagios can be used to customize the system for monitoring under Linux systems. Nagios's monitoring process in Linux uses the Nrpe client to invoke scripts in the/usr/lib64/nagios/plugins/directory and then returns the retrieved data to Nagios, which returns different status values and some information. Nagios is based on these return values to determine whether the service status is normal and whether an alarm is required. These status values are described as follows:
1, the returned status value is 0, indicates OK, no exception.
2, the returned status value is 1, indicates warning, will trigger warning alarm.
3, the returned status value is 2, indicates critical, will trigger critical alarm.
4, the return status of 3, indicating unknown,
that's a detailed description of how to customize the number of connections to the monitoring database through scripting:
The first step: Write a script to get the data, the script explicitly defines the returned status code,
My software is installed in Yum.
The script reads as follows:
vi /usr/lib64/nagios/plugins/check_mysql_connections#!/bin/bash#written by sjf#this Nagios plugin can be check your mysql connections statususage_method= " $ (basename $0) [-w|--warning] [-c|--critical] "usage_value=" Warning value must be small than CRITICAL value: ' basename $0 ' $* "mysqluser= Nagiosmysqlps=nagiosadminmysqlbin=/usr/bin/mysqlstate_ok=0state_warning=1state_critical=2state_unknown=3if [ $# -lt 4 ];thenechoecho "usage: $USAGE _method" Echoexit 0fiwhile &NBSP;[&NBSP;$#&NBSP;-GT&NBSP;0&NBSP,];d ocase "$" in-w|--warning) shiftwarning=$1;; -c|--critical) shiftcritical=$1;; esacshiftdoneif [[ $WARNING -eq $CRITICAL | | $WARNING -gt $CRITICAL ]]thenechoecho "$USAGE _value" echoecho "usage: $ Usage_method "echoexit 0fiused_connections=$ ($MYSQLBIN -u$mysqluser -p$mysqlps -e "show status like ' Threads_connected ' \G" | grep "Value" | awk ' {print $2} ') max_connections=$ ($MYSQLBIN -u$mysqluser -p$MYSQLPS -e "show variables like ' max_connections ' \g" | grep " Value " | awk ' {print $2} ') percent=$ (bc <<< " scale=2; $used _connections/$ Max_connections ' | tr ' ^. ' ' ') if [[ "$PERCENT" -gt "$CRITICAL" ]]thenecho "critical - used_connections is : $used _connections "exit 2fiif [[ " $PERCENT " -gt $WARNING && $PERCENT -lt $CRITICAL ]]thenecho warning - used_connections is : $used _connections "exit 1fiif [[ " $PERCENT " -lt "$WARNING" ]]thenecho "ok - used_connections is : "$used _connections "Exit 0fi
Because this involves MySQL database permissions, so you need to add Naigos account in MySQL, this step Operation command is as follows:
GRANT PROCESS, FILE, SUPER, REPLICATION CLIENT on * * to ' nagios ' @ ' localhost ' identified by ' nagiosadmin '; FLUSH privileges;
The second step: Configure the NRPE.CNF configuration file, define the command to get the data for the Nagios server-side call, configured as follows:
Vim/etc/nrpe.cfgcommand[check_mysql_connections]=/usr/lib64/nagios/plugins/check_mysql_connections-w 75-c 85
After saving, restart the Nrpe client and execute the following command:
Killall nrpenrpe-c/etc/nagios/nrpe.cfg-d
Step three: Define commands in the command configuration file
Vi/etc/nagios/objects/commands.cfg define command{command_name check_mysql_connections command_line $USER 1$/check_mysql_connections-h $HOSTADDRESS $-C $ARG 1$}
Fourth step: In the Nagios server-side configuration server call this command for monitoring, configured as follows:
Define Service {Use Generic-servicehost_name www.sjf.comservice_description check_mysql_connectionscheck_period 24x7notifications_enabled 1max_check_attempts 3normal_check_interval 3retry_check_interval 2contact_groups Adminsnotification_interval 10notification_period 24x7notification_options W,u,c,rcheck_command check_mysql_ Connections
After checking the configuration problem Finally, reload the Nagios configuration with the following command:
Nagios-v/etc/nagios/nagios.cfgsystemctl Restart Nagios
At this point the whole process of monitoring MySQL connections is complete even if added. Other custom monitoring is the same, with the script to change a little bit can be done.
But here is a problem, each version of the variable may change, this small partners should pay attention to the version, I hope to be helpful!
This article is from the "11876896" blog, please be sure to keep this source http://11886896.blog.51cto.com/11876896/1874537
Nagios custom monitoring of the system via scripting