ZK monitor脚本
测试过程中需要实时查看ZK的性能数据,比如outstanding_requests ,可以用zabbix画图或者直接用命令行显示,
下面是我自己写的显示脚本,每秒一行,每10s一个block显示。
#! /bin/bash
zk_ip=$1
count=$2
for (( j=0; j< $count; j++))
do
echo "avg max min rec sent num_conn outstanding_requests state znode watch ephemerals data_size open_file max_file followers synced_fo pending_syncs"
echo "-------------------$(date +"%Y-%m-%d %H:%M:%S")------------------------------------------------------------------------------------------------"
for (( i=0; i<10; i++))
do
echo mntr | nc $zk_ip 2181 | awk 'NR>1 {print $2}' > /tmp/zkstate.log
cmd=(cat /tmp/zkstate.log)
out=$(${cmd[@]})
echo $out
sleep 1
done
done
效果:
# sh monitor.sh 10.199.174.126 100
avg max min rec sent num_conn outstanding_requests state znode watch ephemerals data_size open_file max_file followers synced_fo pending_syncs
-------------------2020-09-17 16:42:49------------------------------------------------------------------------------------------------
9 233 0 82389380 82491775 1143 962 observer 10018 4 0 1412571 1173 65535
9 233 0 82474168 82577513 1143 100 observer 9955 0 0 1403751 1173 65535
9 233 0 82577357 82679848 1143 1061 observer 9306 10 0 1312269 1173 65535
9 233 0 82670911 82773503 1143 961 observer 9306 98 0 1312269 1173 65535
9 233 0 82767837 82870613 1146 987 observer 7700 7 0 1085883 1176 65535
9 233 0 82875978 82978629 1146 1114 observer 7700 114 0 1085883 1176 65535
9 233 0 82975508 83078308 1146 1165 observer 6062 1 0 855185 1176 65535
9 233 0 83081686 83184822 1146 962 observer 5958 7 0 839650 1176 65535
9 233 0 83302313 83405411 1146 1236 observer 6706 6 0 943559 1176 65535
9 233 0 83409579 83513078 1146 886 observer 7161 111 0 1007714 1176 65535
avg max min rec sent num_conn outstanding_requests state znode watch ephemerals data_size open_file max_file followers synced_fo pending_syncs
-------------------2020-09-17 16:43:00------------------------------------------------------------------------------------------------
9 233 0 83519838 83623121 1146 1101 observer 7161 263 0 1007714 1176 65535
9 233 0 83632798 83736234 1146 1328 observer 8559 25 0 1207112 1176 65535
9 233 0 83728784 83832648 1146 965 observer 8049 77 0 1135112 1176 65535
9 233 0 83829132 83933550 1146 583 observer 7321 3 0 1032545 1176 65535
9 233 0 83920833 84025230 1146 683 observer 7135 1 0 1006202 1176 65535
9 233 0 84023589 84127788 1146 989 observer 8666 12 0 1221909 1176 65535
9 233 0 84206997 84311400 1146 968 observer 9905 69 0 1396618 1176 65535