Java Management Extensions - PowerPoint PPT Presentation

1 / 62
About This Presentation
Title:

Java Management Extensions

Description:

Java Management Extensions. Borcon 2004. Ken Sipe. kensipe_at_codementor.net. 2. All Stuff ... Defined the problem space and need that JMX solves. ... – PowerPoint PPT presentation

Number of Views:580
Avg rating:3.0/5.0
Slides: 63
Provided by: kennethg3
Category:

less

Transcript and Presenter's Notes

Title: Java Management Extensions


1
Java Management Extensions
  • Borcon 2004
  • Ken Sipe
  • kensipe_at_codementor.net

2
Overall Presentation Goal
  • Defined the problem space and need that JMX
    solves.
  • Provided details on the architecture and
    understanding of the technology
  • Provide resources need to expound on this
    learning.

3
Speakers Qualifications
  • Sun Certified Java 2 Architect.
  • Instructor for VisiBroker for Java, OOAD,
    Rational Rose, and Java Development.
  • Frequently speaks on the subject of distributed
    computing programming, including CORBA and EJB
    architecture.
  • JBoss Certified Developer )

4
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX

5
What is JMX?
  • Java Management Extensions
  • Provides runtime application configuration and
    management.
  • Update services on the fly
  • No downtime
  • Provides monitoring services with notification
    services.
  • Standardized toolsets
  • Required for future J2EE Services

6
JMX History
  • JSR 03
  • Early need recognition
  • JMX 1.0 Sept 2000
  • JMX 1.2 Dec 2002

7
Implementations of the Spec
  • Sun
  • http//java.sun.com/products/JavaManagement/index.
    jsp
  • IBM
  • http//alphaworks.ibm.com/tech/TMX4J
  • Not really available separately any more, part of
    WAS 5.x
  • AdventNet
  • http//adventnet.com/
  • JBoss
  • http//jboss.org
  • mx4j
  • http//mx4j.sourceforge.net/

8
Wheres JMX currently used
  • WAS 5.0
  • Tomcat 5.0
  • mx4j
  • JBoss 2.4.x, 3.x, and 4.0 beta
  • jbossmx
  • Weblogic 7.x
  • Required
  • J2EE 1.4
  • J2SE 1.5

9
Related Specifications
  • JSR-77 J2EE Management API
  • JSR-88 J2EE Deployment API
  • JSR-160 JMX Remote API
  • JSR-174 Monitoring and Management for the JVM
    machine

10
J2EE Management API JSR-77
  • J2EE 1.4 Required
  • Provides API for Managed Objects
  • J2EEDomain
  • JVM
  • SessionBean
  • State Management
  • Performance Monitoring
  • SNMP

Provides a common tool set to provide monitoring
tools for any J2EE server.
11
Java Management Diagram
12
J2EE Deployment API JSR-88
  • J2EE 1.4 Required
  • Leverages JSR-77 for Targeting deployment

13
JMX Remote API JSR -160
  • JMX 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.
  • Defines the an interoperable, transparent, secure
    and flexible solution for clients to connect to
    JMX servers.
  • Defines
  • Connectors
  • Transport
  • Lookup Services
  • Bindings

14
New to JMX 1.2
  • Open Mbeans manitory
  • New interface StandardMBean interface
  • Class loader repository redesigned and class
    loading behavior clarified.
  • New Security Chapter
  • Updates to
  • Timer service
  • Monitor service
  • ObjectName class

15
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX

16
JMX Architecture Diagram
17
JMX Architecture
  • Instrumentation 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.
  • Agent 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.
  • Distributed Level
  • This level is defined in the specification as
    being needed and provides the details of HTML
    accessible, or SNMP capable. The specification
    doesnt provide a clear direction here, stating
    that it isnt 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
Instrumentation Level
  • MBeans
  • 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
Standard MBean
  • Most Simple
  • Predefined set of attributes and operations which
    are fixed in an Interface
  • Two 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
Standard MBean Interface Example
  • public interface VMMonitorMBean
  • public String getThreadCount()
  • public String getFreeMemory()
  • public String getTotalMemory()

