当前位置: 首页 > java, OpenSource > 正文

使用Jconsole对java的内存使用情况(JVM)进行监控

 

JDK1.5提供JMX remote的管理工具Jconsole,可以监控Java运行程序的内存使用情况、活动线程数量、类装载的数量、MBeans的状态、虚拟机的各种信息等,还可以执行MBean公开的方法或强制进行垃圾回收。因为Apusic应用服务器实现标准的JMX接口,因此也可以使用Jconsole进行监控。

下面是在windows端对Linux的java应用(Resin)的JVM进行监控。
windows: 安装 jdk1.6.0_06  http://java.sun.com/javase/downloads/index.jsp
Linux:Resin2.1.x + jdk1.6

启动resin ,增加jvm监控的指令:
可以在java启动参数添加,
如: httpd.sh  或者 wrapper.pl 里面
vi http.sh
args=”***” 把 需要启动jvm选项加入。

#指定远程服务器的端口
-Dcom.sun.management.jmxremote.port=12345
#指定远程服务器的用户认证
-Dcom.sun.management.jmxremote.password.file=$JRE_HOME/lib/management/password.properties
-Dcom.sun.management.jmxremote.access.file=$JRE_HOME/lib/management/access.properties

使用密码:
#JRE_HOME/lib/management/jmxremote.password.template
cp jmxremote.password.template password.properties
chmod 600 password.properties
#默认用户名 密码为:
monitorRole QED
controlRole R&D
#默认权限
#cp jmxremote.access access.properties 
#设置权限
monitorRole   readonly
controlRole   readwrite

#也可以使用禁止用户认证
com.sun.management.jmxremote.authenticate=false

也可以使用ssl连接

这里先不用
com.sun.management.jmxremote.ssl=false

说明: 如果没有启动com.sun.management.jmxremote 的配置 , 远程连接会提示:
error during jrmp connection establishment ; nested exception is

如果无法连接有可能是linux服务器的hostname存在问题

#修改hostname
/etc/hosts  把127.0.0.1修改为外网卡IP,如192.168.1.100
还有
/etc/sysconfig/network

#启动resin
$RESIN_HOME/bin/http.sh start
#查看是否已经启动
#ps -x
8681 pts/0    S      0:00 perl bin/wrapper.pl -chdir -name httpd -class com.caucho.server.http.HttpServer -J-server -verbose -Dcom.
8683 pts/0    Sl     0:04 /home/2hei.net/jdk1.6.0_06/bin/java -server -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremo
#查看端口
#netstat -an
tcp        0      0 127.0.0.1:35844             127.0.0.1:35848             ESTABLISHED
tcp        0      0 :::8080                     :::*                        LISTEN
tcp        0      0 :::12345                    :::*                        LISTEN

-Dcom.sun.management.jmxremote.authenticate=false
#是否使用ssl
-Dcom.sun.management.jmxremote.ssl=false”

windows下
jconsole命令在 $JAVA_HOME/bin 下

cmd:\>jconsole
#启动

jvm_6.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

连接远程
192.168.1.100:12345
controlRole R&D

jvm_1.png

 

 

 

 

 

 

 

 

 

 

 

jvm_2.png

 

 

 

 

 

 

 

 

 

 

 

jvm_4.png

 

 

 

 

 

 

 

 

 

 

 

 

参考:
http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html

http://java.sun.com/javase/6/docs/technotes/tools/solaris/keytool.html

本文固定链接: https://www.2hei.net/2008/07/10/use_jconsole_moni_java_jvm/ | 2hei.net

该日志由 u2 于2008年07月10日发表在 java, OpenSource 分类下,
原创文章转载请注明: 使用Jconsole对java的内存使用情况(JVM)进行监控 | 2hei.net
关键字: , ,

报歉!评论已关闭.