#! /bin/sh
source ~/.bash_profile
arr_zk=("127.0.0.3:1999" "127.0.0..4:1999" "127.0.0..5:1999")
printf "\n"
date +"###############zookeeper é %Y-%m-%d %H:%M:%S ######################"
check_zk_status()
{
#sysdate=`date "+%Y-%m-%d %H:%M:%S"`
#echo ""
#echo "########## ZK $sysdate ##########"
echo ""
echo "------------------------------------------------------------------------------------------------------------------------------------"
printf "%-16.16s%-10.10s%-20.20s%-10.10s%-10.10s%-16.16s%-16.16s%-10.10s\n" "IP" "Port" "Delay(min/avg/max)" "Accept" "Send" "Connections" "Outstanding" "Mode"· " " "
if [ "${#arr_zk[@]}" = "0" ]
then
echo "zookeeper"
fi
#echo ${#arr_zk[@]}
for((i=0;i<${#arr_zk[@]};i++))
do
# ip
zk_ip=`echo ${arr_zk[i]}|cut -d "," -f1 |cut -d ":" -f1`
zk_port=`echo ${arr_zk[i]}|cut -d "," -f1 |cut -d ":" -f2`
#echo zk_ip:$zk_ip
#echo zk_port:$zk_port
get_zk_info $zk_ip $zk_port
done
}
get_zk_info(){
if [ ! -f $ZOOKEEPER_HOME/share/zookeeper/zookeeper-*.jar ] ; then
echo $ZOOKEEPER_HOME/share/zookeeper/zookeeper-*.jar
else
lib_zk_jar=`echo $ZOOKEEPER_HOME/share/zookeeper/zookeeper-*.jar`
fi
if [ ! -f $ZOOKEEPER_HOME/share/zookeeper/log4j*.jar ] ; then
echo $ZOOKEEPER_HOME/share/zookeeper/log4j*.jar
else
lib_log4j_jar=`echo $ZOOKEEPER_HOME/share/zookeeper/log4j*.jar`
fi
tmp_file=./temp_zk.txt
if ( [ "x$1" != "x" ] && [ "x$2" != "x" ] );then
_zk_ip=$1
_zk_port=$2
# 0 1
_zk_flag=0
_zk_cmd="java -cp $lib_zk_jar:$lib_log4j_jar:.:$CLASSPATH org.apache.zookeeper.client.FourLetterWordMain $_zk_ip $_zk_port srvr "
#echo $_zk_cmd
zk_info=""
#_echo _zk_cmd $_zk_cmd
$_zk_cmd 1> $tmp_file 2>/dev/null
zk_version="-"
zk_Latency="-"
zk_Received="-"
zk_Sent="-"
zk_Connections="-"
zk_Outstanding="-"
zk_Mode="-"
zk_NodeCount="-"
while read oneline ; do
#echo oneline $oneline
if [ "x$oneline" = "x" ];then
continue;
fi
# zk 1 ° ±
if [ `echo $oneline |grep "version" |wc -l` = "1" ];then
#_echo version
zk_version=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_version $zk_version
fi
# zk 2
if [ `echo $oneline |grep "Latency" |wc -l` = "1" ];then
#_echo Latency
zk_Latency=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Latency $zk_Latency
fi
# zk 3
if [ `echo $oneline |grep "Received" |wc -l` = "1" ];then
#_echo Received
zk_Received=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Received $zk_Received
fi
# zk 4 ·
if [ `echo $oneline |grep "Sent" |wc -l` = "1" ];then
#_echo Sent
zk_Sent=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Sent $zk_Sent
fi
# zk 5 Connections
if [ `echo $oneline |grep "Connections" |wc -l` = "1" ];then
#_echo Connections
zk_Connections=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Connections $zk_Connections
fi
# zk 6 Outstanding
if [ `echo $oneline |grep "Outstanding" |wc -l` = "1" ];then
#_echo Outstanding
zk_Outstanding=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Outstanding $zk_Outstanding
fi
# zk 7 Zxid
if [ `echo $oneline |grep "Zxid" |wc -l` = "1" ];then
#_echo Zxid
zk_Zxid=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Zxid $zk_Zxid
fi
# zk 8 Mode
if [ `echo $oneline |grep "Mode" |wc -l` = "1" ];then
#_echo Mode
zk_Mode=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_Mode $zk_Mode
fi
# zk 9 Mode
if [ `echo $oneline |grep "Node count" |wc -l` = "1" ];then
#_echo Node count
zk_NodeCount=`echo $oneline |awk -F ':' '{print $2}'`
#_echo zk_NodeCount $zk_NodeCount
fi
done < $tmp_file
#printf "%-16.16s%-10.10s%-19.19s%-10.10s%-10.10s%-16.16s%-16.16s%-10.10s\n" "$_zk_ip" "$_zk_port" "$zk_Latency" "$zk_Received" "$zk_Sent" "$zk_Connections" "$zk_Outstanding" "$zk_Mode"
#printf "%-16.16s%-10.10s%-10.10s\n" "$_zk_ip" "$_zk_port" "$zk_Mode"
printf "%-16.16s%-10.10s%-20.20s%-10.10s%-10.10s%-16.16s%-16.16s%-10.10s\n" "$_zk_ip" "$_zk_port" "$zk_Latency" "$zk_Received" "$zk_Sent" "$zk_Connections" "$zk_Outstanding" "$zk_Mode"
fi
rm -f $tmp_file
}
check_zk_status
网友评论