...
Table of Content Zone |
---|
RequirementsIn complex Java applications performance problems can occur due to various factors. These problems should be detected and retaliatory actions performed. Monitoring the cpu usage (per core), the amount of total and free physical memory or the process cpu time are only a few points. Monitoring should be possible with little impact on the design of the instrumented application. Instrumenting the VM would give us informations about such as the number of classes loaded, uptime of the JVM, the amount of memory consumed, number of threads running and deadlock detection. Another point would be the monitoring of the runtime stack. It would be an advantage if the monitoring agent doesn't need to know anything about the application to instrument. Due to that, we would achieve an encapsulation. It should be considered in which intervals the monitoring happens and what the trigger is. The amount of the instrumentation should also be configurable (whole application or only pieces). Possible ApproachesThere are a few possible ways to achieve the points listed above. Java SE 6 provides an in-depth focus on performance, offering expanded tools for managing and monitoring applications and for diagnosing common problems. The improvements include:
With this monitoring and management APIs it's possible to get extended informations about the VM such as current threads running, heap state or the memory usage. But there is one thing that can't be done with pure Java. That's where the JNI (Java Native Interface) comes into play. With the JNI it's possible to get informations like the cpu usage directly from the underlying OS. ere are a few possible ways to achieve the points listed above. Java SE 6 provides an in-depth focus on performance, offering expanded tools for managing and monitoring applications and for diagnosing common problems. The improvements include:
With this monitoring and management APIs it's possible to get extended informations about the VM such as current threads running, heap state or the memory usage. But there is one thing that can't be done with pure Java. That's where the JNI (Java Native Interface) comes into play. With the JNI it's possible to get informations like the cpu usage directly from the underlying OS. JMXThe Java Management Extensions (JMX) API is a standard API for management and monitoring of local and remote applications, devices, services, and the Java virtual machine. JMX became a standard part of the Java platform in in J2SE 5.0. Using JMX technology, a given resource is instrumented by one or more Java objects known as Managed Beans (MBeans). These MBeans are registered in a core managed object server (MBean server) that acts as a management agent and can run on most devices enabled for the Java programming language. JMX technology enables Java applications to be managed without heavy investment: A JMX technology agent can run on most Java technology-enabled devices, thus Java applications can become manageable with little impact on their design. A Java application simply needs to embed a managed object server and make some of its functionality available as one or several managed beans (MBeans) registered in the object server; that is all it takes to benefit from the management infrastructure.
JNIThe Java Native Interface is needed for getting informations like the cpu usage of der underlying OS. It's impossible querying for cpu usage with pure Java so we need to go through the JNI to call native methods. Getting the informations out of Windows it's needed to compile the DLLs with a C-Compiler and under Linux it's needed to compile the .so (shared objects) files.
DesignSince Java SE 6 there are a few APIs, which can help us in monitoring. These packages are also available in Java SE 5, so that it shouldn't be a problem with Java 5 applications.
With this APIs we can get informations about: Summary
Threads
Classes
Memory
Operating System
Other Information
JMXJMX technology provides a tiered architecture where managed resources and management applications can be integrated. A given resource is instrumented by one or more MBeans, which are registered in an MBean server. This server acts as a management agent and can run on most Java-enabled devices. 1. Instrumentation Level The instrumentation level defines the requirements for implementing JMX manageable resources. JMX resources can be anything that is developed in Java or provides a Java wrapper.
1.1 MBean
1.2 Notification ModelMBeans can generate notifications, for example to signal a state change, a detected event, or a problem. To generate notifications, an MBean has to implement the interfaces listed below.
1.3 MBean Metadata ClassesMetadata classes contain the structures to describe all components of an MBean's interface (its attributes, methods, notifications and constructors). The metadata includes for each of this a name, a description and its particular characteristics (for example, attribute: is it readable/writable? - method: signature and return types). 2. Agent LevelThe agent level contains the JMX agents used to expose the MBeans. It provides a specification for implementing agents, which control the resources and make them available to remote management applications. The JMX agent consists of an MBean server and a set of services for handling MBeans. 2.1 MBean ServerThe MBean server is a registry for MBeans that makes the MBean management interface available for use by management apps. MBean server never directly exposes the MBean object itself. Any object registered with the MBean server becomes visible to management applications. The server provides a standardized interface for accessing MBeans within the same JVM, giving local objects all the benefits of manipulating manageable resources.
2.2 Agent ServicesAgent services are objects that support standard operations on the MBeans.
3. Manager (or Distributed Services) LevelThis tier contains the components that enable management applications to communicate with JMX agents. It provides the interfaces for implementing JMX managers and defines the management interfaces and components that operate on agents. Such components provide an interface for a management application to interact with an agent and its JMX manageable resources through a connector, and also expose a management view of a JMX agent and its MBeans by mapping their semantic meaning into the constructs of a data-rich protocol (such as HTML). MXBeansAn MXBean is a type of MBean that references only a predefined setof data types. In this way, we can be sure that our MBean will be usable by any client, including remote clients, without any requirement that the client have access to model-specific classes representing the types of the MBeans. MXBeans provide a convenient way to bundle related values together, without requiring clients to be specially configured to handle the bundles. Design Decision The approach with JMX is currently not needed, because we only want to get measurements / informations about the instrumented application. With JMX we can also manage an application and perform specified operations through self-created MBeans. For the SystemSensors it's enough to get the informations of the virtual machine through MXBeans provided by the java.lang.management and com.sun.management packages. You can see here the design of the SystemSensors. RealizationExplanationhttps://195.227.0.189/NovaSpy/wiki/NovaSpy/Conceptual/DomainModel/PlatformSensors#ExplanationAll Information classes implement the IPlatformSensorinterface. The Information classes have one or more MXBeans to get the informations out of the virtual machine. The informations will be provided over the getters, which will called later by another service. Implementationhttps://195.227.0.189/NovaSpy/wiki/NovaSpy/Conceptual/DomainModel/PlatformSensors#ImplementationAgent5.0 The information classes are part of the Agent5.0 project and work only with Java SE 5.0 or higher. The inherited update()-method gets all the necessary informations through the MXBeans. The update()-method retrieves for a data object from the value storage. If the data object we're retrieving is empty here, then a new data object will be created and the specified data will be set, otherwise we're only updating the data object. The refresh time The refresh time in which the system sensors get updated is defined in the core service (also known as value storage) of the agent. The refresh time is by default 1000ms. This can be changed by setting the platformSensorRefreshTime. Data objects |