Zabbix 的JMX监控架构

zaibbix Server-->Java gateway-->JMX counter

服务器端:

安装JMX:可以安装在任何一台服务器上,本次安装在server端;
首先安装zabbix-3.4-1.el7的yum源:
# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.centos.noarch.rpm
# rpm -q zabbix-release
zabbix-release-3.4-1.el7.centos.noarch
# rpm -ql zabbix-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
/etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
/etc/yum.repos.d/zabbix.repo
/usr/share/doc/zabbix-release-3.4
/usr/share/doc/zabbix-release-3.4/GPL

# yum -y install zabbix-java-gateway
# systemctl status zabbix-java-gateway.service

修改Java-gateway配置文件   
# vim /etc/zabbix/zabbix_java_gateway.conf
    # 监听地址
    LISTEN_IP="0.0.0.0"
    # 监听端口
    LISTEN_PORT=10052
    # PID_FILE文件
    PID_FILE="/var/run/zabbix/zabbix_java.pid"
    # 开启的工作线程数
    START_POLLERS=50
    # 超时时间
    TIMEOUT=3

启动zabbix-java-gateway:
    # systemctl start zabbix-java-gateway.service
    # ss -tnl | grep 10052
        LISTEN     0      50           *:10052                    *:*  
    # systemctl enable  zabbix-java-gateway.service

修改zabbix_server的配置文件并重启
    # vim /etc/zabbix/zabbix_server.conf         #修改下面几个参数:
        # JavaGateway的所在服务器IP地址
        JavaGateway=192.168.20.59
        # JavaGateway的服务端口
        JavaGatewayPort=10052
        # 从javaGateway采集数据的进程数
        StartJavaPollers=5

配置文件修改后,重启zabbix-server:
    # systemctl restart zabbix-server.service

注意:Java-gateway配置文件的START_POLLERS参数 >= zabbix_server配置文件的StartJavaPollers参数

客户端:

添加tomact中JMX的参数:在文件开头配置即可。
    # vim $tomcat/bin/catalina.sh 
	CATALINA_OPTS="$CATALINA_OPTS
        -Dcom.sun.management.jmxremote
        -Dcom.sun.management.jmxremote.port=12345    # JMX端口,默认12345
        -Dcom.sun.management.jmxremote.authenticate=false
        -Dcom.sun.management.jmxremote.ssl=false
        -Djava.rmi.server.hostname=192.168.20.60"    # 本机IP
        
重启tomcat服务:        
    # cd $tomcat/bin 
    # ./shutdown.sh
    # jps
    20713 Jps
    # ./startup.sh
    # jps
    20517 Bootstrap
    20739 Jps

 
说明:
 普通启动Java程序:
    java -jar name.jar

 带JMX启动Java程序
    java \
    -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=12345 \
    -Dcom.sun.management.jmxremote.authenticate=false \
    -Dcom.sun.management.jmxremote.ssl=false
    -jar name.jar

 认证加密的JMX启动java程序
    java \
    -Djava.rmi.server.hostname=192.168.20.60 \
    -Dcom.sun.management.jmxremote \
    -Dcom.sun.management.jmxremote.port=12345 \
    -Dcom.sun.management.jmxremote.authenticate=true \
    -Dcom.sun.management.jmxremote.password.file=/data/tools/jdk1.8.0_66/jre/lib/management/jmxremote.password \
    -Dcom.sun.management.jmxremote.access.file=/data/tools/jdk1.8.0_66/jre/lib/management/jmxremote.access \
    -Dcom.sun.management.jmxremote.ssl=true \
    -Djavax.net.ssl.keyStore=$YOUR_KEY_STORE \
    -Djavax.net.ssl.keyStorePassword=$YOUR_KEY_STORE_PASSWORD \
    -Djavax.net.ssl.trustStore=$YOUR_TRUST_STORE \
    -Djavax.net.ssl.trustStorePassword=$YOUR_TRUST_STORE_PASSWORD \
    -Dcom.sun.management.jmxremote.ssl.need.client.auth=true \
    -jar name.jar

GUI端:

导入模板到zabbix,并关联到主机,添加监控
    新建主机,配置JMX接口,默认端口号12345;

zabbix-java-gateway监控tomcat_配置


导入JMX模板
    选择配置:主机-模板-选择-模板-:
    Template App Apache Tomcat JMX
    Template App Generic java JMX

zabbix-java-gateway监控tomcat_配置_02



查看JMX是否生效,可重启tomcat进程和zabbix-java-gateway服务
    Configuration --> Hosts --> 查看制定服务器所对应的JMX是否变为绿色;

zabbix-java-gateway监控tomcat_配置_03

查看图形
    Monitoring --> Graphs --> 选择对应的Host,Graph选择Threads,如图:[object Object]

zabbix-java-gateway监控tomcat_配置_04