plugin-mysql_slave_status: mysql_slave_status

File mysql_slave_status, 1.7 kB (added by anonymous, 6 years ago)
Line 
1 #!/bin/sh
2
3 ## Copyright 2006 Tailrank Inc.  Released under BSD + LGPL licenses.
4 #
5 # Kevin Burton (burton@tailrank.com)
6 #
7 # Graphs "seconds behind master" for MySQL replication slaves
8 #
9 # Modified by Vincent Rivellino <vince at cuz dot cx>
10 #  - added config variables
11 #  - added checks for Slave SQL Running and Slave IO Running
12
13 # Parameters:
14 #
15 #   config
16 #
17 # Configuration variables
18 #
19 #   mysqlopts     - Options to pass to mysql
20 #   mysql         - Set path to mysql command
21 #
22
23 mysqlcommand=$mysql
24 if [ "X$mysqlcommand" = "X" ]; then
25         mysqlcommand=mysql
26 fi
27
28 if [ "X$mysqlopts" != "X" ]; then
29         mysqlcommand="$mysqlcommand $mysqlopts"
30 fi
31
32 if [ "$1" = "config" ]; then
33
34         echo "graph_title MySQL Slave Status"
35         echo "graph_vlabel slave status"
36         echo "graph_category mysql"
37
38         echo "seconds_behind_master.label Seconds Behind Master"
39         echo "seconds_behind_master.min 0"
40         echo "seconds_behind_master.type GAUGE"
41         echo "seconds_behind_master.draw AREA"
42
43         exit 0
44 fi
45
46 slave_io_running=0
47 slave_sql_running=0
48 seconds_behind_master=NaN
49
50 tmpfile="/tmp/.`basename $0`.tmp.$$"
51 echo 'SHOW SLAVE STATUS\G' | $mysqlcommand > $tmpfile
52
53 OLDIFS=$IFS
54 IFS='
55 '
56 for line in `cat $tmpfile`; do
57         if echo $line | grep -q Slave_IO_Running ; then
58                 if echo $line | grep -qi yes; then
59                         slave_io_running=1
60                 fi
61         fi
62
63         if echo $line | grep -q Slave_SQL_Running ; then
64                 if echo $line | grep -qi yes; then
65                         slave_sql_running=1
66                 fi
67         fi
68
69         if echo $line | grep -q Seconds_Behind_Master ; then
70                 seconds_behind_master=`echo $line | grep -oE [0-9]+$`
71         fi
72 done
73
74 if [ $slave_io_running != 1 -o $slave_sql_running != 1 ]; then
75         seconds_behind_master=NaN
76 fi
77
78 IFS=$OLDIFS
79 rm -f $tmpfile
80
81 echo "seconds_behind_master.value $seconds_behind_master"