Jstatd命令(Java Statistics Monitoring Daemon)

JDK内置工具使用

一、javah命令(C Header and Stub File Generator)

二、jps命令(Java Virtual Machine Process Status Tool)

三、jstack命令(Java Stack Trace)

四、jstat命令(Java Virtual Machine Statistics Monitoring Tool)

五、jmap命令(Java Memory Map)

六、jinfo命令(Java Configuration Info)

七、jconsole命令(Java Monitoring and Management Console)

八、jvisualvm命令(Java Virtual Machine Monitoring, Troubleshooting, and Profiling Tool)

九、jhat命令(Java Heap Analyse Tool)

十、Jdb命令(The Java Debugger)

十一、Jstatd命令(Java Statistics Monitoring Daemon)


1、介绍

    jstatd是一个基于RMIRemove Method Invocation)的服务程序,它用于监控基于HotSpotJVM中资源的创建及销毁,并且提供了一个远程接口允许远程的监控工具连接到本地的JVM执行命令。

    jstatd是基于RMI的,所以在运行jstatd的服务器上必须存在RMI注册中心,如果没有通过选项"-p port"指定要连接的端口,jstatd会尝试连接RMI注册中心的默认端口。后面会谈到如何连接到一个默认的RMI内部注册中心,如何禁止默认的RMI内部注册中心的创建,以及如何启动一个外部注册中心。

 

2、参数选项

    jstatd命令支持如下的选项:

    -nr 如果RMI注册中心没有找到,不会创建一个内部的RMI注册中心。

    -p port RMI注册中心的端口号,默认为1099

    -n rminame 默认为JStatRemoteHost;如果同一台主机上同时运行了多个jstatd服务,rminame可以用于唯一确定一个jstatd服务;这里需要注意一下,如果开启了这个选项,那么监控客户端远程连接时,必须同时指定hostidvmid,才可以唯一确定要连接的服务,这个可以参看jps章节中列出远程服务器上Java进程的示例。

    -J 用于传递jvm选项到由javac调用的java加载器中,例如,“-J-Xms48m”将把启动内存设置为48M,使用-J选项可以非常方便的向基于Java的开发的底层虚拟机应用程序传递参数。

 

3、安全性

    jstatd服务只能监视具有适当的本地访问权限的JVM,因此jstatd进程与被监控的JVM必须运行在相同的用户权限中。但是有一些特殊的用户权限,如基于UNIXTM)为系统的root用户,它有权限访问系统中所有JVM的资源,如果jstatd进程运行在这种权限中,那么它可以监视系统中的所有JVM,但是这也带来了额外的安全问题。

    jstatd服务不会对客户端进行任何的验证,因此运行了jstatd服务的JVMs,网络上的任何用户的都具有访问权限,这种暴露不是我们所希望的,因此在启动jstatd之前本地安全策略必须要加以考虑,特别是在生产环境中或者是在不安全的网络环境中。

    如果没有其他安全管理器被安装,jstatd服务将会安装一个RMISecurityPolicy的实例,因此需要在一个安全策略文件中指定,该策略文件必须符合的默认策略实施的策略文件语法。

    下面的这个示例策略将允许jstatd服务具有JVM全部的访问权限:    

grant codebase "file:${java.home}/../lib/tools.jar" {
   permission java.security.AllPermission;
};
    注:此处策略中的 java.home ,和 JAVA_HOME 不是一个概念,童鞋们不要搞错了,此处的 java.home 指的是 JRE 的路径,这个是 Java 的系统属性,不需要手工指定,通常是这个 jdk 下面的 jre 路径 , 即可以认为 ${java.home} ${JAVA_HOME}/jre 是等价,如果想查看这个变量的值,可以任意找一个运行着的 Java 应用,找到它的 PID ,然后通过如下 jinfo 命令查看就可以查看到 java.home 的值:
jinfo ${PID}|grep java.home

    也可以在Java代码中通过如下方式获取到:

System.out.println(System.getProperty("java.home"))

    将上面的策略内容拷贝一个文件中,文件名可以随意取,为了形象我们将文件名命名为jstatd.all.policy,文件存放的路径也可以随意,只有你当前登陆的用户具有访问权限就可以,然后执行以下命令就可以启动jstatd服务:

jstatd -J-Djava.security.policy=jstatd.all.policy

    如果是在具有安全限制的环境中,jstatd的策略安全一定要设置得当,并且只允许受信任的服务器或者网络访问,以免遭受网络攻击,如果存在安全隐患,最好不要启动jstatd服务,就在本地使用jstatjps等工具对JVM进行监控了。


4、示例

4.1、使用内部RMI注册中心

    下面这个示例演示了通过内部RMI注册中心启动jstatd,这个示例假设没有其它的服务绑定到默认的RMI注册中心端口(默认端口是1099)。

