ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JMX Example (for use with Jconsole)

Post new topic  Reply to topic Goto page 1, 2  Next
 JMX Example (for use with Jconsole) « View previous topic :: View next topic » 
Author Message
lancelotlinc
PostPosted: Thu Mar 10, 2011 6:01 am    Post subject: JMX Example (for use with Jconsole) Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

We've had several threads on this, and I don't believe I have seen a short, step-by-step on using JMX inside WMB. So here are the Cliff notes:

1. Create a Singleton. See http://en.wikipedia.org/wiki/Singleton_pattern
2. Inside the Singleton constructor, place this code:

Code:
      Registry rmireg = null;
      
      try {
        rmireg = LocateRegistry.createRegistry(rmiregistryportnumber_try8999);
      } catch (RemoteException e) {
        e.printStackTrace();
        logger.warn( "LocateRegistry: "+e.getMessage());
      }

      JMXServiceURL address = null;
      try {
        address = new JMXServiceURL("service:jmx:rmi://yourservername:yourportnumber_try8993"+"/jndi/rmi://yourservername:rmiregistryportnumber_try8999/jmxrmi");
        logger.info( "JMXService Id: "+address.getClass()+" "+address.getHost()+" "+address.getPort()+" "+address.getProtocol()+" "+address.getURLPath()+" :: EG: "+egName+" Rmi: "+rmireg.toString()+" host: "+hostname);
      } catch (MalformedURLException e) {
        e.printStackTrace();
        logger.warn( "JMX MalformedURLException: "+ e.getMessage());
      }

      MBeanServer mbs = MBeanServerFactory.createMBeanServer();
      JMXConnectorServer jmxcServer = null;
      try {
        jmxcServer = JMXConnectorServerFactory.newJMXConnectorServer(address,null,mbs);
      } catch (IOException e) {
        e.printStackTrace();
        logger.warn( "JMX IOException: "+ e.getMessage());
      }
   
      try {
        jmxcServer.start();
      } catch (IOException e) {
        e.printStackTrace();
        logger.warn( "JMX IOException: "+ e.getMessage());
      }

      logger.info( "Connector server status: "+jmxcServer.isActive()+" "+jmxcServer.getAddress());
      oneofyoursbeanBean = new oneofyourbeanclasses(this);

      try {
        oneofyourbeansName = new ObjectName("yourDetails:name=ONE_OFYOURBEANS");
        mbs.registerMBean(oneofyourbeansBean, oneofyourbeansName);

        // Register and start the HTML adaptor
        HtmlAdaptorServer adapter = new HtmlAdaptorServer();
        ObjectName adapterName = null;
        adapterName = new ObjectName("SimpleyourAgent:name=htmladapter,port=someport_try7000");
        adapter.setPort(someport_try7000);
        mbs.registerMBean(adapter, adapterName);
        adapter.start();

        if( jmxcServer.isActive() == true ){
         
         System.out.println("MBean Agent is running for EG...");
         logger.info("MBean Agent is running for EG on "+hostname);
          
        }
      } catch (Exception e) {
        e.printStackTrace();
        logger.warn( "JMX Exception: "+ e.getMessage());
      }




3. Create a message flow, put a JCN in it, which calls Singleton.getInstance. First message through will instantiate the JMX Server.

Lance
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Thu Mar 10, 2011 6:26 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

So what are the dependencies here? Does one need to deploy specific jars? Does this depend on what version of Broker, and therefore what version of Java one is running?

Does one have to be careful about the classes used, such that one needs to take steps to isolate the jars from the broker?

What are the advantages that are provided?

What is the typical delay in processing the first time a message is run?
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Thu Mar 10, 2011 6:44 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Good questions mqjeff.

>> What is the typical delay in processing the first time a message is run?

Usually the first message incurs an additional 1 ms in latency. No increase in latency for subsequent messages.

>> What are the advantages that are provided?

You can use any JMX client (one you write yourself or Jconsole) to peek inside a running flow to see interesting statistics that you instrument. Such as, how many messages were processed in the last hour; or, how many database rows are loaded into my cache.

