Monitoring And Management Guide - Oracle

Transcription

Java Platform, Standard EditionMonitoring and Management GuideRelease 9E75744-02September 2017

Java Platform, Standard Edition Monitoring and Management Guide, Release 9E75744-02Copyright 2006, 2017, Oracle and/or its affiliates. All rights reserved.This software and related documentation are provided under a license agreement containing restrictions onuse and disclosure and are protected by intellectual property laws. Except as expressly permitted in yourlicense agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify,license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means.Reverse engineering, disassembly, or decompilation of this software, unless required by law forinteroperability, is prohibited.The information contained herein is subject to change without notice and is not warranted to be error-free. Ifyou find any errors, please report them to us in writing.If this is software or related documentation that is delivered to the U.S. Government or anyone licensing it onbehalf of the U.S. Government, then the following notice is applicable:U.S. GOVERNMENT END USERS: Oracle programs, including any operating system, integrated software,any programs installed on the hardware, and/or documentation, delivered to U.S. Government end users are"commercial computer software" pursuant to the applicable Federal Acquisition Regulation and agencyspecific supplemental regulations. As such, use, duplication, disclosure, modification, and adaptation of theprograms, including any operating system, integrated software, any programs installed on the hardware,and/or documentation, shall be subject to license terms and license restrictions applicable to the programs.No other rights are granted to the U.S. Government.This software or hardware is developed for general use in a variety of information management applications.It is not developed or intended for use in any inherently dangerous applications, including applications thatmay create a risk of personal injury. If you use this software or hardware in dangerous applications, then youshall be responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure itssafe use. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of thissoftware or hardware in dangerous applications.Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks oftheir respective owners.Intel and Intel Xeon are trademarks or registered trademarks of Intel Corporation. All SPARC trademarks areused under license and are trademarks or registered trademarks of SPARC International, Inc. AMD, Opteron,the AMD logo, and the AMD Opteron logo are trademarks or registered trademarks of Advanced MicroDevices. UNIX is a registered trademark of The Open Group.This software or hardware and documentation may provide access to or information about content, products,and services from third parties. Oracle Corporation and its affiliates are not responsible for and expresslydisclaim all warranties of any kind with respect to third-party content, products, and services unless otherwiseset forth in an applicable agreement between you and Oracle. Oracle Corporation and its affiliates will not beresponsible for any loss, costs, or damages incurred due to your access to or use of third-party content,products, or services, except as set forth in an applicable agreement between you and Oracle.

ContentsPreface1AudienceviDocumentation AccessibilityviRelated DocumentsviConventionsviOverview of Java SE Monitoring and ManagementKey Monitoring and Management Features21-1Java Virtual Machine Instrumentation1-1Monitoring and Management API1-1Monitoring and Management Tools1-2Java Management Extensions Technology1-2What Are MBeans?1-3MBean Server1-3Creating and Registering MBeans1-3Instrumenting Applications1-4Platform MXBeans1-4Platform MBean Server1-5Monitoring and Management Using JMX TechnologySetting System Properties2-1Enabling the Ready-to-Use Management2-1Local Monitoring and ManagementLocal Monitoring and Management Using JConsoleRemote Monitoring and Management2-22-22-3Using Password Authentication2-4Disabling Password Authentication2-6Using SSL2-6Enabling RMI Registry Authentication2-7Enabling SSL Client Authentication2-7Disabling SSL2-7iii

Disabling Security2-8Remote Monitoring with JConsole2-8Remote Monitoring with JConsole with SSL Enabled2-8Using Password and Access FilesPassword Files2-9Access Files2-9Remote Monitoring with JConsole with SSL Disabled2-10Ready-to-Use Monitoring and Management Properties2-10Configuration Errors2-13Setting Up Monitoring and Management Programmatically2-13Mimicking Ready-to-Use Management Using the JMX Remote API2-14Example of Mimicking Ready-to-Use Management2-15Monitoring Applications Through a Firewall2-17Using an Agent Class to Instrument an Application2-172-18Using JConsoleStarting JConsoleCommand Syntax3-13-1Setting Up Local Monitoring3-1Setting Up Remote Monitoring3-2Setting Up Secure Remote Monitoring3-2Connecting to a JMX Agent3-2Connecting JConsole to a Local Process3-3Connecting JConsole to a Remote Process3-5Connecting Using a JMX Service URL3-6Presenting the JConsole Tabs42-13Connecting to the JMX Agent ProgrammaticallyCreating an Agent Class to Instrument an Application32-93-6Viewing Overview Information3-7Saving Chart Data3-7Monitoring Memory Consumption3-8Monitoring Class Loading3-13Viewing VM Information3-13Monitoring and Managing MBeans3-15Creating Custom Tabs3-24Using the Platform MBean Server and Platform MXBeansUsing the Platform MBean Server4-1Accessing Platform MXBeans4-1iv

