zabbix监控c3p0
zabbix监控c3p0,难点在于c3p0初始化时mbean名称是变动的,需要自定义KEY实现。
新建/etc/zabbix/c3p0.sh,内容为:
#/bin/bash
jmx_host=$1
jmx_port=$2
jmx_user=$3
jmx_passwd=$4
jmx_attributes=$5
jdbcurl="quyiyuan.mysql.rds.aliyuncs.com"
jmx_cmdline="/usr/java/jdk1.7.0_79/bin/java -jar /etc/zabbix/cmdline-jmxclient-0.10.3.jar $jmx_user:$jmx_passwd $jmx_host:$jmx_port"
$jmx_cmdline |grep "com.mchange.v2.c3p0" 2>&1 >/tmp/.MbeanList
lineNo=1
cat /tmp/.MbeanList |while read line
do
#echo $lineNo":" $line
current_jdbcurl=$($jmx_cmdline $line jdbcUrl 2>&1)
echo $current_jdbcurl |grep $jdbcurl &>>/dev/null
disMatch=$?
if [ $disMatch -eq 0 ]; then
#echo "found" $lineNo":" $line $current_jdbcurl &>>/dev/null
$jmx_cmdline $line $jmx_attributes 2>&1 |awk '{print $6}'
break
fi
((lineNo++));
done
</code>
自定义监控项值:
<code>
#C3P0
#UserParameter=c3po.[*],/c3p0.sh $1 $2 $3 $4 $5
UserParameter=c3p0.123.[*],/etc/zabbix/c3p0.sh 123.123.123.123 1234 jmx_user passwd123456
模板:
键 c3p0.123.[numBusyConnections]