发现队列名称
# cat all_mq.sh
mqarray=(`sudo rabbitmqctl list_queues -p /|grep -Ev 'Listing|done'|awk '{print $1}'`)
length=${#mqarray[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$length;i++))
do
printf '\n\t\t{'
printf "\"{#MQ_NAME}\":\"${mqarray[$i]}\"}"
if [ $i -lt $[$length-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
获取单个队列消息数量
[root@esorabbitmq1 zabbix]# cat get_mq.sh
#!/bin/bash
sudo rabbitmqctl list_queues -p /|grep $1|awk '{print $2}'
zabbix配置-重启zabbix-agent2服务
cat zabbix_agent2.d/all_mq.conf
UserParameter=mq.discovery,/etc/zabbix/all_mq.sh
UserParameter=mq.num[*],/etc/zabbix/get_mq.sh $1
模版