Accessing Platform MXBeans Using the ManagementFactory Class4-1Accessing Platform MXBeans Using an MXBean Proxy4-2Accessing Platform MXBeans Using the MBeanServerConnection Class4-2Using Oracle JDK's Platform ExtensionAccessing MXBean Attributes Directly4-3Accessing MXBean Attributes Using MBeanServerConnection4-3Monitoring Thread Contention and CPU Time4-4Managing the Operating System4-4Logging Management4-4Detecting Low Memory4-5Memory Thresholds54-5Usage Threshold4-5Collection Usage Threshold4-6Memory MXBean4-6Memory Pool MXBean4-6Polling4-7Threshold Notifications4-8SNMP Monitoring and ManagementEnabling the SNMP Agent5-1Access Control List File5-1To Enable the SNMP Agent in a Single-User Environment5-2To Enable the SNMP Agent in a Multiple-User Environment5-2SNMP Monitoring and Management PropertiesConfiguration Errors64-35-25-3Java Discovery Protocol (JDP)v

PrefacePrefaceThe Java Platform, Standard Edition 9 (Java SE 9) provide utilities that allow you tomonitor and manage the performance of a Java Virtual Machine (Java VM), and theJava applications that are running in it. The Java SE Monitoring and ManagementGuide describes those monitoring and management utilities.AudienceThis guide is intended for experienced users of the Java language, such as systemsadministrators and software developers, for whom the performance of the Javaplatform and their applications is of vital importance.Documentation AccessibilityFor information about Oracle's commitment to accessibility, visit the OracleAccessibility Program website at http://www.oracle.com/pls/topic/lookup?ctx acc&id docacc.Access to Oracle SupportOracle customers that have purchased support have access to electronic supportthrough My Oracle Support. For information, visit http://www.oracle.com/pls/topic/lookup?ctx acc&id info or visit http://www.oracle.com/pls/topic/lookup?ctx acc&id trsif you are hearing impaired.Related DocumentsSee Oracle JDK 9 Documentation for other JDK 9 guides.ConventionsThe following text conventions are used in this document:ConventionMeaningboldfaceBoldface type indicates graphical user interface elements associatedwith an action, or terms defined in text or the glossary.italicItalic type indicates book titles, emphasis, or placeholder variables forwhich you supply particular values.monospaceMonospace type indicates commands within a paragraph, URLs, codein examples, text that appears on the screen, or text that you enter.vi

1Overview of Java SE Monitoring andManagementThis topic introduces the features and utilities that provide monitoring andmanagement services to the Java Platform, Standard Edition (Java SE platform).Key Monitoring and Management FeaturesThe Java SE platform includes significant monitoring and management features.These features fall into four broad categories: Java Virtual Machine Instrumentation Monitoring and Management API Monitoring and Management Tools Java Management Extensions TechnologyJava Virtual Machine InstrumentationThe Java Virtual Machine (Java VM) is instrumented for monitoring and management,enabling built-in (or ready-to-use) management capabilities that can be accessed bothremotely and locally.See Monitoring and Management Using JMX Technology and SNMP Monitoring andManagement.The Java VM includes a platform MBean server and platform MBeans for use bymanagement applications that conform to the Java Management Extensions (JMX)specification. These platforms are implementations of the monitoring and managementAPI. The platform MXBeans and MBean servers are introduced in the PlatformMXBeans and Platform MBean Server topics.Monitoring and Management APIJava SE includes the following APIs for monitoring and management: java.lang.management: Enables monitoring and managing the Java virtualmachine and the underlying operating system. The API enables applications tomonitor themselves, and enables JMX-compliant tools to monitor and manage avirtual machine locally and remotely. This API provides access to the followingtypes of information:–Number of classes loaded and threads running–Java VM uptime, system properties, and VM input arguments–Thread state, thread contention statistics, and stack trace of live threads–Memory consumption1-1

