Thursday, June 10, 2010

RHQ - how to monitor local JMX servers

If you are using tools like JConsole or VisualVM, you may have seen that it is possible to monitor JVMs that don't have explicit jmx-remoting settings.
This post shows how you can easily achieve the very same in your plugin.

Basically you need to do four things:

  1. Have your plugin use the jmx-plugin:

    <plugin name="hadoop"
    displayName="hadoopPlugin"
    <depends plugin="JMX" useClasses="true"/>


  2. In the Discovery Class (could also be done in ResourceComponent.start() at the very beginning), you put some additional plugin properties:


    public Set<DiscoveredResourceDetails> discoverResources(
    ResourceDiscoveryContext context)
    throws Exception
    {
    Configuration pluginConfiguration = context.getDefaultPluginConfiguration();
    pluginConfiguration.put(new PropertySimple(
    JMXDiscoveryComponent.COMMAND_LINE_CONFIG_PROPERTY,
    javaClazz));
    pluginConfiguration.put(new PropertySimple(
    JMXDiscoveryComponent.CONNECTION_TYPE,
    LocalVMTypeDescriptor.class.getName()));
    ...

    The javaClazz is the fully qualified name of the main class as it would
    appear with jps -l :


    $ jps -l
    3299 org.apache.hadoop.mapred.TaskTracker
    12311
    3177 org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode
    3037 org.apache.hadoop.hdfs.server.namenode.NameNode

    (the output is vmid and class, where the vmid is usually the process id)

  3. Have your component class extend JMXComponent

    public class HadoopServiceComponent extends JMXServerComponent, ...


  4. In component.start() call the JMXServerComponent

        
    public void start(ResourceContext context) throws Exception
    {
    super.start(context);
    ...
    }



From there on, you can get the JMX connection by a simple

     EmsConnection conn = getEmsConnection();


and so on ...

No comments:

Post a Comment