zabbix提供java gateway来监控java程序,在./configure的时候加入--enable-java
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql=/usr/local/mysql/bin/mysql_config --with-net-snmp --with-libcurl --with-libxml2 --enable-java
make
make install
2: 验证有没有安装java gateway
ll -h /usr/local/zabbix/sbin/zabbix_java/
3: 启动java gateway
/usr/local/zabbix/sbin/zabbix_java/startup.sh
netstat -tulnp #端口10052
4: zabbix server配置新增(/usr/local/zabbix/etc/zabbix_server.conf),监控流程是zabbix server --> java gateway --> 监控tomcat服务器
JavaGateway=127.0.0.1 ##否则jmx会显示JavaGateway not host
JavaGatewayPort=10052
StartJavaPollers=5
需要重启zabbix server。
5: tomcat服务器加入如下配置(vim /usr/local/tomcat/bin/catalina.sh),重启tomcat
CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=12345 -Djava.rmi.server.hostname=144.202.119.71"
6: cmdline-jmxclient-0.10.3.jar测试能否获取jmx数据(cd /usr/local/tomcat/)
java -jar cmdline-jmxclient-0.10.3.jar - 192.168.1.106:12345
java -jar cmdline-jmxclient-0.10.3.jar - 144.202.119.71:12345 java.lang:type=Memory
java -jar cmdline-jmxclient-0.10.3.jar - 144.202.119.71:12345 java.lang:type=Memory HeapMemoryUsage
java -jar cmdline-jmxclient-0.10.3.jar - 144.202.119.71:12345 java.lang:type=OperatingSystem ProcessCpuLoad