>> Does one have to be careful about the classes used,
>> such that one needs to take steps to isolate the jars
>> from the broker?

I've not had any difficulty. Same rules apply to these jars as to any other externally referenced jar.

>> So what are the dependencies here?
>> Does one need to deploy specific jars?

The source code example provided depends on jmxtools.jar and log4j-1.2.16.jar . I put them in shared-classes directory. Also, I put log4j.properties in common/wsrr directory.

If you didnt want the simple HTML server, you could eliminate jmxtools.jar and just use JMX and Jconsole. jmxtools.jar provides a simple HTML client you can use any web browser to interact with.

>>Does this depend on what version of Broker, and
>>therefore what version of Java one is running?

If using WMB 6.x, and you compile your own jar, set Java compliance to 1.5. If using WMB 7.x, you can use either 1.5 or 1.6 compliance level. The two jars (jmxtools.jar and log4j-1.2.16.jar) are distributed as 1.5 compliance level, so they don't need special treatment no matter what version of broker you use.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Thu Mar 10, 2011 7:12 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

lancelotlinc wrote:
>> What are the advantages that are provided?

You can use any JMX client (one you write yourself or Jconsole) to peek inside a running flow to see interesting statistics that you instrument. Such as, how many messages were processed in the last hour; or, how many database rows are loaded into my cache.


Does one have to instrument the statistics one is interested in?
Is there a clear advantage to using this method instead of using Accounting & Statistics and Monitoring events?
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Thu Mar 10, 2011 7:31 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

>> Does one have to instrument the statistics one is interested in?

Yes. See http://download.oracle.com/javase/tutorial/jmx/mbeans/standard.html

>> Is there a clear advantage ?

I think so, because, using MBeans, you can change things on-the-fly. For instance, I can turn up the level of logging, reload a class, reload cache, dump cache objects to a log file, change the behaviour of the code, etc. MBeans provide "Read/Write" capability to management.

>> using Accounting & Statistics and Monitoring events?

I like this also (Accounting & Statistics and Monitoring events). This is more robust in WMB v7. I didn't much care for it in WMB v6. I still think it could use more polish in the design-time interface. But I like it nevertheless. This mechanism is more "Read" than 'Read/Write".
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Thu Mar 10, 2011 7:44 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

I do hope you understand that I'm just discussing here.

Particularly in v7, the Administrative API(CMP API) has gone a long way towards making a lot more things Read&Write. And MBX is enabled and enhanced to take advantage of that and provide a good management console.

So I can certainly see using JMX to provide administrative controls over things that had been developed inside JCNs - the business logic, essentially.

But I still always lean towards using product native functions rather than reinvent the round-thing-on-an-axle. So I would never see a good reason to use JMX to keep track of the number of messages processed in the last hour, for example.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Thu Mar 10, 2011 7:47 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Yes, I agree with you. The messages in last hour was a top-of-the-head caffeine-deprived example.

I align with you in that where there are native APIs for Broker, those should be always the first choice.

JMX provides knobs, dials, and read-outs to the custom code.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
fenway_frank
PostPosted: Tue Jun 05, 2012 2:12 pm    Post subject: Reply with quote

Apprentice

Joined: 21 Oct 2011
Posts: 43
Location: Boston, MA USA

this is an interesting post and relevant to my immediate situation. we are considering visualVM admin dashboard to report back on jvm resource stats from broker 7.x. historical and snapshot capabilities are attractive with visualvm but i think broker's native cmp api will suffice.
curious, what protocol does broker use under-the-hood to capture resource stats that are viewable from cmp api/admin console? would be nice to extend the jvm resource stat collection capabilities beyond what it already provides (include thread usage for ex). also, are resource stats only available thru a system queue/topic or is it logged elsewhere?[/list]
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Jun 06, 2012 2:15 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Hi Frank -
You should be somewhat careful about monitoring each EG's JVM from a purely JVM point of view. You need to make sure that you know when you are seeing data that actually relates to your specific code and when you are essentially monitoring the performance of the broker's internal code.

