Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Management Solutions Borcon 2005 Ken Sipe Borcon 2005 Ken Sipe

Similar presentations


Presentation on theme: "Java Management Solutions Borcon 2005 Ken Sipe Borcon 2005 Ken Sipe"— Presentation transcript:

1 Java Management Solutions Borcon 2005 Ken Sipe kensipe@codementor.net Borcon 2005 Ken Sipe kensipe@codementor.net

2 All Stuff No Fluff No Fluff ™ 2 Overall Presentation Goal tDefined the problem space and need that JMX solves. tProvided details on the architecture and understanding of the technology tProvide resources need to expound on this learning.

3 All Stuff No Fluff No Fluff ™ 3 Speaker’s Qualifications t tSun Certified Java 2 Architect. t tInstructor for VisiBroker for Java, OOAD, Rational Rose, and Java Development. t tFrequently speaks on the subject of distributed computing programming, including CORBA and EJB architecture. t tJBoss Certified Developer ;)

4 All Stuff No Fluff No Fluff ™ 4 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX

5 All Stuff No Fluff No Fluff ™ 5 What is JMX? t tJava Management Extensions t tProvides runtime application configuration and management. Update services on the fly No downtime t tProvides monitoring services with notification services. Standardized toolsets t tRequired for future J2EE Services

6 All Stuff No Fluff No Fluff ™ 6 JMX History tJSR – 03 Early need recognition tJMX 1.0 – Sept 2000 t JMX 1.2 – Dec 2002

7 All Stuff No Fluff No Fluff ™ 7 Implementations of the Spec t Sun http://java.sun.com/products/JavaManagement/index.jsp tIBM http://alphaworks.ibm.com/tech/TMX4J Not really available separately any more, part of WAS 5.x t AdventNet http://adventnet.com/ t JBoss http://jboss.org t mx4j http://mx4j.sourceforge.net/

8 All Stuff No Fluff No Fluff ™ 8 Where’s JMX currently used tWAS 5.0 tTomcat 5.0 mx4j tJBoss 2.4.x, 3.x, and 4.0 beta jbossmx tWeblogic 7.x tRequired J2EE 1.4 J2SE 1.5

9 All Stuff No Fluff No Fluff ™ 9 Related Specifications tJSR-77 J2EE Management API tJSR-88 J2EE Deployment API tJSR-160 JMX Remote API tJSR-174 Monitoring and Management for the JVM machine

10 All Stuff No Fluff No Fluff ™ 10 J2EE Management API JSR-77 tJ2EE 1.4 Required tProvides API for Managed Objects J2EEDomain JVM SessionBean tState Management tPerformance Monitoring tSNMP Provides a common tool set to provide monitoring tools for any J2EE server.

11 All Stuff No Fluff No Fluff ™ 11 Java Management Diagram

12 All Stuff No Fluff No Fluff ™ 12 J2EE Deployment API JSR-88 tJ2EE 1.4 Required tLeverages JSR-77 for Targeting deployment

13 All Stuff No Fluff No Fluff ™ 13 JMX Remote API JSR -160 tJMX specification since 1.0 defined distributed services as a level of the architecture. However even specification 1.2 merely mentions it and do not define it. tDefines the an interoperable, transparent, secure and flexible solution for clients to connect to JMX servers. tDefines: Connectors Transport Lookup Services Bindings

14 All Stuff No Fluff No Fluff ™ 14 New to JMX 1.2 tOpen Mbeans manitory tNew interface StandardMBean interface tClass loader repository redesigned and class loading behavior clarified. tNew Security Chapter tUpdates to: Timer service Monitor service ObjectName class

15 All Stuff No Fluff No Fluff ™ 15 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX

16 All Stuff No Fluff No Fluff ™ 16 JMX Architecture Diagram

17 All Stuff No Fluff No Fluff ™ 17 JMX Architecture tInstrumentation Level Defines the implementation of manageable resources commonly referred to as MBeans or Managed Beans. There are several defined types of MBeans which will be outlined in the Instrumentation section. This level essentially defines interfaces and APIs for the developer to adhere to during the implement of an Mbean. tAgent Level Defines the agents and services which will provide access to the managed resources. This level is implemented and provided to the developer providing services and the MBeanServer. tDistributed Level This level is defined in the specification as being needed and provides the details of HTML accessible, or SNMP capable. The specification doesn’t provide a clear direction here, stating that it isn’t in scope for this phase of the specification. Tribal knowledge defines this level as Connectors and Adaptors to the services. Additionally there is JSR-160 which defines JMX remote API, which purpose is to provide JMX agent discovery and access to clients.

