环境
java -version:
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
uname -a:
Linux 3.16.0-70-generic #90~14.04.1-Ubuntu SMP Wed Apr 6 22:56:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
准备工作
第一次接触的同学可以先看一下这个入门指南
第一步:client启动 jvisualvm
jvisualvm
第二步:server主机上启动 jstatd
看名字都知道和 jstat (d 就是 Daemon 的意思) 命令有关。 jstatd 是一个RMI server应用,目的是在本机上建立对JVM 的监控,同时提供接口给远程的主机监控本地JVM的信息。
第三步:为client jvisualvm 添加远程主机
!关于安全问题
这是比较重要的部分,因为 jstatd 默认能监控和启动jstatd 相同用户的JVM(同一用户). 另外在linux中root 启动的 jstatd 可以查看所有jvm.
对于远程连接至 jstatd 服务的client, jstatd 服务端是没有提供任何认证的。example:
所以在生产环境肯定是需要提供可靠的认证过程:
The jstatd server installs an instance of RMISecurityPolicy if no other security manager has been installed and therefore requires a security policy file to be specified. The policy file must conform to the default policy implementation's Policy File Syntax.
The following policy file will allow the jstatd server to run without any security exceptions. This policy is less liberal then granting all permissions to all codebases, but is more liberal than a policy that grants the minimal permissions to run the jstatd server.
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
To use this policy, copy the text into a file called jstatd.all.policy and run the jstatd server as follows:
jstatd -J-Djava.security.policy=jstatd.all.policy
更多的信息可能需要大家从ORACLE官网获取,查看下面的参考信息,由于官方建议直接在目标机器上使用_jstat_查看堆,垃圾回收等信息,而且本人也更倾向于这种方式。所以不再深入研究 policy 的问题。对_jstat_感兴趣的同学可以查看下面的参考。
参考: