JVM系列---【使用jconsole开启JVM监控】

发布时间 2023-05-04 19:53:41作者: 少年攻城狮

使用jconsole开启JVM监控

设置远程监控相关选项

对于远程Java进程的连接,会要麻烦些,首先需要在需监控的远程Java程序启动脚本中加入与JVM远程监控相关的选项:

1.开启JVM远程监控

-Dcom.sun.management.jmxremote=true

2.监控的IP地址

-Djava.rmi.server.hostname=192.168.91.166,远程进程所在主机的IP。

3.监控的端口

-Dcom.sun.management.jmxremote.port=50013,
#这个端口值可以任意设置,但在之后用Jconsole连接这个远程进程的时候,远程进程中的port一定要和此处的设置一致,并且一定不要和远程进程的服务端口区分开。

4.是否禁用ssl验证

-Dcom.sun.management.jmxremote.ssl
#false为禁用,true为启用。

5.是否需要用户密码验证

-Dcom.sun.management.jmxremote.authenticate
#false为不需要验证,true为需要验证。但我在Win7(32位、64位)中tomcat5.5.23下试着将该选项设置为true,tomcat无法启动,命令行窗口一闪而过。

6.是否在内存溢出时输出dump文件

-XX:+HeapDumpOnOutOfMemoryError

7.生成dump文件

jmap -dump:format=b,file=文件 进程号

8.启动参数,开启jconsole监控命令

只用把下面的ip和端口改成你自己的即可。

-Dcom.sun.management.jmxremote=true -Djava.rmi.server.hostname=`10.0.1.117` -Dcom.sun.management.jmxremote.port=`50013`  -Dcom.sun.management.jmxremote.ssl=false  -Dcom.sun.management.jmxremote.authenticate=false -XX:+HeapDumpOnOutOfMemoryError
#如果只是为了看监控,没必要加最后一个参数`-XX:+HeapDumpOnOutOfMemoryError`

9.找到Jdk的bin目录,双击jconsole.exe

直接输入ip和端口即可,不用输入用户名密码