And remember that some large part of Broker functionality never touches the JVM in the EG in the first place - there's still quite a bit that's handled direclty in the C++ runtime.

So unless you've got a lot of JavaCompute nodes, you may not achieve a lot of significant value out of monitoring the JVM like you're talking about.

What lancelotlinc is discussing in this thread is creating a JMX framework that wraps the CMP/Admin API to expose it's functions through JMX.
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Wed Jun 06, 2012 4:50 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

mqjeff wrote:
What lancelotlinc is discussing in this thread is creating a JMX framework that wraps the CMP/Admin API to expose it's functions through JMX.


For clarity, the value delivered by JMX Managed Beans is monitoring our Singleton and related cache objects. We track all transactions and results through the Singleton and jconsole et. al. provides a no-coding way to view these objects. We can also issue commands to the Singleton, such as reset the cache values, etc. While we have not used JMX to invoke CMP commands, it would be easy to do so.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
kash3338
PostPosted: Wed Jun 06, 2012 5:02 am    Post subject: Reply with quote

Shaman

Joined: 08 Feb 2009
Posts: 709
Location: Chennai, India

Just to know how exactly this helps in my message flow, you had mentioned advantage of using JMX as,

lancelotlinc wrote:
using MBeans, you can change things on-the-fly. For instance, I can turn up the level of logging, reload a class, reload cache, dump cache objects to a log file, change the behaviour of the code, etc. MBeans provide "Read/Write" capability to management.


As per my understanding, this can be used only in case I have vastly used JCN in my flow and used Java Singleton for my cache and log4j for logging. Apart from that, added advantage is to invoke CMP API from JMX right?

Will this help me in any way where I do not have anything of the above used in my message flow? Can I use this in my message flow (which does not have any of the above mentioned aspect implemented) just for Accounting & Statistics and Monitoring events or will this be a overhead?

Your thoughts please.
Back to top
View user's profile Send private message Send e-mail
lancelotlinc
PostPosted: Wed Jun 06, 2012 5:26 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

The Singleton provides the host to the JMX engine. Here is a resource that may help:

http://docs.oracle.com/javase/tutorial/jmx/index.html

JMX is independent of log4j, CMP, etc. Therefore, you can use JMX to do many things without needing those other technologies. For example, I could have a JMX Managed Bean that controls my cache of information in which I command the Bean to refresh the cache through jconsole or the command line.

JMX is designed to be high-speed, low-drag which means the overhead to use JMX is slight. YMMV. try it and see. From a blank page to a functional JMX implementation may take a good Java programmer an hour or so.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Wed Jun 06, 2012 5:27 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

lancelotlinc wrote:
JMX is designed to be high-speed, low-drag which means the overhead to use JMX is slight. YMMV. try it and see. From a blank page to a functional JMX implementation may take a good Java programmer an hour or so.


But, again, not much added value if all you have is ESQL and COBOL programmers.

And even less added value if all you have is .NET programmers...
Back to top
View user's profile Send private message
lancelotlinc
PostPosted: Wed Jun 06, 2012 5:29 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

mqjeff wrote:
lancelotlinc wrote:
JMX is designed to be high-speed, low-drag which means the overhead to use JMX is slight. YMMV. try it and see. From a blank page to a functional JMX implementation may take a good Java programmer an hour or so.


But, again, not much added value if all you have is ESQL and COBOL programmers.

And even less added value if all you have is .NET programmers...


We access our Singleton through ESQL and store ESQL objects in the cache. I would say that all WMB nodes can access JMX, not just Java Compute Nodes. The value to all nodes using JMX is the same regardless of language.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
kash3338
PostPosted: Thu Jun 07, 2012 1:36 am    Post subject: Reply with quote

Shaman

Joined: 08 Feb 2009
Posts: 709
Location: Chennai, India

lancelotlinc wrote:
I would say that all WMB nodes can access JMX, not just Java Compute Nodes. The value to all nodes using JMX is the same regardless of language.


Just on curiosity, can you explain how this can be done?
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » JMX Example (for use with Jconsole)
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.