21
Standard MBean Class Example
  • public class VMMonitor implements VMMonitorMBean
  • public String getThreadCount()
  • ThreadGroup root Thread.currentThread().getT
    hreadGroup()
  • 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
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
Dynamic MBean
  • Does NOT define fixed list of attributes and
    operations.
  • Attributes and operations are dynamic at runtime.
  • Must implement the DynamicMBean interface
  • 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
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
Dynamic MBean Characteristics
  • Works much like a COM object.
  • Query the interface with the getMBeanInfo()
  • Invoke the method with the invoke() method

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
Dynamic MBean Pros / Cons
  • Pro
  • Programmatic access to the meta data
  • MBean is not statically bound to Java class.
  • The bean could manage a resource which didnt
    exist at the time of development.
  • Faster execution.
  • Cons
  • Much more to develop.

28
Model MBeans
  • Mbean which extends the ModelMBean interface.
  • public abstract interface ModelMBean extends
    DynamicMBean, PersistentMBean, ModelMBeanNotificat
    ionBroadcaster
  • void setModelMBeanInfo(ModelMBeanInfo
    modelMBeanInfo) throws MBeanException,
    RuntimeOperationsException
  • void setManagedResource(Object object, String
    string) throws MBeanException, RuntimeOperationsEx
    ception, InstanceNotFoundException,
    InvalidTargetObjectTypeException
  • PersistentMBean
  • Interfaces adds the signatures necessary to
    persist the state of the Mbean
  • ModelMBeanNotificationBroadcaster
  • Interface provides the methods necessary to
    broadcast notifications

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

30
Open MBean
  • The open in Open MBeans carries the same
    connotation as open standards.
  • It refers to providing MBeans which follow
    standards in such a way that there is a high
    degree of interoperability.
  • Uses OpenMBeanInfo vs. MBeanInfo class
  • Implements the DynamicMBean interface
  • All types are constrained to

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

32
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX

33
Agent Level
  • MBean Server
  • MBean Registration Component
  • Communication Channel
  • Pre-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
MBeanServer
  • Creating an MBeanServer
  • MBeanServer server MBeanServerFactory.createMBe
    anServer()
  • MBeanServer server MBeanServerFactory.createMBe
    anServer(server1)
  • Finding an MBeanServer
  • ArrayList servers MBeanServerFactory.findMBeanS
    erver(null)
  • MBeanServer server (MBeanServer)servers.get(0)