jstatd -J-Djava.security.policy=jstatd.all.policy

    注:如果基于默认端口1099RMI注册中心原来没有被启动过,那么上面运行的命令首先会启动端口为1099RMI注册中心,然后再启动jstatd服务,此时即使jstatd停止了,RMI注册中心也不会停止;如果是再次执行上面的命令,就不会再次启动RMI注册中心,jstatd会直接注册到注册中心。


4.2、使用外部的RMI注册中心

    这个示例演示了使用一个外部的RMI注册中心来启动jstatd,如果默认的内部注册中心已经被启动了,下面的这个示例就会抛出“端口1099已经被占用”的异常,因为它尝试在1099端口启动外部RMI注册中心:

rmiregistry&jstatd -J-Djava.security.policy=all.policy

    这个示例演示了使用一个外部的RMI注册中心来启动jstatd,此注册中心的端口为2020

rmiregistry 2020&jstatd -J-Djava.security.policy=all.policy -p 2020
    这个示例演示了使用一个外部的 RMI 注册中心来启动 jstatd ,此注册中心的端口为 2020 ,并且绑定到 RMI 注册中心的名为 AlternateJstatdServerName
rmiregistry 2020&jstatd -J-Djava.security.policy=all.policy -p 2020 -n AlternateJstatdServerName

    注:这个端口为2020RMI注册中心,我们会在jps章节中使用到。


4.3、禁止内部RMI注册中心的创建

    这个示例演示了jstatd在启动的时候,如果没有找到默认的RMI注册中心,也不会创建默认的注册中心。这个示例中如果没有RMI注册中心在运行,此示例就会报错,如果存在就会正常运行:   

jstatd -J-Djava.security.policy=all.policy -nr


4.4、开启RMI日记记录

    这个示例演示的是jstatd运行在开启了日志记录功能的RMI注册中,这个对于问题查找或监控服务状态非常有用:

jstatd -J-Djava.security.policy=all.policy -J-Djava.rmi.server.logCalls=true









  • 3
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Overview Module Package Class Use Tree Deprecated Index Help Java SE 9 & JDK 9 Prev Next Frames No Frames All Classes SEARCH: Java® Platform, Standard Edition & Java Development Kit Version 9 API Specification This document is divided into three sections: Java SE The Java Platform, Standard Edition (Java SE) APIs define the core Java platform for general-purpose computing. These APIs are in modules whose names start with java. JDK The Java Development Kit (JDK) APIs are specific to the JDK and will not necessarily be available in all implementations of the Java SE Platform. These APIs are in modules whose names start with jdk. JavaFX The JavaFX APIs define a set of user-interface controls, graphics, media, and web packages for developing rich client applications. These APIs are in modules whose names start with javafx. Java SE Module Description java.activation Defines the JavaBeans Activation Framework (JAF) API. java.base Defines the foundational APIs of the Java SE Platform. java.compiler Defines the Language Model, Annotation Processing, and Java Compiler APIs. java.corba Defines the Java binding of the OMG CORBA APIs, and the RMI-IIOP API. java.datatransfer Defines the API for transferring data between and within applications. java.desktop Defines the AWT and Swing user interface toolkits, plus APIs for accessibility, audio, imaging, printing, and JavaBeans. java.instrument Defines services that allow agents to instrument programs running on the JVM. java.logging Defines the Java Logging API. java.management Defines the Java Management Extensions (JMX) API. java.management.rmi Defines the RMI connector for the Java Management Extensions (JMX) Remote API. java.naming Defines the Java Naming and Directory Interface (JNDI) API. java.prefs Defines the Preferences API. java.rmi Defines the Remote Method Invocation (RMI) API. java.scripting Defines the Scripting API. java.se Defines the core Java SE API. java.se.ee Defines the full API of the Java SE Platform. java.security.jgss Defines the Java binding of the IETF Generic Security Services API (GSS-API). java.security.sasl Defines Java support for the IETF Simple Authentication and Security Layer (SASL). java.sql Defines the JDBC API. java.sql.rowset Defines the JDBC RowSet API. java.transaction Defines a subset of the Java Transaction API (JTA) to support CORBA interoperation. java.xml Defines the Java API for XML Processing (JAXP), the Streaming API for XML (StAX), the Simple API for XML (SAX), and the W3C Document Object Model (DOM) API. java.xml.bind Defines the Java Architecture for XML Binding (JAXB) API. java.xml.crypto Defines the API for XML cryptography. java.xml.ws Defines the Java API for XML-Based Web Services (JAX-WS), and the Web Services Metadata API. java.xml.ws.annotation Defines a subset of the Common Annotations API to support programs running on the Java SE Platform. JDK Module Description jdk.accessibility Defines JDK utility classes used by implementors of Assistive Technologies. jdk.attach Defines the attach API. jdk.charsets Provides charsets that are not in java.base (mostly double byte and IBM charsets). jdk.compiler Defines the implementation of the system Java compiler and its command line equivalent, javac, as well as javah. jdk.crypto.cryptoki Provides the implementation of the SunPKCS11 security provider. jdk.crypto.ec Provides the implementation of the SunEC security provider. jdk.dynalink Defines the API for dynamic linking of high-level operations on objects. jdk.editpad Provides the implementation of the edit pad service used by jdk.jshell. jdk.hotspot.agent Defines the implementation of the HotSpot Serviceability Agent. jdk.httpserver Defines the JDK-specific HTTP server API. jdk.incubator.httpclient Defines the high-level HTTP and WebSocket API. jdk.jartool Defines tools for manipulating Java Archive (JAR) files, including the jar and jarsigner tools. jdk.javadoc Defines the implementation of the system documentation tool and its command line equivalent, javadoc. jdk.jcmd Defines tools for diagnostics and troubleshooting a JVM such as the jcmd, jps, jstat tools. jdk.jconsole Defines the JMX graphical tool, jconsole, for monitoring and managing a running application. jdk.jdeps Defines tools for analysing dependencies in Java libraries and programs, including the jdeps, javap, and jdeprscan tools. jdk.jdi Defines the Java Debug Interface. jdk.jdwp.agent Provides the implementation of the Java Debug Wire Protocol (JDWP) agent. jdk.jfr Defines the API for Java Flight Recorder. jdk.jlink Defines the jlink tool for creating run-time images, the jmod tool for creating and manipulating JMOD files, and the jimage tool for inspecting the JDK implementation-specific container file for classes and resources. jdk.jshell This module provides support for Java Programming Language 'snippet' evaluating tools, such as Read-Eval-Print Loops (REPLs), including the jshell tool. jdk.jsobject Defines the API for the JavaScript Object. jdk.jstatd Defines the jstatd tool for starting a daemon for the jstat tool to monitor JVM statistics remotely. jdk.localedata Provides the locale data for locales other than US locale. jdk.management Defines JDK-specific management interfaces for the JVM. jdk.management.agent Defines the JMX management agent. jdk.management.cmm Defines the Management Interface for Cooperative Memory Management. jdk.management.jfr Defines the Management Interface for Java Flight Recorder. jdk.management.resource Defines the Resource Management API. jdk.naming.dns Provides the implementation of the DNS Java Naming provider. jdk.naming.rmi Provides the implementation of the RMI Java Naming provider. jdk.net Defines the JDK-specific Networking API. jdk.pack Defines tools for transforming a JAR file into a compressed pack200 file and transforming a packed file into a JAR file, including the pack200 and unpack200 tools. jdk.packager.services Defines the services used by the Java packager tool. jdk.policytool Defines the GUI tool for managing policy files called policytool. jdk.rmic Defines the rmic compiler for generating stubs and skeletons using the Java Remote Method Protocol (JRMP) and stubs and tie class files (IIOP protocol) for remote objects. jdk.scripting.nashorn Provides the implementation of Nashorn script engine and the runtime environment for programs written in ECMAScript 5.1. jdk.sctp Defines the JDK-specific API for SCTP. jdk.security.auth Provides implementations of the javax.security.auth.* interfaces and various authentication modules. jdk.security.jgss Defines Java extensions to the GSS-API and an implementation of the SASL GSSAPI mechanism. jdk.snmp Defines the SNMP management agent. jdk.xml.dom Defines the subset of the W3C Document Object Model (DOM) API that is not part of the Java SE API. jdk.zipfs Provides the implementation of the zip file system provider. JavaFX Module Description javafx.base Defines the base APIs for the JavaFX UI toolkit, including APIs for bindings, properties, collections, and events. javafx.controls Defines the UI controls, charts, and skins that are available for the JavaFX UI toolkit. javafx.fxml Defines the FXML APIs for the JavaFX UI toolkit. javafx.graphics Defines the core scenegraph APIs for the JavaFX UI toolkit (such as layout containers, application lifecycle, shapes, transformations, canvas, input, painting, image handling, and effects), as well as APIs for animation, css, concurrency, geometry, printing, and windowing. javafx.media Defines APIs for playback of media and audio content, as part of the JavaFX UI toolkit, including MediaView and MediaPlayer. javafx.swing Defines APIs for the JavaFX / Swing interop support included with the JavaFX UI toolkit, including SwingNode (for embedding Swing inside a JavaFX application) and JFXPanel (for embedding JavaFX inside a Swing application). javafx.web Defines APIs for the WebView functionality contained within the the JavaFX UI toolkit. Other Modules Module Description java.jnlp Defines the API for Java Network Launch Protocol (JNLP). java.smartcardio Defines the Java Smart Card I/O API. Skip navigation links Overview Module Package Class Use Tree Deprecated Index Help Java SE 9 & JDK 9 Prev Next Frames No Frames All Classes

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值