18 All Stuff No Fluff No Fluff ™ 18 Instrumentation Level tMBeans Must provide the following characteristics Public and concrete One public constructor  Does not have to be a no argument constructor Categories Standard MBean Dynamic MBean

19 All Stuff No Fluff No Fluff ™ 19 Standard MBean tMost Simple tPredefined set of attributes and operations which are fixed in an Interface tTwo Components The interface This interface defines the publicly exposed API It has a specific naming convention* The class implementation Class must implement the defined interface

20 All Stuff No Fluff No Fluff ™ 20 Standard MBean Interface Example public interface VMMonitorMBean { public String getThreadCount(); public String getFreeMemory(); public String getTotalMemory(); }

21 All Stuff No Fluff No Fluff ™ 21 Standard MBean Class Example public class VMMonitor implements VMMonitorMBean { public String getThreadCount() { ThreadGroup root = Thread.currentThread().getThreadGroup(); while (root.getParent() != null) root = root.getParent(); return root.activeCount() + " active threads"; } public String getFreeMemory() { return Runtime.getRuntime().freeMemory() + " bytes"; } public String getTotalMemory() { return Runtime.getRuntime().totalMemory() + " bytes"; } }

22 All Stuff No Fluff No Fluff ™ 22 JMX 1.2 Standard MBean The JMX 1.2 Specification addresses the issue of forcing the MBean notation on an interface name. It allows for the creation of a standard MBean with an interface of an arbitrary name. The relationship of the interface and the implementation is managed by the creation of a StandardMBean object. The new StandardMBean class removes the necessary to follow the previously required naming convention of the MBean interface. Previously the association of the MBean interface to the MBean implementation was by naming convention. The StandardMBean constructor provides the associate in JMX 1.2. This allows the developer to name new interfaces any name desired or to over existing interfaces without change. In our StandardMBean example, the interface VMMonitorMBean could be named VMMonitor. In this case the following would create the StandardMBean which could then be registered with the MBeanServer: Mbean = new StandardMBean(new VMMonitorImpl(), VMMonitor.class);

23 All Stuff No Fluff No Fluff ™ 23 Dynamic MBean t Does NOT define fixed list of attributes and operations. Attributes and operations are dynamic at runtime. t Must implement the DynamicMBean interface t Types Dynamic MBean Any MBean which is dynamic Model MBean Extends ModelMBean interface, which extends the DynamicMBean interface Open MBean Dynamic MBean which follows specific rules

24 All Stuff No Fluff No Fluff ™ 24 DynamicMBean Interface public interface DynamicMBean { public MBeanInfo getMBeanInfo(); public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException; public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException; public AttributeList getAttributes(String[] attributes); public AttributeList setAttributes(AttributeList attributes); public Object invoke(String method, Object[] arguments, String[] params) throws MBeanException, ReflectionException; }

25 All Stuff No Fluff No Fluff ™ 25 Dynamic MBean Characteristics tWorks much like a COM object. tQuery the interface with the getMBeanInfo() tInvoke the method with the invoke() method

26 All Stuff No Fluff No Fluff ™ 26 MBeanInfo Class public class MBeanInfo implements Cloneable, Serializable { public String getClassName() public String getDescription() public MBeanConstructorInfo[] getConstructors() public MBeanAttributeInfo[] getAttributes() public MBeanOperationInfo[] getOperations() public MBeanNotificationInfo[] getNotifications() }

27 All Stuff No Fluff No Fluff ™ 27 Dynamic MBean Pros / Cons tPro: Programmatic access to the meta data MBean is not statically bound to Java class. The bean could manage a resource which didn’t exist at the time of development. Faster execution. tCons: Much more to develop.

28 All Stuff No Fluff No Fluff ™ 28 Model MBeans tMbean which extends the ModelMBean interface. public abstract interface ModelMBean extends DynamicMBean, PersistentMBean, ModelMBeanNotificationBroadcaster { void setModelMBeanInfo(ModelMBeanInfo modelMBeanInfo) throws MBeanException, RuntimeOperationsException; void setManagedResource(Object object, String string) throws MBeanException, RuntimeOperationsException, InstanceNotFoundException, InvalidTargetObjectTypeException; } tPersistentMBean Interfaces adds the signatures necessary to persist the state of the Mbean tModelMBeanNotificationBroadcaster Interface provides the methods necessary to broadcast notifications

29 All Stuff No Fluff No Fluff ™ 29 Model Mbean Characteristics t Provides a generic template for managing resources. t Provides extensions to the management interfaces, such as attributes, operations, constructors, and notifications. t Defines behavioral properties such as security, transactions, persistence, and caching.

