RabbitMQ队列监控
Idle:通过自动发现队列,获取各个队列中的ready,unackd等值
sudo !!!
1 #!/bin/sh 2 discovery(){ 3 Queue=(`rabbitmqctl list_queues |grep -v List |awk '{print $1}'`) 4 len=${#Queue[@]} 5 printf "{\n" 6 printf '\t'"\"data\":[" 7 for ((i=0;i<$len;i++)) 8 do 9 printf '\n\t\t{' 10 printf "\"{#MQ_NAME}\":\"${Queue[$i]}\"}" 11 if [ $i -lt $[$len-1] ];then 12 printf ',' 13 fi 14 done 15 printf "\n\t]\n" 16 printf "}\n" 17 18 } 19
20 21 22 messages(){ 23 QUEUE=$1 24 ROW=`rabbitmqctl list_queues |grep -n $QUEUE |awk -F : '{print $1}'` 25 MESSAGES=`rabbitmqctl list_queues messages |awk 'NR=="'''$ROW'''"{print}'` 26 echo $MESSAGES 27 } 28 ready(){ 29 QUEUE=$1 30 ROW=`rabbitmqctl list_queues |grep -n $QUEUE |awk -F : '{print $1}'` 31 READY=`rabbitmqctl list_queues messages_ready |awk 'NR=="'''$ROW'''"{print}'` 32 echo $READY 33 } 34 unack(){ 35 QUEUE=$1 36 ROW=`rabbitmqctl list_queues |grep -n $QUEUE |awk -F : '{print $1}'` 37 UNACK=`rabbitmqctl list_queues messages_unacknowledged |awk 'NR=="'''$ROW'''"{print}'` 38 echo $UNACK 39 } 40 41 42 if [ $1 == "discovery" ]; then 43 discovery 44 elif [ $1 == "messages" ]; then 45 messages $2 46 elif [ $1 == "ready" ]; then 47 ready $2 48 elif [ $1 == "unack" ]; then 49 unack $2 50 fi
1 UserParameter=rabbitmq.discovery_queue[*],sh /etc/zabbix/zabbix_source/rabbitmq.sh $1 ###自动发现队列 2 UserParameter=rabbitmq.queue.list, sudo rabbitmqctl list_queues |wc -l ###队列个数 3 UserParameter=rabbitmq.consumer.list, sudo rabbitmqctl list_consumers |wc -l ###消费者个数 4 UserParameter=rabbitmq.total.messages[*], sh /etc/zabbix/zabbix_source/rabbitmq.sh messages $1 ###总消息 5 UserParameter=rabbitmq.message.ready[*], sh /etc/zabbix/zabbix_source/rabbitmq.sh ready $1 ###生产数 6 UserParameter=rabbitmq.message.unackd[*], sh /etc/zabbix/zabbix_source/rabbitmq.sh unack $1 ###未消费数
No one indebted for others,while many people don't know how to cherish others.