ZABBIX开发Zookeeper中间件服务性能监控
脚本内容:
#!/bin/sh
###################################################
# Used to obtain Zookeeper middleware service performance information
# script by shell
# writed by Deliver
# huchangxi 2022/11/15
###################################################
# 脚本运行超时处理
source /usr/local/zabbix-agent/etc/scripts/zabbixtimeout.sh
##########################################################################
#获取Zookeeper中间件性能信息,再根据选项获取相应值
zk_port=$1
zk_mntr=$2
case $zk_mntr in
#版本
zk_version)
version=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_version |grep awk '{print $2}'`
if [ -n "version" ];then
echo $version
else
echo NO
fi
;;
#平均延时
zk_avg_latency)
avg_latency=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_avg_latency |grep awk '{print $2}'`
if [ -n "avg_latency" ];then
echo $avg_latency
else
echo 0
fi
;;
#最大延时
zk_max_latency)
max_latency=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_max_latency |grep awk '{print $2}'`
if [ -n "max_latency" ];then
echo $max_latency
else
echo 0
fi
;;
#最小延时
zk_min_latency)
min_latency=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_min_latency |grep awk '{print $2}'`
if [ -n "min_latency" ];then
echo $min_latency
else
echo 0
fi
;;
#收包数
zk_packets_received)
packets_received=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_packets_received |grep awk '{print $2}'`
if [ -n "packets_received" ];then
echo $packets_received
else
echo 0
fi
;;
#发包数
zk_packets_sent)
packets_sent=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_packets_sent |grep awk '{print $2}'`
if [ -n "packets_sent" ];then
echo $packets_sent
else
echo 0
fi
;;
#连接数
zk_num_alive_connections)
num_alive_connections=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_num_alive_connections |grep awk '{print $2}'`
if [ -n "num_alive_connections" ];then
echo $num_alive_connections
else
echo 0
fi
;;
#堆积请求数
zk_outstanding_requests)
outstanding_requests=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_outstanding_requests |grep awk '{print $2}'`
if [ -n "outstanding_requests" ];then
echo $outstanding_requests
else
echo 0
fi
;;
#节点状态
zk_server_state)
server_state=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_server_state |grep awk '{print $2}'`
if [ -n "server_state" ];then
echo $server_state
else
echo NO
fi
;;
#znode数量
zk_znode_count)
znode_count=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_znode_count |grep awk '{print $2}'`
if [ -n "znode_count" ];then
echo $znode_count
else
echo 0
fi
;;
#watch数量
zk_watch_count)
watch_count=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | grep zk_watch_count |grep awk '{print $2}'`
if [ -n "watch_count" ];then
echo $watch_count
else
echo 0
fi
;;
#临时节点(znode)
zk_ephemerals_count)
ephemerals_count=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | zk_ephemerals_count |grep awk '{print $2}'`
if [ -n "ephemerals_count" ];then
echo $ephemerals_count
else
echo 0
fi
;;
#数据大小
zk_approximate_data_size)
approximate_data_size=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | zk_approximate_data_size |grep awk '{print $2}'`
if [ -n "approximate_data_size" ];then
echo $approximate_data_size
else
echo 0
fi
;;
#打开的文件描述符数量
zk_open_file_descriptor_count)
open_file_descriptor_count=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | zk_open_file_descriptor_count |grep awk '{print $2}'`
if [ -n "open_file_descriptor_count" ];then
echo $open_file_descriptor_count
else
echo 0
fi
;;
#最大文件描述符数量
zk_max_file_descriptor_count)
max_file_descriptor_count=`(echo mntr;sleep 2) |telnet localhost $zk_port 2>/dev/null | zk_max_file_descriptor_count |grep awk '{print $2}'`
if [ -n "max_file_descriptor_count" ];then
echo $max_file_descriptor_count
else
echo 0
fi
;;
#通配规则
*)
echo -e "\e[033mUsage: $0 {zk_port|zk_mntr} \e[0m"
esac
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?