使用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
#启动
[img]http://www.2hei.net/mt/2008/07/10/jvm_6-thumb-440x458.png[/img]

连接远程
192.168.1.100:12345
controlRole R&D
[img]http://www.2hei.net/mt/jvm_1.png[/img]
[img]http://www.2hei.net/mt/2008/07/10/jvm_2.png[/img]
[img]http://www.2hei.net/mt/2008/07/10/jvm_4.png[/img]

参考:
http://java.sun.com/javase/6/docs/technotes/guides/management/jconsole.html
http://java.sun.com/javase/6/docs/technotes/tools/solaris/keytool.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值