zabbix監控activemq隊列腳本


  公司業務使用activemq5.9.1消息隊列,由於隊列阻塞導致程序端口無響應,並且telnet無法連通。經過over 1 hour的排查,最終定位原因activemq導致。遂寫了一個監控activemq隊列信息的腳本。

 

一、腳本部分

1.腳本內容,如下:

[root@localhost ~]# cat activemqqueue.sh 
#!/bin/bash #author:xkops #define common info HOST=10.44.144.92 PORT=8161 USER=admin PASSWORD=admin #obtain queue's Pending,Consumers,Enqueued,Dequeued function Queue() { Count=$(curl -u"$USER":"$PASSWORD" http://$HOST:$PORT/admin/queues.jsp 2> /dev/null |grep -A 5 "^$1"|grep -oP '\d+'); #echo $Count Pending=$(echo $Count |awk '{print $1}'); #echo $Count Consumers=$(echo $Count |awk '{print $2}'); Enqueued=$(echo $Count |awk '{print $3}'); Dequeued=$(echo $Count |awk '{print $4}'); #EndeltaDn=$(($Enqueued - $Dequeued)) #echo '-------------' #echo -e "$Pending\n$Consumers\n$Enqueued\n$Dequeued"; #echo "$2" if [ "$2" = '' ];then exit fi if [ "$2" = 'Pending' ];then echo $Pending elif [ "$2" = 'Consumers' ];then echo $Consumers elif [ "$2" = 'Enqueued' ];then echo $Enqueued #elif [ "$2" = 'EndeltaDn' ];then # echo $EndeltaDn else echo $Dequeued fi } #call function and input queue_name queue_type Queue $1 $2

2.測試執行腳本,需要傳入2個參數,其中一個是對列名稱,一個是隊列類型(如Pending,Consumers,Enqueued,Dnqueued)

[root@localhost ~]# bash activemqqueue.sh message.push Consumers
32

 

二、zabbix監控部分

1.編輯配置文件

[root@localhost ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_activemqqueue.conf
# monitor tomcat process and port
UserParameter=tomcatamqqueue[*],/etc/scripts/activemqqueue.sh $1 $2

2.創建zabbix模板,並傳遞相應的隊列名稱和隊列類型。根據下圖依次創建自己的item。

3.創建展示Pending,Consumers,Enqueued,Dequeued等圖表。

4.觸發報警,當Pending的值大於某一個值時報警,比如1000。

5.郵件發送。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM