And so nobody else has to flounder like I did, here is the script.
- Import into File Management -> External Monitor Program File List
- Create health monitor -> External
- Set Interval and Timeout ( I am using 30/91)
- Select the script you created in step 1
- Add the following Variables
- Name: query , Value: select @@read_only;
- Name: result, Value: 0
- Name: pass, Value: <password here>
Value of 0 (zero) indicates Read/Write (Master) node, value of 1 (one) indicates read-only node.
Here is the script:
#!/bin/bash
# Name of the pidfile
pidfile="/var/run/$MONITOR_NAME.$1..$2.pid"
# Send signal to the process group to kill our former self and any children
# as external monitors are run with SIGHUP blocked
if [ -f $pidfile ]
then
kill -9 -`cat $pidfile` > /dev/null 2>&1
fi
echo "$$" > $pidfile
# Remove the IPv6/IPv4 compatibility prefix
node_addr=`echo $1 | sed 's/::ffff://'`
# pass, query, and result are passed as variables
# from the Health Monitor definition
# Search the data received for the expected expression.
# Replace "<monitoring username here>" with the user you wish to log into mysql with
/bin/mysql -sN -u <monitoring username here> -p${pass} -h ${node_addr} -P $2 -e "${query}" 2> /dev/null | grep -E -i ${result} > /dev/null
status=$?
if [ $status -eq 0 ]
then
# Remove the pidfile before the script echoes anything to stdout and is killed by bigd
rm -f $pidfile
echo "up"
fi
# Remove the pidfile before the script ends
rm -f $pidfile