四字命令详解:
方式一:
zookeeper中间件服务状态:echo ruok |nc |localhost 2181
imok
zookeeper中间件服务性能:echo mntr |nc |localhost 2181
方式二:
zookeeper中间件服务状态:(echo ruok;sleep 2) |telnet localhost $zk_port 2>/dev/null |sed -n '4p'
imok
zookeeper中间件服务性能:(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep $zk_mntr |awk '{print $2}'
脚本逻辑:
1.zookeeper中间件服务状态
zk_port=$1
ruok=`(echo ruok;sleep 2) |telnet localhost $zk_port 2>/dev/null | sed -n '4p'`
if [ -n "$ruok" ];then
echo $ruok
echo "`date +%y%m%d-%H:%M:%S`$zk_ruok:$ruok" >> $logfile
else
echo NO
echo "`date +%y%m%d-%H:%M:%S`$zk_ruok:NO" >> $logfile
fi
2.zookeeper中间件服务性能
zk_port=$1
mntr=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep $zk_mntr |awk '{print $2}'`
if [ -n "$mntr" ];then
echo $mntr
echo "`date +%y%m%d-%H:%M:%S`$zk_mntr:$mntr" >> $logfile
else
echo 0
echo "`date +%y%m%d-%H:%M:%S`$zk_ruok:0" >> $logfile
fi