PluginPortrait/mysql_slave_status: mysql_slave_status

File mysql_slave_status, 1.7 KB (added by anonymous, at 2006-06-21T00:14:38+02:00)
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
23mysqlcommand=$mysql
24if [ "X$mysqlcommand" = "X" ]; then
25        mysqlcommand=mysql
26fi
27
28if [ "X$mysqlopts" != "X" ]; then
29        mysqlcommand="$mysqlcommand $mysqlopts"
30fi
31
32if [ "$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
44fi
45
46slave_io_running=0
47slave_sql_running=0
48seconds_behind_master=NaN
49
50tmpfile="/tmp/.`basename $0`.tmp.$$"
51echo 'SHOW SLAVE STATUS\G' | $mysqlcommand > $tmpfile
52
53OLDIFS=$IFS
54IFS='
55'
56for 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
72done
73
74if [ $slave_io_running != 1 -o $slave_sql_running != 1 ]; then
75        seconds_behind_master=NaN
76fi
77
78IFS=$OLDIFS
79rm -f $tmpfile
80
81echo "seconds_behind_master.value $seconds_behind_master"