Zabbix3.2监控RabbitMQ
程序员文章站
2022-07-11 11:47:21
...
Zabbix监控QQ交流群:9888359 欢迎喜欢交流的朋友加入!
一、监控脚本
vim discovery_rabbitmq
#!/bin/sh
#RMQ_HOME=/opt/appl/olrmq/rabbitmq
#PATH=$PATH:$HOME/bin:$RMQ_HOME/sbin
#export PATH
discovery(){
Queue=(`rabbitmqctl list_queues |grep -v List |awk '{print $1}'`)
len=${#Queue[@]}
printf "{\n"
printf '\t'"\"data\":["
for ((i=0;i<$len;i++))
do
printf '\n\t\t{'
printf "\"{#MQ_NAME}\":\"${Queue[$i]}\"}"
if [ $i -lt $[$len-1] ];then
printf ','
fi
done
printf "\n\t]\n"
printf "}\n"
}
discovery
vim zabbix_rabbitmq.sh
#!/bin/bash
RMQ_HOME=/opt/appl/rabbitmq/rmq
PATH=$PATH:$HOME/bin:$RMQ_HOME/sbin
ERLANG_HOME=/usr/local/erlang
PATH=$PATH:$ERLANG_HOME/bin
export PATH
RMQ_COMMAND=$1
QUEUE=$2
function list_queues_status {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_queues |grep "$QUEUE"|grep -v List |awk '{print $2}'
}
function list_queues {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_queues |grep -v List |wc -l
}
function list_consumers {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_consumers |grep -v List |wc -l
}
function list_channels_state {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_channels state |grep -v List |wc -l
}
function list_connections_state {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_connections state |grep -v List |wc -l
}
function list_connections_name {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl list_connections name state |grep -v List |wc -l
}
function disk_free {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl status|grep -A1 disk |grep "disk_free,"|awk -F [{,\}] '{print $3/1024/1024/1024}'|awk '{print int($1+0.5)}'
}
function memory_free {
limt=`/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl status|grep -A1 memory |grep "vm_memory_limit"|awk -F [{,\}] '{print $3}'`
free=`/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl status|grep -A1 memory |grep "total,"|awk -F [{,\}] '{print $3}'`
echo "$free $limt"|awk '{printf("%0.2f\n",$1/$2*100)}'
# echo 100
}
function health_check {
/opt/appl/olrmq/rabbitmq/sbin/rabbitmqctl node_health_check 2>&1 |grep "Health check passed" 2>&1 >/dev/null
if [ $? -ne 0 ];then
echo "1"
else
echo "0"
fi
}
case $RMQ_COMMAND in
ram_status)
list_queues_status ;;
check_queues)
list_queues ;;
check_consumers)
list_consumers ;;
check_channels)
list_channels_state ;;
check_connections)
list_connections_name ;;
check_disk)
disk_free ;;
check_memory)
memory_free ;;
check_health)
health_check ;;
*)
echo -e "Usage: $0 [ram_status key| check_queues|check_consumers |check_channels |check_connections|check_disk|check_memory|check_health] "
esac
vim zabbix_mq.conf
UserParameter=rabbitmq.discovery_queue[*],/etc/zabbix/scripts/discovery_rabbitmq "$1"
UserParameter=rabbitmq[*],/etc/zabbix/scripts/zabbix_rabbitmq.sh "$1" "$2"
二、模板
Zabbix监控QQ交流群:9888359有提供
上一篇: C# 中 Redis 的简单使用