35
Registering an MBean
  • MBeanServer server MBeanServerFactory.createMBea
    nServer()
  • ObjectName name new ObjectName("ServernameMoni
    tor")
  • server.registerMBean(new VMMonitor(), name)

36
M-Let Services
  • MLet Tag
  • ltMLET CODE class ARCHIVEjar listgt
    constructor arglist lt/MLETgt
  • Example
  • ltMLET CODEnet.codementor.VMMonitor
    ARCHIVEVM.jargt lt/MLETgt

37
M-Let Dynamic Loading
  • name new ObjectName(servicenameMLET")
  • server.registerMBean(new MLet(), name)
  • server.invoke(name,
  • "getMBeansFromURL",
  • new Object new
    URL("http//codementor.net/config.mlet"),
  • new StringURL.class.getName
    ()
  • )

38
Timer Service
  • Registration of 2 Mbeans with MBeanServer
  • Timer - Broadcaster
  • Reciever
  • Start the timer
  • Invoke the addNotification method on the Timer
  • addNotificationListener with a Filter

39
Timer Registration
  • ObjectName timer new ObjectName("servicenameti
    mer")
  • ObjectName receiver new ObjectName("domainname
    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
AddNotification
  • Date date new Date(System.currentTimeMillis()
    Timer.ONE_SECOND 5)
  • Integer id (Integer)server.invoke(timer,"a
    ddNotification",
  • new
    Object

  • "timer.event", // type

  • "Notification Message", // message
  • null,
    // user specific data
  • date
    // event time
  • ,
  • new
    String

  • String.class.getName(),

  • String.class.getName(),

  • Object.class.getName(),

  • Date.class.getName(),
  • )
  • server.addNotificationListener(timer, receiver,
    new ExampleFilter(id), null)

41
Notification Filter
  • public class ExampleFilter implements
    NotificationFilter
  • Integer id
  • public ExampleFilter(Integer id) this.id
    id
  • public boolean isNotificationEnabled(Notificatio
    n 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
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX

43
Distribution Level
  • Very loose in the specification
  • Tribal definition Connectors and Adaptors
  • HtmlAdaptorServer
  • HttpAdaptor
  • RMIAdaptor
  • JSR-160 Remote Access Specification allows any
    transport
  • RMI
  • IIOP
  • JMXMP
  • HTTP
  • SOAP
  • JMS

44
HtmlAdaptor Example
  • HtmlAdaptorServer adaptor new
    HtmlAdaptorServer()
  • adaptor.setPort(8082)
  • ObjectName adName new ObjectName("ServernameHt
    tpAdaptor")
  • server.registerMBean(adaptor, adName)
  • // start he adaptor service, which blocks the
    main thread
  • adaptor.start()

45
Html Console
46
HttpAdaptor Console
47
Remote Access JSR-160
  • MBeanServerConnection
  • Provides remote access
  • All methods through IOException
  • Must explicitly close connections

48
Remote / Local Access Comparison
  • Local access
  • MBeanServer server MBeanServerFactory.createMBea
    nServer()
  • server.createMBean(className, obName)
  • Object a server.getAttribute(obName, Attr)
  • Set names server.queryNames(...)
  • Remote access
  • JMXConnector c JMXConnectorFactory.connect(url)
  • MBeanServerConnection server c.getMBeanServerCon
    nection()
  • server.createMBean(className, obName)
  • Object a server.getAttribute(obName, Attr)
  • Set names server.queryNames(...)
  • c.close()

49
Remote Listeners
  • Code is the same as local
  • Connector handles forwarding notifications to
    remote clients.
  • class MyListener
  • implements NotificationListener ...
  • NotificationListener l new MyListener()
  • server.addNotificationListener(obName, l)

50
JMX Remote URL
  • Starts with servicejmx
  • servicejmxrmi//host/
  • servicejmxjmxmp//hostport

51
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX

52
ObjectName
  • Defines a unique name for an Mbean
  • Used to distinguish a bean for invocation
  • Used to query a server for a specific bean
  • Used to manage notification and relationship.

53
Object Naming Convention
  • Domainpropertyvalue,otherpropertyothervalue
  • Special Characters can not be used in the name
  • Colon ()
  • Comma()
  • Equals()
  • Asterisks ()
  • Example Names
  • ServernameMonitor
  • WebSpherenameserver1,processserver1,platformco
    mmon,nodefezzik,version5.0,typeServer,mbeanIden
    tifiercells/fezzik/nodes/fezzik/servers/server1/s
    erver.xmlServer_1,cellfezzik,processTypeUnManag
    edProcess

54
Querying Object Names
  • ,typeServer,
  • All Mbeans of type Server
  • ,cellfezzik
  • All Mbeans on the cell named fezzik

55
Presentation Agenda
  • JMX Introduction
  • JMX Architecture
  • Instrumentation Level
  • Agent Level
  • Distributed Services Level
  • JMX Object Naming
  • Leveraging JMX
  • Code and Demos

56
VMMonitor Example
  • public class VMMonitorTester
  • public static void main(String args) throws
    Exception
  • MBeanServer server MBeanServerFactory.createMBe
    anServer()
  • // 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("Servern
    ameHttpAdaptor")
  • server.registerMBean(adaptor, adName)
  • adaptor.start()

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

59
Need to know Tools
  • Mx4j
  • http//mx4j.sourceforge.net/
  • EJTools
  • http//www.ejtools.org/
  • https//sourceforge.net/projects/ejtools/
  • Jakarta Commons Modeler
  • http//jakarta.apache.org/commons/modeler/
  • MBeanInspector - (WebSphere)
  • http//www.alphaworks.ibm.com/tech/mbeaninspector
  • Sun
  • http//java.sun.com/jmx

60
Conclusion
  • JMX is mature
  • JMX is here to stay
  • JMX 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_at_codementor.net
Write a Comment
User Comments (0)
About PowerShow.com