30 All Stuff No Fluff No Fluff ™ 30 Open MBean t The open in Open MBeans carries the same connotation as open standards. tIt refers to providing MBeans which follow standards in such a way that there is a high degree of interoperability. tUses OpenMBeanInfo vs. MBeanInfo class tImplements the DynamicMBean interface tAll types are constrained to: Java data typesJava Wrapper types (java.lang.Double) java.lang.Stringjava.lang.Void java.util.Date java.math.BigInteger java.math.BigDecimal javax.management.ObjectName Java.management.open mbean.CompositeData java.management.openmbean. TabularData (interface)

31 All Stuff No Fluff No Fluff ™ 31 XMBeans (Not part of Spec) tTerm first introduced by JBoss Development team. tDefines a Dynamic Mbean which is configured and specified in XML. All the meta-data is described in XML tOther follow: IBM has a XML specification for Mbeans deployed in WAS Common Modeler Used by Tomcat 5 http://jakarta.apache.org/commons/modeler/

32 All Stuff No Fluff No Fluff ™ 32 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX

33 All Stuff No Fluff No Fluff ™ 33 Agent Level tMBean Server MBean Registration Component Communication Channel tPre-defined Service / MBeans M-Let Service Dynamic loading service Timer Service Notification service Monitoring Service Counter Monitor, Gauge Monitor, String Monitor Relation Service Maintains relationship information Notifies on relationship changes

34 All Stuff No Fluff No Fluff ™ 34 MBeanServer tCreating an MBeanServer MBeanServer server = MBeanServerFactory.createMBeanServer(); MBeanServer server = MBeanServerFactory.createMBeanServer(“server1”); tFinding an MBeanServer ArrayList servers = MBeanServerFactory.findMBeanServer(null); MBeanServer server = (MBeanServer)servers.get(0);

35 All Stuff No Fluff No Fluff ™ 35 Registering an MBean MBeanServer server = MBeanServerFactory.createMBeanServer(); ObjectName name = new ObjectName("Server:name=Monitor"); server.registerMBean(new VMMonitor(), name);

36 All Stuff No Fluff No Fluff ™ 36 M-Let Services tMLet Tag constructor arglist tExample