Chapter 1Key Monitoring and Management Features–Garbage collection statistics–Low memory detection–On-demand deadlock detection–Operating system information java.util.logging.LoggingMXBean: Enables you to retrieve and set logginginformation. Attach: Allows a management agent to be dynamically loaded onto a virtualmachine. JConsole: Provides a programmatic interface to access JConsole such as addinga JConsole plug-in. JTop is an example of a JConsole plug-in that’s available atthe JDK HOME/demo/management/JTop directory.Monitoring and Management ToolsThe Java SE platform provides a graphical monitoring tool called JConsole. JConsoleimplements the JMX API, and enables you to monitor the performance of a Java VMand any instrumented applications. It provides information to help you optimize theperformance.Some of the enhancements in JConsole are as follows: JConsole plug-in support, which allows you to build your own plug-ins to run withJConsole. For example, you can add a custom tab for accessing the MBeans ofthe application. Dynamic attach capability allowing you to connect JConsole to any application thatsupports the Attach API. Enhanced user interface, which makes data more easily accessible. New Overview and VM Summary tabs for a better presentation of generalinformation about your Java VM. HotSpot Diagnostic MBean, which provides an API to request heap dump atruntime and also change the setting of certain VM options. Improved presentation of MBeans to make it easier to access the MBeansoperations and attributes.JConsole is presented in detail in the Using JConsole topic.Other command-line tools are also supplied with the Java SE platform.Java Management Extensions TechnologyThe Java SE platform, release 9 includes the Java Management Extensions (JMX)specification, version 1.4. The JMX API allows you to instrument applications formonitoring and management. A remote method invocation (RMI) connector allows thisinstrumentation to be remotely accessible, for example, using JConsole.See JMX technology documentation in the Java Platform, Standard Edition JavaManagement Extensions Guide.The following sections provide a brief introduction to the main components of the JMXAPI.1-2

Chapter 1Key Monitoring and Management FeaturesWhat Are MBeans?JMX technology MBeans are managed beans, namely Java objects that representresources to be managed. An MBean has a management interface consisting of thefollowing: Named and typed attributes that can be read and written. Named and typed operations that can be invoked. Typed notifications that can be emitted by the MBean.For example, an MBean representing an application's configuration can have attributesrepresenting different configuration parameters, such as a CacheSize. Reading theCacheSize attribute will return the current size of the cache. Writing CacheSize updatesthe size of the cache, potentially changing the behavior of the running application. Anoperation such as save stores the current configuration persistently. The MBean cansend a notification such as ConfigurationChangedNotification when the configurationchanges.MBeans can be standard or dynamic. Standard MBeans are Java objects that conformto design patterns derived from the JavaBeans component model. Dynamic MBeansdefine their management interface at runtime. An additional type of MBean, calledMXBean, is added to the Java platform. A standard MBean exposes the resource to be managed directly through itsattributes and operations. Attributes are exposed through getter and settermethods. Operations are the other methods of the class that are available tomanagers. All these methods are defined statically in the MBean interface and arevisible to a JMX agent through introspection. This method is the moststraightforward way of making a new resource manageable. A dynamic MBean is an MBean that defines its management interface at runtime.For example, a configuration MBean determines the names and types of theattributes that it exposes, by parsing an XML file. An MXBean is a type of MBean that provides a simple way to code an MBean thatreferences only a predefined set of types. In this way, you can ensure that theMBean is usable by any client. It includes remote clients without any requirementthat the client has access to model-specific classes, which represents the types ofyour MBeans. The platform MBeans are all MXBeans.MBean ServerTo be useful, an MBean must be registered in an MBean server. An MBean server is arepository of MBeans. Each MBean is registered with a unique name within the MBeanserver. Usually the only access to the MBeans is through the MBean server. In otherwords, code does not access an MBean directly, but rather accesses the MBean bythe name through the MBean server.The Java SE platform includes a built-in platform MBean server. See Using thePlatform MBean Server and Platform MXBeans.Creating and Registering MBeansThere are two ways to create an MBean. One is to construct a Java object that will bethe MBean, then use the registerMBean method to register it in the MBean server. The1-3

