Monday, May 7, 2012

Hyperic, Anatomy of a JMX plugin

http://support.hyperic.com/display/DOC/JMX+Plugin

http://support.hyperic.com/display/DOC/JMX+Plugin+Tutorial

More modern (for 4.6.5):
http://support.hyperic.com/display/EVO/JMX+Plugin


java -Duser=weblogic -Dpass=weblogic1 -Dplugins.include=jmx -jar C:\pierre\hypericagent\agent-4.6.5-EE\bundles\agent-4.6.5\pdk\lib\hq-pdk-4.6.5.jar jmx MBeanDumper service:jmx:rmi:///jndi/rmi://myhost:8888/jmxrmi

(8888 is the remote jmx port)


java -Duser=weblogic -Dpass=weblogic1 -Dplugins.include=jmx -jar C:\pierre\hypericagent\agent-4.6.5-EE\bundles\agent-4.6.5\pdk\lib\hq-pdk-4.6.5.jar jmx MBeanDumper service:jmx:iiop://myhost:8001/jndi/weblogic.management.mbeanservers.runtime

(8001 is the listen port of the WLS)

you will get:

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial


so you will add -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory
and a we have this:

java -cp C:\Oracle\Middleware\wlserver_10.3\server\lib\wlfullclient.jar -Duser=weblogic -Dpass=weblogic1 -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory -Dplugins.include=jmx -jar C:\pierre\hypericagent\agent-4.6.5-EE\bundles\agent-4.6.5\pdk\lib\hq-pdk-4.6.5.jar jmx MBeanDumper service:jmx:iiop://myhost:8001/jndi/weblogic.management.mbeanservers.runtime

but adding the wlfullclient.jar is not enough, because the classpath is set in the MANIFEST.MF of the hq-pdk-4.6.5.jar:

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: bob
Build-Jdk: 1.6.0_29
Main-Class: org.hyperic.hq.product.util.PluginMain
Class-Path: hq-common-4.6.5.jar hq-util-4.6.5.jar commons-logging-1.0.
 4.jar httpclient-4.1.1.jar httpcore-4.1.jar commons-codec-1.4.jar com
 mons-validator-1.3.1.jar commons-beanutils-1.7.0.jar commons-digester
 -1.6.jar commons-collections-2.1.1.jar xml-apis-1.3.04.jar jsch-0.1.4
 2.jar log4j-1.2.14.jar velocity-1.6.3.jar commons-lang-2.4.jar oro-2.
 0.8.jar sigar-1.6.4.jar jdom-1.1.jar spring-beans-3.0.5.RELEASE.jar s
 pring-asm-3.0.5.RELEASE.jar spring-context-3.0.5.RELEASE.jar spring-a
 op-3.0.5.RELEASE.jar aopalliance-1.0.jar spring-expression-3.0.5.RELE
 ASE.jar org.springframework.roo.file.monitor-1.0.2.RELEASE.jar org.sp
 ringframework.roo.support-1.0.2.RELEASE.jar org.springframework.roo.f
 ile.monitor.polling-1.0.2.RELEASE.jar wrapper-3.5.6.jar xstream-1.3.1
 .jar xpp3_min-1.1.4c.jar hibernate-3.2.6.ga.jar asm-attrs-1.5.3.jar d
 om4j-1.6.1.jar antlr-2.7.6.jar cglib-2.1_3.jar asm-1.5.3.jar spring-t
 x-3.0.5.RELEASE.jar jboss-remoting-2.2.2.SP8.jar jboss-common-logging
 -spi-2.0.4.GA.jar hq-lather-4.6.5.jar backport-util-concurrent-3.1.ja
 r getopt-1.0.13.jar geronimo-j2ee-management_1.0_spec-1.1.jar snmp4j-
 1.11.jar xalan-2.7.1.jar serializer-2.7.1.jar cm-file-monitor-1.0.1.j
 ar cm-versioncontrol-1.0.1.jar slf4j-log4j12-1.6.1.jar slf4j-api-1.6.
 1.jar jcl-over-slf4j-1.6.1.jar org.eclipse.jgit-1.0.0.201106090707-r.
 jar org.eclipse.jgit.junit-1.0.0.201106090707-r.jar spring-oxm-3.0.5.
 RELEASE.jar jpathwatch-0-94.jar jaxb-api-2.1.jar stax-api-1.0-2.jar a
 ctivation-1.1.jar jaxb-impl-2.1.3.jar


all those classes are in
C:\pierre\hypericagent\agent-4.6.5-EE\bundles\agent-4.6.5\pdk\lib

I copy there the wlfullclient.jar

and I run
java -cp "C:\pierre\hypericagent\agent-4.6.5-EE\bundles\agent-4.6.5\pdk\lib\*" -Duser=weblogic -Dpass=weblogic1 -Djava.naming.factory.initial=weblogic.jndi.WLInitialContextFactory -Dplugins.include=jmx org.hyperic.hq.product.util.PluginMain jmx MBeanDumper service:jmx:iiop://myhost:8001/jndi/weblogic.management.mbeanservers.runtime


and I get

