jstatd 命令全稱: Virtual Machine jstat Daemon
DESCRIPTION
The jstatd tool is an RMI server application that monitors for the creation and termination of instrumented HotSpot Java virtual machines (JVMs) and pro-
vides a interface to allow remote monitoring tools to attach to JVMs running on the local host.
The jstatd server requires the presence of an RMI registry on the local host. The jstatd server will attempt to attach to the RMI registry on the default
port, or on the port indicated by the -p port option. If an RMI registry is not found, one will be created within the jstatd application bound to the
port indicated by the -p port option or to the default RMI registry port if -p port is omitted. Creation of an internal RMI registry can be inhibited by
specifying the -nr option.
NOTE - This utility is unsupported and may or may not be available in future versions of the J2SE SDK. It is not currently available on the Windows 98
and Windows ME platforms.
jstatd是一個基於RMI(Remove Method Invocation)的服務程序,它用於監控基於HotSpot的JVM中資源的創建及銷毀,並且提供了一個遠程接口允許遠程的監控工具連接到本地的JVM執行命令。
jstatd是基於RMI的,所以在運行jstatd的服務器上必須存在RMI注冊中心,如果沒有通過選項"-p port"指定要連接的端口,jstatd會嘗試連接RMI注冊中心的默認端口。后面會談到如何連接到一個默認的RMI內部注冊中心,如何禁止默認的RMI內部注冊中心的創建,以及如何啟動一個外部注冊中心
Option參數:jstatd 命令行參數可以是任何順序的,如果出現冗余或相互沖突的參數,最后一個參數優先。
-nr: 當沒找到rmi registry服務,在jstatd內部不會試圖創建rim registry.
-p:指定注冊的rmi registry服務器端口,如果沒有找到在此端口監聽的registry服務,並且沒有指定參數-nr,將會在jstatd內部以指定的端口創建registry.
-n rminame :指定綁定到rim registry中遠程服務對象的名稱,默認為JStatRemoteHost;如果同一台主機上同時運行了多個jstatd服務,rminame可以用於唯一確定一個jstatd服務;這里需要注意一下,如果開啟了這個選項,那么監控客戶端遠程連接時,必須同時指定hostid及vmid,才可以唯一確定要連接的服務
-Joption: 用於傳遞jvm選項到由javac調用的java加載器中,例如,“-J-Xms48m”將把啟動內存設置為48M,使用-J選項可以非常方便的向基於Java的開發的底層虛擬機應用程序傳遞參數。
jstatd安全:
如果沒設置其他安全管理器,jstatd將使用RMISecurityPolicy,並且需要指定安全策略文件. 安全策略文件必須符合安全策略語法,通過命令
-J-Djava.security.policy=file指定策略文件. 一下的安全策略可以訪問所有代碼庫.
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};
保存上面3行安全策略,例如保存在文件名為statd.all.policy文件中。通過下面命令啟動jstatd就可以使用安全策略.
jstatd -J-Djava.security.policy=jstatd.all.policy
示例:
(1)如果沒有rmi registry 在默認1099端口監聽,將在內部自動創建registry的rmi regitry服務》
jstatd -J-Djava.security.policy=all.policy
(2)使用外部已經存在的rmi registry服務. 先開啟rmi registry服務,再開啟jstatd.
rmiregistry 5000
jstatd -J-Djava.security.policy=all.policy -p 5000
此時用jps命令如: jps localhost:5000
(3)指定vmid
jstatd -J-Djava.security.policy=all.policy -p 2020 -n AlternateJstatdServerName