Chapter 1Platform MXBeansother method is to create and register the MBean in a single operation using one of thecreateMBean methods.The registerMBean method is simpler for local use, but cannot be used remotely. ThecreateMBean method can be used remotely, but sometimes requires attention to theclass loading issues. An MBean can perform actions when it is registered in orunregistered from an MBean server if it implements the MBeanRegistration interface.Instrumenting ApplicationsGeneral instructions on how to instrument your applications for management by theJMX API is beyond the scope of this document.Platform MXBeansA platform MXBean is an MBean for monitoring and managing the Java VM, and othercomponents of the Java Runtime Environment (JRE). Each MXBean encapsulates apart of VM functionality such as the class loading system, just-in-time (JIT) compilationsystem, garbage collector, and so on.Table 1-1 lists all the platform MXBeans and the aspect of the VM that they manage.Each platform MXBean has a unique javax.management.ObjectName for registration inthe platform MBean server. A Java VM may have zero, one, or more than oneinstance of each MXBean, depending on its function, as shown in the table.Table 1-1Platform MXBeansInterfacePart of VM ManagedObject NameInstances per VMClassLoadingMXBeanClass loading systemjava.lang:type ClassLoadingOneCompilationMXBeanCompilation systemjava.lang:type CompilationZero or onejava.lang:type GarbageCollector,name collectorNameOne or moreGarbageCollectorMXB Garbage collectoreanLoggingMXBeanLogging systemMemoryManagerMXBean Memory pool(subinterface ofGarbageCollectorMXBean)java.util.logging:t Oneype Loggingjava.lang:typeMemoryManager,name managerNameOne or moreMemoryPoolMXBeanMemoryjava.lang: type MemoryPool,name poolNameOne or moreMemoryMXBeanMemory systemjava.lang:type MemoryOnejava.lang:type OperatingSystemOnejava.lang:type RuntimeOneOperatingSystemMXBe Underlying operatingsystemanRuntimeMXBeanRuntime system1-4

Chapter 1Platform MBean ServerTable 1-1(Cont.) Platform MXBeansInterfacePart of VM ManagedObject NameInstances per VMThreadMXBeanThread systemjava.lang:type ThreadingOneThe details on platform MXBeans (apart from LoggingMXBean) are described in thejava.lang.management API reference. The LoggingMXBean interface is described inthe java.util.logging API reference.Platform MBean ServerThe platform MBean server can be shared by different managed components runningwithin the same Java VM. You can access the platform MBean server with the methodManagementFactory.getPlatformMBeanServer(). The first call to this method creates theplatform MBean server and registers the platform MXBeans using their unique objectnames. Subsequently, this method returns the initially created platform MBeanServerinstance.MXBeans that are created and destroyed dynamically (for example, memory pools andmanagers) will automatically be registered and unregistered in the platform MBeanserver. If the system property javax.management.builder.initial is set, then theplatform MBean server will be created by the specified MBeanServerBuilder parameter.You can use the platform MBean server to register other MBeans besides the platformMXBeans. This enables all MBeans to be published through the same MBean server,and makes network publishing and discovery easier.1-5

2Monitoring and Management Using JMXTechnologyThe Java virtual machine (Java VM) has built-in instrumentation that enables you tomonitor and manage it using the Java Management Extensions (JMX) technology.These built-in management utilities are often referred to as out-of-the-boxmanagement tools for the Java VM. You can also monitor any appropriatelyinstrumented applications using the JMX API.Setting System PropertiesTo enable and configure the ready-to-use JMX agent so that it can monitor andmanage the Java VM, you must set certain system properties when you start the JavaVM. You set a system property on the command line as follows:java -Dproperty value .You can set any number of system properties in this way. If you do not specify a valuefor a management property, then the property is set with its default value. SeeTable 2-1 for the full set of ready-to-use management properties. You can also setsystem properties in a configuration file, as described in the Ready-to-Use Monitoringand Management Properties section.Note:To run the Java VM from the command line, you must add JRE HOME/bin toyour path, where JRE HOME is the directory containing the Java RuntimeEnvironment (JRE) implementation. Alternatively, you can enter the full pathwhen you enter the command.The syntax and the full set of command-line options supported by the Java HotSpotVMs are described in the Java application launcher section of Java Platform, StandardEdition Tools Reference.Enabling the Ready-to-Use ManagementTo monitor a Java platform using the JMX API, you must do the following:1.Enable the

The Java Virtual Machine (Java VM) is instrumented for monitoring and management, enabling built-in (or ready-to-use) management capabilities that can be accessed both remotely and locally. See Monitoring and Management Using JMX Technology and SNMP Monitoring and Management. The Java VM inc