java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root ex
ception is java.net.ConnectException: t3://localhost:7001: Destination unreachable; nested exception
 is:
        java.net.ConnectException: Connection refused: connect; No available router to destination]
        at javax.management.remote.rmi.RMIConnector.connect(Unknown Source)
        at javax.management.remote.JMXConnectorFactory.connect(Unknown Source)
        at org.hyperic.hq.product.jmx.MxUtil.getMBeanConnector(MxUtil.java:538)
        at org.hyperic.hq.product.jmx.MxUtil.connect(MxUtil.java:564)
        at org.hyperic.hq.product.jmx.MxUtil.getMBeanServer(MxUtil.java:621)
        at org.hyperic.hq.product.jmx.MBeanDumper.getMBeanServer(MBeanDumper.java:138)
        at org.hyperic.hq.product.jmx.MBeanDumper.dump(MBeanDumper.java:164)
        at org.hyperic.hq.product.jmx.MBeanDumper.dump(MBeanDumper.java:160)
        at org.hyperic.hq.product.jmx.MBeanDumper.main(MBeanDumper.java:235)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.hyperic.hq.product.util.PluginMain.runMain(PluginMain.java:218)
        at org.hyperic.hq.product.util.PluginMain.main(PluginMain.java:317)


Were on earth is this "t3://localhost:7001" ? crap!!!


First, enable your Java process to be monitored by remote jmx (see help name="Java" at the end of the myfirstplugin.xml plugin below)

take this file myfirstplugin.xml and put it into $HQ_AGENT_HOME/pdk/plugins
(like /opt/hyperic/agent/agent-4.6.5-EE/bundles/agent-4.6.5/pdk/plugins)

and adjust the localhost:6969 bit:

<?xml version="1.0"?>
 
<!DOCTYPE plugin [<!ENTITY process-metrics SYSTEM "/pdk/plugins/process-metrics.xml">]>
 
<plugin package="org.hyperic.hq.plugin.java">
 
<classpath>
<include name="pdk/lib/mx4j"/>
</classpath>
 
<filter name="template" value="${OBJECT_NAME}:${alias}"/>
 
<metrics name="Class Loading Metrics">
<metric name="Loaded Class Count" indicator="false" category="THROUGHPUT"/>
<metric name="Total Loaded Class Count" indicator="false" category="THROUGHPUT"/>
<metric name="Unloaded Class Count" indicator="false" category="THROUGHPUT"/>
</metrics>
 
<metrics name="Compilation">
<metric name="Total Compilation Time" indicator="false" category="THROUGHPUT" collectionType="trendsup" units="ms"/>
</metrics>
 
<metrics name="Garbage Collector">
<metric name="Collection Count" indicator="false" category="THROUGHPUT" collectionType="trendsup"/>
<metric name="Collection Time" indicator="false" category="THROUGHPUT" collectionType="trendsup"/>
</metrics>
 
<metrics name="Memory">
<metric name="Object Pending Finalization Count" category="THROUGHPUT" indicator="false"/>
</metrics>
 
<metrics name="Threading">
<metric name="Thread Count" category="UTILIZATION" indicator="false"/>
<metric name="Daemon Thread Count" category="UTILIZATION" indicator="false"/>
</metrics>
 
<server name="Java" version="1.5.x">
<property name="HAS_BUILTIN_SERVICES" value="true"/>
<property name="VERSION_FILE" value="jre/lib/fontconfig.Sun.2003.bfc"/>
<property name="DEFAULT_PROGRAM" value="bin/java"/>
<property name="domain" value="Java"/>
 
<config>
<option name="jmx.url" description="JMX URL to MBeanServer"  default="service:jmx:rmi:///jndi/rmi://localhost:6969/jmxrmi"/>
<option name="jmx.username" description="JMX username" optional="true" default=""/>
<option name="jmx.password" description="JMX password" optional="true" default="" type="secret"/>
<option name="process.query" description="PTQL for Java Process" default="State.Name.eq=java,Args.*.ct=proc.java.home"/>
</config>
 
<metric name="Availability" template="sigar:Type=ProcState,Arg=%process.query%:State" indicator="true"/>
&process-metrics;
 
<property name="OBJECT_NAME" value="java.lang:type=ClassLoading"/>
 
<metrics include="Class Loading Metrics"/>
<property name="OBJECT_NAME" value="java.lang:type=Compilation"/>
 
<metrics include="Compilation"/>
<property name="OBJECT_NAME" value="java.lang:type=Memory"/>
 
<plugin type="log_track" class="org.hyperic.hq.product.jmx.MxNotificationPlugin"/>
 
<property name="OBJECT_NAME" value="java.lang:type=Threading"/>
<metrics include="Threading"/>
 
<!-- derive installpath from JAVA_HOME env prop... -->
<property name="PROC_HOME_ENV" value="JAVA_HOME"/>
 
<!-- derive installpath from -Dproc.java.home=... -->
<property name="PROC_HOME_PROPERTY" value="proc.java.home"/>
<plugin type="autoinventory" class="org.hyperic.hq.product.jmx.MxServerDetector"/>
<plugin type="measurement" class="org.hyperic.hq.product.jmx.MxMeasurementPlugin"/>
 
<service name="Java GC">
<plugin type="autoinventory"/>
<property name="OBJECT_NAME" value="java.lang:type=GarbageCollector,name=*"/>
<metrics include="Garbage Collector"/>
</service>
</server>
 
<server name="Java" version="1.6.x" include="1.5.x">
<property name="VERSION_FILE" value="jre/lib/management-agent.jar"/>
</server>
 
<!--
 ==================== Plugin Help ===========================
-->
<help name="Java">
<![CDATA[
  <p>
  <h3>Configure HQ for monitoring Java</h3>
  </p>
  <p>
  1) Add this line to the java options when executing the binary.
  <br>
  "-Dcom.sun.management.jmxremote \
  <br>
  -Dcom.sun.management.jmxremote.port=6969 \
  <br>
  -Dcom.sun.management.jmxremote.ssl=false \
  <br>
  -Dcom.sun.management.jmxremote.authenticate=false"
  <br>
  </p>
]]>
</help>
<help name="Java 1.5.x" include="Java"/>
<help name="Java 1.6.x" include="Java"/>
</plugin>


restart the agent:

./hq-agent.sh restart

No comments: