-
Zabbix 3.4 提供了用于自动发现 Activemq 监控模板的功能
资源介绍
用zabbix 自动发现实现activemq 监控pending consumers
activemq_scan.sh
#!/bin/bash
activemq() {
MQ_IP=(10.10.11.208:8161)
for g in ${MQ_IP[@]}
do
port=($(curl -uadmin:admin http://${g}/admin/queues.jsp 2>/dev/null| grep -A 4 "${QUEUENAME}"|awk -F '<' '{print $1}'|grep '^[a-Z]'))
done
#遍历输出port数组
printf '{\n'
printf '\t"data":[\n'
for key in ${!port[@]}
do
if [[ "${#port[@]}" -gt 1 && "${key}" -ne "$((${#port[@]}-1))" ]];then
printf '\t {\n'
printf "\t\t\t\"{#QUEUENAME}\":\"${port[${key}]}\"},\n"
else [[ "${key}" -eq "((${#port[@]}-1))" ]]
printf '\t {\n'
printf "\t\t\t\"{#QUEUENAME}\":\"${port[${key}]}\"}\n"
fi
done
printf '\t ]\n'
printf '}\n'
}
activemq $1
################################
activemq_status.sh
#!/bin/bash
#
#Description: get activemq data
#
#Var
IP=10.10.11.208
PORT=8161
QUEUENAME=$1
case $2 in
Pending|pending)
Pending=`curl -uadmin:admin http://$IP:$PORT/admin/queues.jsp 2> /dev/null | grep -A 4 "${QUEUENAME}"|awk -F '<' '{print $2}'|sed 's/td>//g'|grep '^[0-9]'|head -1`
echo $Pending
;;
Consumers|consumers)
Consumers=`curl -uadmin:admin http://$IP:$PORT/admin/queues.jsp 2> /dev/null | grep -A 4 "${QUEUENAME}"|awk -F '<' '{print $2}'|sed 's/td>//g'|grep '^[0-9]'|head -2|tail -1`
echo $Consumers
;;
Enqueued|enqueued)
Enqueued=`curl -uadmin:admin http://$IP:$PORT/admin/queues.jsp 2> /dev/null | grep -A 4 "${QUEUENAME}"|awk -F '<' '{print $2}'|sed 's/td>//g'|grep '^[0-9]'|head -3|tail -1`
echo $Enqueued
;;
Dequeued|dequeued)
Dequeued=`curl -uadmin:admin http://$IP:$PORT/admin/queues.jsp 2> /dev/null | grep -A 4 "${QUEUENAME}"|awk -F '<' '{print $2}'|sed 's/td>//g'|grep '^[0-9]'|head -4|tail -1`
echo $Dequeued
;;
*)
echo "Usage: $0 Consumers|Enqueued|Dequeued"
esac
##############################
在 zabbix.confi添加
UnsafeUserParameters=1
UserParameter=mq.mqScan,/etc/zabbix/zabbix_agentd.d/activemq_scan.sh
UserParameter=mq.status[*],/etc/zabbix/zabbix_agentd.d/activemq_status.sh $1 $2