Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Check MySQL Replication Slave Status
2019082203
2019-08-22
- Nagios 1.x
- Nagios 2.x
- Nagios 3.x
- Nagios 4.x
- Nagios XI
ClaudioKuenzler
GPL
148485
Meet The New Nagios Core Services Platform
Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.
Monitoring Made Magically Better
- Nagios Core on Overdrive
- Powerful Monitoring Dashboards
- Time-Saving Configuration Wizards
- Open Source Powered Monitoring On Steroids
- And So Much More!
Please see the following website for full documentation and download:
https://www.claudiokuenzler.com/monitoring-plugins/check_mysql_slavestatus.php
*** Description ***
Written in bash/shell this script is very easy to use and implement into your Nagios monitoring.
It's a very modified version of the script 'check mysql slave sql running' by dhirajt.
If you find a bug or have ideas, feel free to add it to the script or contact me.
*** Usage ***
./check_mysql_slavestatus.sh (-o file|(-H dbhost [-P port]|-S socket) -u username -p password) [-s connection] [-w integer] [-c integer] [-m TBD]
*** Change History ***
2008041700 Original Script modified
2008041701 Added additional info if status OK
2008041702 Added usage of script with params -H -u -p
2008041703 Added bindir variable for multiple platforms
2008041704 Added help because mankind needs help
2008093000 Using /bin/sh instead of /bin/bash (Victor Balada Diaz)
2008093001 Added port for MySQL server (Victor Balada Diaz)
2008093002 Added mysqldir if mysql binary is elsewhere (Victor Balada Diaz)
2008101501 Changed bindir/mysqldir to use PATH (Soren Klintrup)
2008101501 Use $() instead of `` to avoid forks (Soren Klintrup)
2008101501 Use ${} for variables to prevent problems (Soren Klintrup)
2008101501 Check if required commands exist (Soren Klintrup)
2008101501 Check if mysql connection works (Soren Klintrup)
2008101501 Exit with unknown status at script end (Soren Klintrup)
2008101501 Also display help if no option is given (Soren Klintrup)
2008101501 Add warning/critical check to delay (Soren Klintrup)
2011062200 Add perfdata (Philippe Barsalou)
2011122700 Checking Slave_IO_Running (Marc Feret)
2012080300 Changed to use only one mysql query (Peter Lecki)
2012080301 Added warn and crit delay as optional args (Peter Lecki)
2012080302 Added standard -h option for syntax help (Peter Lecki)
2012080303 Added check for mandatory options passed in (Peter Lecki)
2012080304 Added error output from mysql (Peter Lecki)
2012080305 Changed from 'cut' to 'awk' (eliminate ws) (Peter Lecki)
2012111600 Do not show password in error output
2013042800 Changed PATH to use existing PATH, too
2013050800 Bugfix in PATH export
2013092700 Bugfix in PATH export
2013092701 Bugfix in getopts
2013101600 Rewrite of threshold logic and handling #
2013101601 Optical clean up #
2013101602 Rewrite help output #
2013101700 Handle Slave IO in 'Connecting' state #
2013101701 Minor changes in output, handling UNKWNON situations now #
2013101702 Exit CRITICAL when Slave IO in Connecting state #
2013123000 Slave_SQL_Running also matched Slave_SQL_Running_State
2015011600 Added 'moving' check to catch possible connection issues
2015011900 Use its own threshold for replication moving check
2019082200 Add support for mysql option file (Marc Falzon)
2019082201 Improve password security (remove from mysql cli)
2019082202 Added socket parameter (-S) (Andreas Pfeiffer)
2019082203 Use default port 3306, makes -P optional
https://www.claudiokuenzler.com/monitoring-plugins/check_mysql_slavestatus.php
*** Description ***
Written in bash/shell this script is very easy to use and implement into your Nagios monitoring.
It's a very modified version of the script 'check mysql slave sql running' by dhirajt.
If you find a bug or have ideas, feel free to add it to the script or contact me.
*** Usage ***
./check_mysql_slavestatus.sh (-o file|(-H dbhost [-P port]|-S socket) -u username -p password) [-s connection] [-w integer] [-c integer] [-m TBD]
*** Change History ***
2008041700 Original Script modified
2008041701 Added additional info if status OK
2008041702 Added usage of script with params -H -u -p
2008041703 Added bindir variable for multiple platforms
2008041704 Added help because mankind needs help
2008093000 Using /bin/sh instead of /bin/bash (Victor Balada Diaz)
2008093001 Added port for MySQL server (Victor Balada Diaz)
2008093002 Added mysqldir if mysql binary is elsewhere (Victor Balada Diaz)
2008101501 Changed bindir/mysqldir to use PATH (Soren Klintrup)
2008101501 Use $() instead of `` to avoid forks (Soren Klintrup)
2008101501 Use ${} for variables to prevent problems (Soren Klintrup)
2008101501 Check if required commands exist (Soren Klintrup)
2008101501 Check if mysql connection works (Soren Klintrup)
2008101501 Exit with unknown status at script end (Soren Klintrup)
2008101501 Also display help if no option is given (Soren Klintrup)
2008101501 Add warning/critical check to delay (Soren Klintrup)
2011062200 Add perfdata (Philippe Barsalou)
2011122700 Checking Slave_IO_Running (Marc Feret)
2012080300 Changed to use only one mysql query (Peter Lecki)
2012080301 Added warn and crit delay as optional args (Peter Lecki)
2012080302 Added standard -h option for syntax help (Peter Lecki)
2012080303 Added check for mandatory options passed in (Peter Lecki)
2012080304 Added error output from mysql (Peter Lecki)
2012080305 Changed from 'cut' to 'awk' (eliminate ws) (Peter Lecki)
2012111600 Do not show password in error output
2013042800 Changed PATH to use existing PATH, too
2013050800 Bugfix in PATH export
2013092700 Bugfix in PATH export
2013092701 Bugfix in getopts
2013101600 Rewrite of threshold logic and handling #
2013101601 Optical clean up #
2013101602 Rewrite help output #
2013101700 Handle Slave IO in 'Connecting' state #
2013101701 Minor changes in output, handling UNKWNON situations now #
2013101702 Exit CRITICAL when Slave IO in Connecting state #
2013123000 Slave_SQL_Running also matched Slave_SQL_Running_State
2015011600 Added 'moving' check to catch possible connection issues
2015011900 Use its own threshold for replication moving check
2019082200 Add support for mysql option file (Marc Falzon)
2019082201 Improve password security (remove from mysql cli)
2019082202 Added socket parameter (-S) (Andreas Pfeiffer)
2019082203 Use default port 3306, makes -P optional
Reviews (4)
bybrokenbuddha, March 10, 2023
It doesn't work even if you create a user with the same privileges as root, if the username isn't root it fails to retrieve any information.
byainfantino, July 18, 2014
Hi, great plugin!
Forgot though to add the warning and critical thresholds in the performance output when thresholds are being used :
if [[ ${delayinfo} -ge ${crit_delay} ]]
then echo "CRITICAL: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;"; exit ${STATE_CRITICAL}
elif [[ ${delayinfo} -ge ${warn_delay} ]]
then echo "WARNING: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;"; exit ${STATE_WARNING}
else echo "OK: Slave SQL running: ${check} Slave IO running: ${checkio} / master: ${masterinfo} / slave is ${delayinfo} seconds behind master | delay=${delayinfo}s;"; exit
==>
if [[ ${delayinfo} -ge ${crit_delay} ]]
then echo "CRITICAL: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit ${STATE_CRITICAL}
elif [[ ${delayinfo} -ge ${warn_delay} ]]
then echo "WARNING: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit ${STATE_WARNING}
else echo "OK: Slave SQL running: ${check} Slave IO running: ${checkio} / master: ${masterinfo} / slave is ${delayinfo} seconds behind master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit
Forgot though to add the warning and critical thresholds in the performance output when thresholds are being used :
if [[ ${delayinfo} -ge ${crit_delay} ]]
then echo "CRITICAL: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;"; exit ${STATE_CRITICAL}
elif [[ ${delayinfo} -ge ${warn_delay} ]]
then echo "WARNING: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;"; exit ${STATE_WARNING}
else echo "OK: Slave SQL running: ${check} Slave IO running: ${checkio} / master: ${masterinfo} / slave is ${delayinfo} seconds behind master | delay=${delayinfo}s;"; exit
==>
if [[ ${delayinfo} -ge ${crit_delay} ]]
then echo "CRITICAL: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit ${STATE_CRITICAL}
elif [[ ${delayinfo} -ge ${warn_delay} ]]
then echo "WARNING: Slave is ${delayinfo} seconds behind Master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit ${STATE_WARNING}
else echo "OK: Slave SQL running: ${check} Slave IO running: ${checkio} / master: ${masterinfo} / slave is ${delayinfo} seconds behind master | delay=${delayinfo}s;$warn_delay;$crit_delay;;"; exit
Hello,
Plugin wroks great only it would be good if support for mariadb would be added
Plugin wroks great only it would be good if support for mariadb would be added
Owner's reply
It works with MySQL and other forks, as MariaDB or Percona.
bychrislaskey, February 23, 2014
1 of 1 people found this review helpful
Easy to setup, straight forward options and correct reporting. Very pleased. Keep up the great work. Thanks!