1 Reply Latest reply on Sep 29, 2011 12:25 AM by linjinxiao_hyperic

    jmx-c3p0 with dynamic object_name

    linjinxiao_hyperic Hot Shot
      OS:WIN7
      HYPERIC VERSIONsource code 4.5.1
      i write two plugin for jmx. One with fix object_name, it works fine. But c3p0 with
      dynamic object_name start jvm every time. So i write a plugin base java code. I extends MxMeasurementPlugin, find the object_name of c3p0. Code:
      public class C3p0MeasurementPlugin extends MxMeasurementPlugin {

           public ObjectName c3p0ObjectName = null;
           public MetricValue getValue(Metric metric) throws PluginException, MetricNotFoundException,
                     MetricUnreachableException {
                if (c3p0ObjectName == null) {
                     c3p0ObjectName = getC3p0ObjectName(metric);
                     if (c3p0ObjectName == null)
                          return null;
      //               System.out.println("c3p0ObjectName:"+c3p0ObjectName.getCanonicalName());
                }
                metric.setObjectName(c3p0ObjectName.getCanonicalName());
                return super.getValue(metric);
           }

           public ObjectName getC3p0ObjectName(Metric metric) {
                ObjectName objectName = null;
                try {
                     MBeanServerConnection conn = MxUtil.getMBeanServer(metric.getProperties());
                     Set names = conn.queryNames(new ObjectName("com.mchange.v2.c3p0:*"), null);
                     if (names == null)
                          return null;
                     for (Iterator i = names.iterator(); i.hasNext();) {
                          ObjectName name = (ObjectName) i.next();
                          if (name.getCanonicalName().contains("com.mchange.v2.c3p0:type=PooledDataSource")) {
                               objectName = name;
                          }
                     }
                } catch (MalformedURLException e) {
                     e.printStackTrace();
                } catch (IOException e) {
                     e.printStackTrace();
                } catch (MalformedObjectNameException e) {
                     e.printStackTrace();
                } catch (NullPointerException e) {
                     e.printStackTrace();
                }
                return objectName;
           }
      }

      and i wirte a xml file:
      <?xml version="1.0"?>
      <plugin>
           <service name="c3p0" server="Sun JVM" version="1.5">
                <property name="OBJECT_NAME" value="com.mchange.v2.c3p0:*" />
                <property name="AUTOINVENTORY_NAME" value="%platform.name% c3p0 pool %type%" />

                <config>
                     <option name="type" description="c3p0 instance id" default="" />
                </config>

                <plugin type="autoinventory" />
                <plugin type="measurement" class="aurora.jmx.C3p0MeasurementPlugin" />

                <filter name="template" value="${OBJECT_NAME}:${alias}" />
                <metric name="Active DB connections" template="${OBJECT_NAME}:numBusyConnections"
                     indicator="true" />

                <metric name="Idle DB connections" alias="numIdleConnections"
                     indicator="true" />

           </service>
      </plugin>


      i can test the plugin with hq-pdk-4.5.1.jar by command line, but in the ui monitor, it only can find the fix object_name plugin, can not find the c3p0 plugin.

      C:\Users\linjinxiao>java -jar D:/Mysoftware/agent-4.5.1/bundles/agent-4.5.1/pdk/lib/hq-pdk-4.5.1.jar -p c3p0 -t "Sun JVM
      1.5 c3p0" -Djmx.url=service:jmx:rmi:///jndi/rmi://localhost:6969/jmxrmi
      WARN  [main] [MetricsTag] MsSQL 2000 include not found: mssql-cache
      Sun JVM 1.5 c3p0 Idle DB connections:
         com.mchange.v2.c3p0:*:numIdleConnections:jmx.url=service%3Ajmx%3Armi%3A///jndi/rmi%3A//localhost%3A6969/jmxrmi,jmx.us
      ername=%jmx.username%,jmx.password=
         =>3.0<=

      Message was edited by: lin jinxiao