JVM监控

jconsole

说明:

首先JConsole这个是JDK里面自带的工具  在JAVA_HOME/bin目录下,今天主要测试远程监控JVM 

第一步:设置好需要远程机器的Tomcat 

修改Tomcat下的配置文件:/opt/tomcat7/bin/catalina.sh

在 文件中找到----- Execute The Requested Command --这一行,在这一行上面设置如下代码:

JAVA_OPTS="$JAVA_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=47.107.183.88"

JAVA_OPTS="$JAVA_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=47.107.183.88"

# ----- Execute The Requested Command -----------------------------------------

//注意中间没有换行,这是一条语句;hostname的IP为要监控的服务器的IP地址

第二步:配置完成后重启Tomcat

/usr/local/apache-tomcat-7.0.41/bin/shutdown.sh   //关闭Tomcat

/usr/local/apache-tomcat-7.0.41/bin/startup.sh  //重启Tomcat

netstat -an| grep 12345  //查看配置的端口号是否启动

第三步:在Windows系统上打开Jconsole

C:Program FilesJavajdk1.8.0_92inJconsole.exe   //根据自己实际路径查找,打开后如下图:

选择远程进程,这里有两种连接方式,这里选择第一种<hostname>:<port>的方式,如下图:

配置完成后点击连接,会有一条提示,这里我们选择以不安全的方式连接即可,最后如下图:

jprofile

前提条件:

windows下安装好jprofile

linux下解压好profile

# tar -zxvf jprofiler_linux_7_2_3.tar.gz

接下来,打开window端的jprofile:

选择:linux,next

随便选,next:

 直接 next:

 填写需要监控的 ip ,next :

输入 linux 内 jprofile 的目录 ,next:

[root@xiaowenshu jprofiler7]# pwd
/opt/jprofiler7

默认端口:8849 ,确保linux的改端口没有被占用,直接 next :

远程 jvm 启动添加此参数来监听 windows 客户端:

-agentpath:/opt/jprofiler7/bin/linux-arm/libjprofilerti.so=port=8849

 

配置linux:

修改Tomcat下的配置文件:/opt/tomcat7/bin/catalina.sh

在 文件中找到----- Execute The Requested Command --这一行,在这一行上面设置如下代码:

-agentpath:/opt/jprofiler7/bin/linux-arm/libjprofilerti.so=port=8849

改好了,重启 tomcat

 如果要两个都用的话:配置如下:

JAVA_OPTS="$JAVA_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=47.107.183.88"


CATALINA_OPTS="-agentpath:/opt/jprofiler7/bin/linux-x64/libjprofilerti.so=port=8849,nowait $CATALINA_OPTS" export CATALINA_OPTS

如果单独配置一个:想用哪个,注释掉另一个


JAVA_OPTS="$JAVA_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=47.107.183.88"

JAVA_OPTS="
-agentpath:/opt/jprofiler7/bin/linux-x64/libjprofilerti.so=port=8849,nowait $CATALINA_OPTS"

next ,finsh 完成 session创建

ok

这样,初步就ok

原文地址:https://www.cnblogs.com/xiaowenshu/p/10217045.html