37 All Stuff No Fluff No Fluff ™ 37 M-Let Dynamic Loading name = new ObjectName(“service:name=MLET"); server.registerMBean(new MLet(), name); server.invoke(name, "getMBeansFromURL", new Object[] {new URL("http://codementor.net/config.mlet")}, new String[]{URL.class.getName()} );

38 All Stuff No Fluff No Fluff ™ 38 Timer Service tRegistration of 2 Mbeans with MBeanServer Timer - Broadcaster Reciever tStart the timer tInvoke the addNotification method on the Timer taddNotificationListener with a Filter

39 All Stuff No Fluff No Fluff ™ 39 Timer Registration ObjectName timer = new ObjectName("service:name=timer"); ObjectName receiver = new ObjectName("domain:name=timerlistener"); // Timer: import javax.management.timer.Timer; server.registerMBean(new Timer(), timer); // TimerReciever: is user defined, implements // javax.management.NotificationListener; server.registerMBean(new TimerReceiver(),receiver); server.invoke(timer, "start", null, null);

40 All Stuff No Fluff No Fluff ™ 40 AddNotification Date date = new Date(System.currentTimeMillis() + Timer.ONE_SECOND * 5); Integer id = (Integer)server.invoke(timer,"addNotification", new Object[] { "timer.event", // type "Notification Message", // message null, // user specific data date // event time }, new String[]{ String.class.getName(), Object.class.getName(), Date.class.getName(), }); server.addNotificationListener(timer, receiver, new ExampleFilter(id), null);

41 All Stuff No Fluff No Fluff ™ 41 Notification Filter public class ExampleFilter implements NotificationFilter { Integer id; public ExampleFilter(Integer id) { this.id = id; } public boolean isNotificationEnabled(Notification notification) { // check / filter the notification message if(notification.getType().equals("timer.event")) { // we know it is of type TimerNotification TimerNotification timerNote = (TimerNotification) notification; if(timerNote.getNotificationID().equals(id)) // it's a timerNotification and it's this specific timer notification return true; } return false; } }

42 All Stuff No Fluff No Fluff ™ 42 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX

43 All Stuff No Fluff No Fluff ™ 43 Distribution Level tVery loose in the specification tTribal definition: Connectors and Adaptors HtmlAdaptorServer HttpAdaptor RMIAdaptor tJSR-160 Remote Access Specification allows any transport RMI ** IIOP ** JMXMP * HTTP SOAP JMS

44 All Stuff No Fluff No Fluff ™ 44 HtmlAdaptor Example HtmlAdaptorServer adaptor = new HtmlAdaptorServer(); adaptor.setPort(8082); ObjectName adName = new ObjectName("Server:name=HttpAdaptor"); server.registerMBean(adaptor, adName); // start he adaptor service, which blocks the main thread adaptor.start();

45 All Stuff No Fluff No Fluff ™ 45 Html Console

46 All Stuff No Fluff No Fluff ™ 46 HttpAdaptor Console

47 All Stuff No Fluff No Fluff ™ 47 Remote Access JSR-160 tMBeanServerConnection Provides remote access All methods through IOException Must explicitly close connections

48 All Stuff No Fluff No Fluff ™ 48 Remote / Local Access Comparison  Local access: MBeanServer server = MBeanServerFactory.createMBeanServer(); server.createMBean(className, obName); Object a = server.getAttribute(obName, “Attr”); Set names = server.queryNames(...);  Remote access: JMXConnector c = JMXConnectorFactory.connect(url); MBeanServerConnection server = c.getMBeanServerConnection(); server.createMBean(className, obName); Object a = server.getAttribute(obName, “Attr”); Set names = server.queryNames(...); c.close();

49 All Stuff No Fluff No Fluff ™ 49 Remote Listeners tCode is the same as local tConnector handles forwarding notifications to remote clients. class MyListener implements NotificationListener {...} NotificationListener l = new MyListener(); server.addNotificationListener(obName, l);

50 All Stuff No Fluff No Fluff ™ 50 JMX Remote URL tStarts with “service:jmx:” service:jmx:rmi://host/… service:jmx:jmxmp://host:port

51 All Stuff No Fluff No Fluff ™ 51 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX

52 All Stuff No Fluff No Fluff ™ 52 ObjectName tDefines a unique name for an Mbean tUsed to distinguish a bean for invocation tUsed to query a server for a specific bean tUsed to manage notification and relationship.

53 All Stuff No Fluff No Fluff ™ 53 Object Naming Convention t[Domain]:property=value[,otherproperty=othervalue]* tSpecial Characters can not be used in the name Colon (:) Comma(;) Equals(=) Asterisks (*) tExample Names Server:name=Monitor WebSphere:name=server1,process=server1,platform=common,node=fezzik,version =5.0,type=Server,mbeanIdentifier=cells/fezzik/nodes/fezzik/servers/server1/server.x ml#Server_1,cell=fezzik,processType=UnManagedProcess

54 All Stuff No Fluff No Fluff ™ 54 Querying Object Names t*:*,type=Server,* All Mbeans of type Server t*:*,cell=fezzik All Mbeans on the cell named fezzik

55 All Stuff No Fluff No Fluff ™ 55 Presentation Agenda tJMX Introduction tJMX Architecture Instrumentation Level Agent Level Distributed Services Level JMX Object Naming tLeveraging JMX Code and Demos

56 All Stuff No Fluff No Fluff ™ 56 VMMonitor Example public class VMMonitorTester { public static void main(String[] args) throws Exception { MBeanServer server = MBeanServerFactory.createMBeanServer(); // register the new service ObjectName name = new ObjectName("VM"); server.registerMBean(new VMMonitor(), name); // register the http adaptor // HttpAdaptor adaptor = new HttpAdaptor(); HtmlAdaptorServer adaptor = new HtmlAdaptorServer(); adaptor.setPort(8082); ObjectName adName = new ObjectName("Server:name=HttpAdaptor"); server.registerMBean(adaptor, adName); adaptor.start(); }

57 All Stuff No Fluff No Fluff ™ 57 Working with WAS 5 Starting Server Starting wsadmin Query a MBean object name. Get all attributes for the MBean.

58 Demos / Code VMMonitor Timer Example WAS 5 VMMonitor Timer Example WAS 5

59 All Stuff No Fluff No Fluff ™ 59 Need to know Tools tMx4j http://mx4j.sourceforge.net/ tEJTools http://www.ejtools.org/ https://sourceforge.net/projects/ejtools/ tJakarta Commons Modeler http://jakarta.apache.org/commons/modeler/ tMBeanInspector - (WebSphere) http://www.alphaworks.ibm.com/tech/mbeaninspector tSun http://java.sun.com/jmx

60 All Stuff No Fluff No Fluff ™ 60 Conclusion tJMX is mature tJMX is here to stay tJMX defines the standard for Management and Monitoring

61 Questions?

62 Thank You Please fill out the speaker evaluation You can contact me further at... kensipe@codementor.net Please fill out the speaker evaluation You can contact me further at... kensipe@codementor.net


Download ppt "Java Management Solutions Borcon 2005 Ken Sipe Borcon 2005 Ken Sipe"

Similar presentations


Ads by Google