Tomcat_03_监控

2020-08-19 10:54:31 浏览数 (1)

9、监控tomcat集群状态
1、方法一:开发java监控页面
代码语言:javascript复制
[root@web03 tomcat8_1]# cat /application/tomcat/webapps/memtest/meminfo.jsp 
<%
Runtime rtm = Runtime.getRuntime();
long mm = rtm.maxMemory()/1024/1024;
long tm = rtm.totalMemory()/1024/1024;
long fm = rtm.freeMemory()/1024/1024;

out.println("JVM memory detail info :<br>");
out.println("Max memory:" mm "MB" "<br>");
out.println("Total memory:" tm "MB" "<br>");
out.println("Free memory:" fm "MB" "<br>");
out.println("Available memory can be used is :" (mm fm-tm) "MB" "<br>");
%>
2、方法二:使用jps命令进行监控
代码语言:javascript复制
[root@web03 ~]# jps -lvm

31906 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/application/tomcat8_1/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat8_1/endorsed -Dcatalina.base=/application/tomcat8_1 -Dcatalina.home=/application/tomcat8_1 -Djava.io.tmpdir=/application/tomcat8_1/temp

31812 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat/endorsed -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp

31932 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/application/tomcat8_2/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/application/tomcat8_2/endorsed -Dcatalina.base=/application/tomcat8_2 -Dcatalina.home=/application/tomcat8_2 -Djava.io.tmpdir=/application/tomcat8_2/temp

32079 sun.tools.jps.Jps -lvm -Denv.class.path=.:/application/jdk/lib:/application/jdk/jre/lib:/application/jdk/lib/tools.jar -Dapplication.home=/application/jdk1.8.0_60 -Xms8m
3、Tomcat远程监控功能

修改配置文件,开启远程监控

代码语言:javascript复制
vim /application/tomcat8_1/bin/catalina.sh  97

CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=12345  
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jmxremote.ssl=false 
-Djava.rmi.server.hostname=10.0.0.17"

​ 重启服务,检查12345端口是否开启

代码语言:javascript复制
/application/tomcat8_1/bin/shutdown.sh 
/application/tomcat8_1/bin/startup.sh 
netstat -tunlp|grep 12345

​ 检查端口

代码语言:javascript复制
[root@web03 ~]# netstat -tunlp|grep 12345
tcp6       0      0 :::12345           :::*          LISTEN      33158/java

在windows**上监控tomcat**

注意:windwos**需要安装jdk**环境!

查考:http://www.oracle.com/technetwork/java/javase/downloads/index.html

4、zabbix监控tomcat程序

zabbix搭建详情参考:https://www.toutiao.com/i6808897883299906059/

若是有问题,请移步官网 : https://www.zabbix.com/documentation/4.0/zh/manual/installation

服务端安装配置java**监控服务**

代码语言:javascript复制
[root@m01 ~]# yum install zabbix-java-gateway -y

查看配置文件

代码语言:javascript复制
配置文件路径:/etc/zabbix/zabbix_java_gateway.conf
sed -i -e '220a JavaGateway=127.0.0.1' -e '236a StartJavaPollers=5'  /etc/zabbix/zabbix_server.conf

启动zabbix-java-gateway服务,与zabbix服务

代码语言:javascript复制
systemctl start zabbix-java-gateway.service
systemctl restart zabbix-server.service

检查java端口是否开启

代码语言:javascript复制
[root@m01 ~]# netstat -lntup |grep java
tcp6       0      0 :::10052   :::*    LISTEN      72971/java

​ 检查java进程是否存在

代码语言:javascript复制
[root@m01 ~]# ps -ef |grep [j]ava
zabbix    72971      1  0 11:29 ?        00:00:00 java -server -Dlogback.configurationFile=/etc/zabbix/zabbix_java_gateway_logback.xml -classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-0.9.27.jar:lib/logback-core-0.9.27.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-3.0.13.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java.pid -Dzabbix.timeout=3 -Dsun.rmi.transport.tcp.responseTimeout=3000 com.zabbix.gateway.JavaGateway
zabbix    73255  73226  0 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller #1 [got 0 values in 0.000002 sec, idle 5 sec]
zabbix    73256  73226  0 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller #2 [got 0 values in 0.000002 sec, idle 5 sec]
zabbix    73257  73226  0 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller #3 [got 0 values in 0.000002 sec, idle 5 sec]
zabbix    73258  73226  0 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller #4 [got 0 values in 0.000002 sec, idle 5 sec]
zabbix    73259  73226  0 11:35 ?        00:00:00 /usr/sbin/zabbix_server: java poller #5 [got 0 values in 0.000004 sec, idle 5 sec]

web**界面添加**

​ 添加主机

​ 主机管理模板,注意是JMX模板

监控完成

5、排除tomcat故障步骤

a. 查看catalina.out

b. 使用sh show-busy-java-threads.sh脚本进行检测

脚本下载地址

https://files.cnblogs.com/files/clsn/show-busy-java-threads.sh

0 人点赞