#!/bin/bash
#
# Simple tool displaying status of Spark, HBase, and HDFS on current machine
# and all registered slaves.
#
# $Id: //guest/cmclouth/projects/htd-deployment/htd-source/tools/statusanalytics.sh#4 $
#
function checkforrunning() {
# echo "$@"
expected=0
for parm in $@; do
if [ $expected -gt 0 ]; then
if [ -z $regex ]; then
regex="\<$parm\>"
else
regex="$regex\|\<$parm\>"
fi
else
remoteserver=$parm
unset regex
fi
((expected += 1))
done
((expected -= 1))
if [ "$remoteserver" = "$HOSTNAME" ]; then
found=$(jps | grep -v "^.* Jps$" | grep "$regex" | wc -l)
else
found=$(ssh "$remoteserver" jps | grep -v "^.* Jps$" | grep "$regex" | wc -l)
fi
if [ $found -eq $expected ]; then
echo "all services running on $remoteserver: $@."
else
# determine which ones are missing
expected=0
for parm in $@; do
if [ $expected -gt 0 ]; then
regex="\<$parm\>"
if [ "$remoteserver" = "$HOSTNAME" ]; then
found=$(jps | grep -v "^.* Jps$" | grep "$regex" | wc -l)
else
found=$(ssh "$remoteserver" jps | grep -v "^.* Jps$" | grep "$regex" | wc -l)
fi
if [ $found -lt 1 ]; then
if [ -z notfound ]; then
notfound="$parm"
else
notfound="$notfound $parm"
fi
fi
fi
((expected += 1))
done
echo "expected services not running on $remoteserver: $notfound."
fi
}
function checkforslaves() {
for htdanalyticsdataslave in $(grep -v "^$" "/opt/interset/hadoop/etc/hadoop/slaves" | grep -v "^#"); do
checkforrunning "$htdanalyticsdataslave" $@
done
}
HOSTNAME=$(hostname)
echo "Status of $HOSTNAME"
checkforrunning "$HOSTNAME" "NameNode" "SecondaryNameNode" "HQuorumPeer" "HMaster" "Master"
# check slaves
echo "Status of slaves"
checkforslaves "DataNode" "HRegionServer" "Worker"