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.jarjmx_user:jmx_passwdjmx_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)
        echocurrent_jdbcurl |grep jdbcurl &>>/dev/null
        disMatch=?
        if [ disMatch -eq 0 ]; then
                #echo "found"lineNo":" linecurrent_jdbcurl &>>/dev/null
                jmx_cmdlineline jmx_attributes 2>&1 |awk '{print6}'
                break
        fi

        ((lineNo++));
done
</code>
自定义监控项值:
<code>
#C3P0
#UserParameter=c3po.[*],/c3p0.sh 12 34 $5
UserParameter=c3p0.123.[*],/etc/zabbix/c3p0.sh 123.123.123.123 1234  jmx_user passwd123456

模板:

键   c3p0.123.[numBusyConnections]

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

Captcha Code