# NDB CLUSTER MONITOR
# script for monitoring mysql-cluster status data/ndb/mgmnodes

NDB_MGM=”ndb_mgm”
ndb_ps=`ps -ef|grep “ndb_mgmd”|grep -v grep |wc -l`
node_count=`$NDB_MGM -e “show” |grep -w “id”|wc -l`

echo ${Log}
> ${Log}

if [ $ndb_ps -ne 1 ] ; then
echo “Looks like NDB_MGMD is not running”
echo “check MANAGEMENT Node status”
exit 1
### need to work on this condition.
else
echo “MANAGEMENT Node is up, proceed with next step”
echo “checking individual node status”
$NDB_MGM -e “show”|grep -w “id”|awk ‘{print $1}’|cut -c 4- |while read node_id
do
# check to see ndbd_mgm daemon is running on $HOST and
# node are running
NODE_STATUS=`$NDB_MGM -e “$node_id status” | egrep -v ‘(Connected to Management Server|^$)’`
case $NODE_STATUS in
*started*)
## echo “for datanode if status is started then ndbd is up”
echo “OK – $NODE_STATUS” >>${Log}
;;
“Node $node_id: connected”*)
## echo “for MGMD & SQL if status is connected then things are fine”
echo “OK – $NODE_STATUS” >>${Log}
;;
*starting*)
echo “WARRING – $NODE_STATUS” >>${Log}
;;
*)
echo “ERROR – $NODE_STATUS” >>${Log}
;;
esac
# done with all nodes
done
fi ## closing if

cnt=`cat ${Log}|grep -vw “OK”|wc -l`
if [ $cnt -eq 0 ] ; then
echo “ALL NODE STATUS is FINE”
cat ${Log}
exit 0
else
echo “${Header.Start}”
echo “CHECK MYSQL-CLUSTER NODE STATUS”
$NDB_MGM -e “show”
echo “${Header.Stop}”
exit 1
fi