© C2B2 Consulting Limited 2013 
All Rights Reserved 
Through the JMX Window 
Matt Brasier 
Head of Consulting 
C2B2 Consulting
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Who am I? 
• Head of consulting at C2B2 
• Application server consultant 
– WebLogic 5.1->Present 
– JBoss 3.x -> Present 
– Tomcat, etc 
• Performance tuning and critical situation 
support 
• Author
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Agenda 
• What is JMX? 
• JMX tools 
• What information does it expose? 
• What operations can JMX expose? 
• Exposing your own information and 
operations
© C2B2 Consulting Limited 2013 
All Rights Reserved 
WHAT IS JMX?
© C2B2 Consulting Limited 2013 
All Rights Reserved 
What is JMX 
• Java Management 
eXtensions 
• Currently at version 1.4 
• http://docs.oracle.com/ 
javase/7/docs/technote 
s/guides/jmx/JMX_1_4_ 
specification.pdf 
“The Java Management 
extensions (also called 
the JMX specification) 
define an architecture, 
the design patterns, the 
APIs, and the services 
for application and 
network management 
and monitoring in the 
Java programming 
language.”
© C2B2 Consulting Limited 2013 
All Rights Reserved 
JMX History 
• 1998 – JMX starts as JSR 
3. EG composed of most 
J2EE vendors, based on 
JDMK 
• 2003 – J2EE 1.4 
incorporates JMX in the 
J2EE Spec 
• 2004 – With Java 5 
release, JMX becomes 
part of the JDK/Java SE 
• JMAPI – Java Management 
API, failed Sun project 
• JDMK – Java Dynamic 
Management Kit, another 
failed Sun project 
• JMX
© C2B2 Consulting Limited 2013 
All Rights Reserved 
What is management? 
• Management Information 
– Any information that is useful for the runtime 
management of the application. 
• Management Operations 
– Any operations that can assist in the runtime 
management of the application.
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Why JMX? 
• Application Management is important! 
– If often forgotten. 
• Standardise the APIs and patterns for exposing 
management operations and tooling. 
– Tools can be sure information is in an expected 
format. 
– Applications can take advantage of existing 
tooling.
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Core Concepts 
• MBean 
– Management Bean 
• Operations 
• Attributes 
• MBean Server 
– Registry for MBeans 
• API 
– Remote and local access to MBean Server and 
MBeans
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Core Concepts 
• Applications/Frameworks/Containers expose 
MBeans 
• The JVM contains an MBeanServer which 
registers all MBeans 
• Clients use the JMX API to connect to the 
MBeanServer and find relevant MBeans 
• Clients read/change values of attributes and 
invoke operations to manage the service
© C2B2 Consulting Limited 2013 
All Rights Reserved 
JMX TOOLS
© C2B2 Consulting Limited 2013 
All Rights Reserved 
JMX Tools 
• JConsole 
• JVisualVM 
• Monitoring tools 
– Hyperic HQ 
– Nagios 
– Etc
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Demo
© C2B2 Consulting Limited 2013 
All Rights Reserved 
WHAT INFORMATION DOES IT 
EXPOSE?
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Default JMX info 
• Heap Use 
– java.lang:type=Memory 
– java.lang:type=MemoryPool,name=Eden Space 
– java.lang:type=MemoryPool,name=Tenured Gen 
– java.lang:type=MemoryPool,name=Perm Gen 
• Garbage collection 
– java.lang:type=GarbageCollector,name=MarkSweepCompact 
– java.lang:type=GarbageCollector,name=Copy 
• Operating system info 
– java.lang:type=OperatingSystem
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Default JMX info 
• Runtime JVM parameters 
– java.lang:type=Runtime 
• NIO Buffers 
– java.nio:type=BufferPool,name=direct 
• JDK Logger 
– java.util.logging:type=Logging 
• Classloading 
– java.lang:type=ClassLoading 
• And more!
© C2B2 Consulting Limited 2013 
All Rights Reserved 
In an application server 
• Connection pool info 
– Sizes 
– Free connections 
• Servlet/JSP info 
– Number of requests 
– Number of errors 
• Thread pools 
– Sizes 
• JMS 
– Queue sizes 
– Pending messages 
• EJBs 
– Pool sizes 
– Cache hit rates 
• Connectors 
– In coming request 
volumes
© C2B2 Consulting Limited 2013 
All Rights Reserved 
WHAT OPERATIONS DOES IT 
EXPOSE?
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Default operations 
• com.sun.management:type=HotSpotDiagnostic 
– dumpHeap 
– setVMOption 
– getVMOption 
• java.lang:type=Memory 
– Gc 
• java.lang:type=Threading 
– dumpAllThreads 
– findDeadLockedThreads
© C2B2 Consulting Limited 2013 
All Rights Reserved 
In an application server 
• Datasources 
– Reset all datasources 
• JMS 
– Delete all messages 
• Server 
– Restart or stop a server 
• Deployment 
– Deploy or redeploy applications
© C2B2 Consulting Limited 2013 
All Rights Reserved 
In an application server 
• Any operation you 
could normally perform 
to manage an 
application server! 
• It is like an X-ray of your 
application
EXPOSING YOUR OWN 
MANAGEMENT INFORMATION AND 
OPERATIONS 
© C2B2 Consulting Limited 2013 
All Rights Reserved
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Two step process 
• Create MBeans 
• Register with MBean 
server 
• Profit
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Create MBeans 
• Identify where in your application you have 
relevant management information 
• Create an MBean interface 
• Implement the MBean interface
© C2B2 Consulting Limited 2013 
All Rights Reserved 
MBean Interface 
public Interface LocationMonitorMBean 
{ 
public void getNumberOfFiles(); 
public void setScanPeriod(); 
public void getScanPeriod(); 
public void resetFileCounter(); 
public void disable(); 
public void enable(); 
public void getEnabled(); 
} 
Getters and Setters represent 
Attributes 
Other methods represent 
operations
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Implementation class 
• Implement the MBean interface 
– You can do this with an existing class 
• Try and avoid doing intensive work in the 
MBean implementation 
– Pre-compute values 
– Periodically check and cache values
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Implementation class 
public class LocationMonitor implements LocationMonitorMBean 
{ 
private boolean enabled; 
private long scanInterval; 
private long numFiles; 
public void getNumberOfFiles( 
{ 
return numFiles; 
... 
Attributes are accessed via getters/setters
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Register with MBeanServer 
• Create (or get hold of) an instance of your 
MBean implementation 
• Get hold of an MBean Server 
– PlatformMBeanServer 
• Create an ObjectName for your MBean 
• Register the MBean
Get the MBean Server 
Create the ObjectName 
© C2B2 Consulting Limited 2013 
All Rights Reserved 
Register with MBeanServer 
public static void main(String[] args) throws Exception 
{ 
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); 
ObjectName name = new 
ObjectName(“uk.co.c2b2.management:type=LocationMonitor"); 
LocationMonitor mbean = new LocationMonitor(); 
mbs.registerMBean(mbean, name); 
} 
Create the MBean instance 
Register it
© C2B2 Consulting Limited 2013 
All Rights Reserved 
What to monitor 
• Resources that your application uses 
– Including data (flow rates etc) 
• Expose management operations 
– Restarting components 
– Re-loading configuration files
What is through the JMX window? 
© C2B2 Consulting Limited 2013 
All Rights Reserved 
• A future with more 
Information 
• A future with more 
control
© C2B2 Consulting Limited 2013 
All Rights Reserved 
QUESTIONS?

Through the JMX Window

  • 1.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Through the JMX Window Matt Brasier Head of Consulting C2B2 Consulting
  • 2.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Who am I? • Head of consulting at C2B2 • Application server consultant – WebLogic 5.1->Present – JBoss 3.x -> Present – Tomcat, etc • Performance tuning and critical situation support • Author
  • 3.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Agenda • What is JMX? • JMX tools • What information does it expose? • What operations can JMX expose? • Exposing your own information and operations
  • 4.
    © C2B2 ConsultingLimited 2013 All Rights Reserved WHAT IS JMX?
  • 5.
    © C2B2 ConsultingLimited 2013 All Rights Reserved What is JMX • Java Management eXtensions • Currently at version 1.4 • http://docs.oracle.com/ javase/7/docs/technote s/guides/jmx/JMX_1_4_ specification.pdf “The Java Management extensions (also called the JMX specification) define an architecture, the design patterns, the APIs, and the services for application and network management and monitoring in the Java programming language.”
  • 6.
    © C2B2 ConsultingLimited 2013 All Rights Reserved JMX History • 1998 – JMX starts as JSR 3. EG composed of most J2EE vendors, based on JDMK • 2003 – J2EE 1.4 incorporates JMX in the J2EE Spec • 2004 – With Java 5 release, JMX becomes part of the JDK/Java SE • JMAPI – Java Management API, failed Sun project • JDMK – Java Dynamic Management Kit, another failed Sun project • JMX
  • 7.
    © C2B2 ConsultingLimited 2013 All Rights Reserved What is management? • Management Information – Any information that is useful for the runtime management of the application. • Management Operations – Any operations that can assist in the runtime management of the application.
  • 8.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Why JMX? • Application Management is important! – If often forgotten. • Standardise the APIs and patterns for exposing management operations and tooling. – Tools can be sure information is in an expected format. – Applications can take advantage of existing tooling.
  • 9.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Core Concepts • MBean – Management Bean • Operations • Attributes • MBean Server – Registry for MBeans • API – Remote and local access to MBean Server and MBeans
  • 10.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Core Concepts • Applications/Frameworks/Containers expose MBeans • The JVM contains an MBeanServer which registers all MBeans • Clients use the JMX API to connect to the MBeanServer and find relevant MBeans • Clients read/change values of attributes and invoke operations to manage the service
  • 11.
    © C2B2 ConsultingLimited 2013 All Rights Reserved JMX TOOLS
  • 12.
    © C2B2 ConsultingLimited 2013 All Rights Reserved JMX Tools • JConsole • JVisualVM • Monitoring tools – Hyperic HQ – Nagios – Etc
  • 13.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Demo
  • 14.
    © C2B2 ConsultingLimited 2013 All Rights Reserved WHAT INFORMATION DOES IT EXPOSE?
  • 15.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Default JMX info • Heap Use – java.lang:type=Memory – java.lang:type=MemoryPool,name=Eden Space – java.lang:type=MemoryPool,name=Tenured Gen – java.lang:type=MemoryPool,name=Perm Gen • Garbage collection – java.lang:type=GarbageCollector,name=MarkSweepCompact – java.lang:type=GarbageCollector,name=Copy • Operating system info – java.lang:type=OperatingSystem
  • 16.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Default JMX info • Runtime JVM parameters – java.lang:type=Runtime • NIO Buffers – java.nio:type=BufferPool,name=direct • JDK Logger – java.util.logging:type=Logging • Classloading – java.lang:type=ClassLoading • And more!
  • 17.
    © C2B2 ConsultingLimited 2013 All Rights Reserved In an application server • Connection pool info – Sizes – Free connections • Servlet/JSP info – Number of requests – Number of errors • Thread pools – Sizes • JMS – Queue sizes – Pending messages • EJBs – Pool sizes – Cache hit rates • Connectors – In coming request volumes
  • 18.
    © C2B2 ConsultingLimited 2013 All Rights Reserved WHAT OPERATIONS DOES IT EXPOSE?
  • 19.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Default operations • com.sun.management:type=HotSpotDiagnostic – dumpHeap – setVMOption – getVMOption • java.lang:type=Memory – Gc • java.lang:type=Threading – dumpAllThreads – findDeadLockedThreads
  • 20.
    © C2B2 ConsultingLimited 2013 All Rights Reserved In an application server • Datasources – Reset all datasources • JMS – Delete all messages • Server – Restart or stop a server • Deployment – Deploy or redeploy applications
  • 21.
    © C2B2 ConsultingLimited 2013 All Rights Reserved In an application server • Any operation you could normally perform to manage an application server! • It is like an X-ray of your application
  • 22.
    EXPOSING YOUR OWN MANAGEMENT INFORMATION AND OPERATIONS © C2B2 Consulting Limited 2013 All Rights Reserved
  • 23.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Two step process • Create MBeans • Register with MBean server • Profit
  • 24.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Create MBeans • Identify where in your application you have relevant management information • Create an MBean interface • Implement the MBean interface
  • 25.
    © C2B2 ConsultingLimited 2013 All Rights Reserved MBean Interface public Interface LocationMonitorMBean { public void getNumberOfFiles(); public void setScanPeriod(); public void getScanPeriod(); public void resetFileCounter(); public void disable(); public void enable(); public void getEnabled(); } Getters and Setters represent Attributes Other methods represent operations
  • 26.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Implementation class • Implement the MBean interface – You can do this with an existing class • Try and avoid doing intensive work in the MBean implementation – Pre-compute values – Periodically check and cache values
  • 27.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Implementation class public class LocationMonitor implements LocationMonitorMBean { private boolean enabled; private long scanInterval; private long numFiles; public void getNumberOfFiles( { return numFiles; ... Attributes are accessed via getters/setters
  • 28.
    © C2B2 ConsultingLimited 2013 All Rights Reserved Register with MBeanServer • Create (or get hold of) an instance of your MBean implementation • Get hold of an MBean Server – PlatformMBeanServer • Create an ObjectName for your MBean • Register the MBean
  • 29.
    Get the MBeanServer Create the ObjectName © C2B2 Consulting Limited 2013 All Rights Reserved Register with MBeanServer public static void main(String[] args) throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName(“uk.co.c2b2.management:type=LocationMonitor"); LocationMonitor mbean = new LocationMonitor(); mbs.registerMBean(mbean, name); } Create the MBean instance Register it
  • 30.
    © C2B2 ConsultingLimited 2013 All Rights Reserved What to monitor • Resources that your application uses – Including data (flow rates etc) • Expose management operations – Restarting components – Re-loading configuration files
  • 31.
    What is throughthe JMX window? © C2B2 Consulting Limited 2013 All Rights Reserved • A future with more Information • A future with more control
  • 32.
    © C2B2 ConsultingLimited 2013 All Rights Reserved QUESTIONS?