2019.9.22 Tomcat 远程监控功能
方法一:开发java监控页面
[root@localhost ~]# mkdir /usr/local/tomcat8/webapps/memtest/
[root@localhost ~]# vim /usr/local/tomcat8/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>");
%>
方法二:使用jps命令进行监控
[root@localhost ~]# jps -lvm
80106 sun.tools.jps.Jps -lvm -Dapplication.home=/usr/local/java -Xms8m
79788 org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/usr/local/tomcat8/conf/logging.propertie
s -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dcatalina.base=/usr/local/tomcat8 -Dcatalina.home=/usr/local/tomcat8 -Djava.io.tmpdir=/usr/local/tomcat8/temp
方法三:Tomcat远程监控功能
修改配置文件,开启远程监控
[root@localhost ~]# vim /usr/local/tomcat8/bin/catalina.sh
#!/bin/sh //在# !/bin/sh下面插入这些内容
CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345 //监听端口是12345
-Dcom.sun.management.jmxremote.authenticate=false //不用去做验证
-Dcom.sun.management.jmxremote.ssl=false //ssl也是关闭的
-Djava.rmi.server.hostname=192.168.200.112" //监控ip必须是本机ip
[root@localhost ~]# /usr/local/tomcat8/bin/shutdown.sh //关闭
[root@localhost ~]# /usr/local/tomcat8/bin/startup.sh //开启
[root@localhost ~]# netstat -lnpt | grep :12345 //查看刚才设置的端口是否开启
tcp6 0 0 :::12345 :::* LISTEN 6551/java
在windows上监控tomcat
注意:windwos需要安装jdk环境!
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html
将jdk直接解压到C:\java\中,双击运行C:\java\jdk-12\bin\jconsole.exe
连接成功即可进行监控,连接的时候注意端口信息。