| 1 |
#!/bin/sh |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 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" |
|---|