Zabbix 3.2 通过JMX监控Tomcat性能状态

一. 服务端(zabbix_server)配置

1.由于zabbix_java_gateway插件需要依赖于jdk,故首先安装jdk

#tar -zxf jdk-7u80-linux-x64.tar.gz
#mv /root/jdk-7u80-linux /usr/local/java
#vi /etc/profile 添加如下内容:
     export JAVA_HOME=/usr/local/java
      export PATH=$JAVA_HOME/bin:$PATH
      export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

 

2.下载并安装对应zabbix版本的zabbix-java-gateway插件

#rpm -Uvh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-java-gateway-3.2.4-1.el7.x86_64.rpm

 

3. 由于此次zabbix_server与java_gateway在同一台机器上,故IP设置均为本地,编辑/etc/zabbix/zabbix_java_gateway.conf

# This is a configuration file for Zabbix Java Gateway.
# It is sourced by startup.sh and shutdown.sh scripts.

### Option: zabbix.listenIP
#       IP address to listen on. 
#
# Mandatory: no
# Default:
LISTEN_IP="127.0.0.1"   #设置IP地址

### Option: zabbix.listenPort
#  Port to listen on. 
#
# Mandatory: no
# Range: 1024-32767
# Default:
LISTEN_PORT=10052   #设置监听端口

### Option: zabbix.pidFile
#       Name of PID file.
#       If omitted, Zabbix Java Gateway is started as a console application.
#
# Mandatory: no
# Default:
# PID_FILE=

PID_FILE="/var/run/zabbix/zabbix_java.pid"

### Option: zabbix.startPollers
#       Number of worker threads to start.
#
# Mandatory: no
# Range: 1-1000
# Default:
START_POLLERS=5    #设置工作线程

### Option: zabbix.timeout
#       How long to wait for network operations.
#
# Mandatory: no
# Range: 1-30
# Default:
# TIMEOUT=3

TIMEOUT=3

 

4.查看zabbix-java-gateway安装后的启动脚本/配置文件位置等

# rpm -ql zabbix-java-gateway-3.2.4-1.el7.x86_64

/etc/zabbix/zabbix_java_gateway.conf
/etc/zabbix/zabbix_java_gateway_logback.xml
/usr/lib/systemd/system/zabbix-java-gateway.service
/usr/lib/tmpfiles.d/zabbix-java-gateway.conf
/usr/sbin/zabbix_java_gateway                   #启动脚本
/usr/share/doc/zabbix-java-gateway-3.2.4
/usr/share/doc/zabbix-java-gateway-3.2.4/AUTHORS
/usr/share/doc/zabbix-java-gateway-3.2.4/COPYING
/usr/share/doc/zabbix-java-gateway-3.2.4/ChangeLog
/usr/share/doc/zabbix-java-gateway-3.2.4/NEWS
/usr/share/doc/zabbix-java-gateway-3.2.4/README
/usr/share/zabbix-java-gateway
/usr/share/zabbix-java-gateway/bin
/usr/share/zabbix-java-gateway/bin/zabbix-java-gateway-3.2.4.jar
/usr/share/zabbix-java-gateway/lib
/usr/share/zabbix-java-gateway/lib/android-json-4.3_r3.1.jar
/usr/share/zabbix-java-gateway/lib/logback-classic-0.9.27.jar
/usr/share/zabbix-java-gateway/lib/logback-core-0.9.27.jar
/usr/share/zabbix-java-gateway/lib/slf4j-api-1.6.1.jar
/var/log/zabbix
/var/run/zabbix

 

5.修改/app/zabbix/etc/zabbix_server.conf中java_gateway部分的配置项

### Option: JavaGateway
#       IP address (or hostname) of Zabbix Java gateway.
#       Only required if Java pollers are started.
#
# Mandatory: no
# Default:
JavaGateway=127.0.0.1              #配置java gateway的机器IP
### Option: JavaGatewayPort
#       Port that Zabbix Java gateway listens on.
#
# Mandatory: no
# Range: 1024-32767
# Default:
JavaGatewayPort=10052                #java gateway监听端口
### Option: StartJavaPollers
#       Number of pre-forked instances of Java pollers.
#
# Mandatory: no
# Range: 0-1000
# Default:
StartJavaPollers=5

 

6.服务端配置后可直接启动java gateway 

#sh /usr/sbin/zabbix_java_gateway
#netstat -antlp | grep :10052

 

二. 客户端(Tomcat)配置

1.编辑/usr/local/tomcat/bin/catalina.sh 添加如下内容:

CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345          #JMX端口
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Djava.rmi.server.hostname=<tomcat server IP>"     #Tomcat Server IP

 

2.重启Tomcat

#/usr/local/tomcat/bin/shutdown.sh
#/usr/local/tomcat/bin/startup.sh

 

3.测试java gataway 通过客户端工具jmxcmd,有正常输出即为配置正确

#java -jar cmdline-jmxclient-0.10.3.jar - 172.16.3.126:12345 java.lang:type=Memory NonHeapMemoryUsage

07/19/2017 10:11:16 +0800 org.archive.jmx.Client NonHeapMemoryUsage: 
committed: 185073664
init: 2555904
max: -1
used: 179324752

 

三. zabbix配置

1.由于使用系统默认自带模板Template JMX Generic/Template JMX Tomcat会出现很多item项无数据中,经分析后发现默认定义的application/item项与实际tomcat部署的版本中关于Catalina MBean Name存在差异,故需要进行修改

2.如何查看不同Tomcat版本中支持的MBean Object Name以及属性值

  ①. 可通过使用jconsole远程连接jmx接口,查看对应的MBean Name/Attribute值

 

  ②.使用前面测试返回数据用的cmdline-jmxclient-0.10.3.jar,如下图:

由于MBean Name返回数据很多可以根据需要过滤出所需的Name值

 

3.根据上述方式查询到的Object Name以及Attribute值对默认jmx模版中的Item项进行修改

jmx["Catalina:type=GlobalRequestProcessor,name=\"http-apr-80\"",bytesReceived]

zabbix中key值参数间需要',' 分隔,'\'进行转义,name值必须包含""

 

4.监控数据如图:

 

 

 Reference: http://www.fblinux.com/?p=616#堆内存

                    https://www.topjishu.com/2993.html

 

posted @ 2018-10-22 13:44  2240930501  阅读(1148)  评论(0编辑  收藏  举报