Tag: JMX

Accessing “jboss.web:type=*” MBeans Programmatically in JBossAS7.1.1

Hi,

During various builds of JBoss AS7 the MBean access methodology was kee changing, even the JMX subsystem XSD “jboss-as-jmx_1_1.xsd” also changed a lot from JBossAS7.0 till JBossAS7.1.1 Final. So here we are going to see How can we access the JBoss MBeans Remotely & Programatically. Here are the following points which we will notice as part of this article:

Point-1). Accessing MBeans using the JBoss Native Management port 9999 on JBoss AS7.1.1.Final.

Point-2). The jmx subsystem inside our JBoss configuration file like “standalone-full.xml” should look something like following:

        <subsystem xmlns="urn:jboss:domain:jmx:1.1">
            <show-model value="true"/>
             <remoting-connector  use-management-endpoint="true" />
        </subsystem>

Here If the value of “use-management-endpoint” is “true” then this connector will use the management endpoint, otherwise it will use the remoting subsystem endpoint.

Point-3). Here we will also need to make sure that we enable the following System Property in the JBoss Cofiguration file (standalone*.xml) So that JBoss will make the “jboss.web:type=Manager” access available for the remote JMX Clients.

    <system-properties>
        <property name="org.apache.tomcat.util.ENABLE_MODELER" value="true"/>
    </system-properties>

***NOTE***: If you will not add the above System property for your JBoss then JBoss will not expose some of the MBeans which are available as part of “jboss.web:type=*”

Accessing MBeans Programatically Remotely/Locally

Step-1). After enabling the System property org.apache.tomcat.util.ENABLE_MODELER=true on your JBoss, Start your JBoss AS7.1.1 Final like following

     ./standalone.sh  -c standalone-full.xml

You can also start it in a particular Bind address as well.

Step-2). Write a Simple Class “JBossJMXClient.java” inside “/home/userone/JmxDemo/” as following:

import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.management.*;

public class JBossJMXClient {
    public static void main(String[] args) throws Exception {
        String host = "localhost";  // Your JBoss Bind Address default is localhost
        int port = 9999;  // management-native port

        String urlString ="service:jmx:remoting-jmx://" + host + ":" + port;
        System.out.println("		nnt****  urlString: "+urlString);

        JMXServiceURL serviceURL = new JMXServiceURL(urlString);
        JMXConnector jmxConnector = JMXConnectorFactory.connect(serviceURL, null);
        MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();

        //Invoke on the JBoss AS MBean server
        int count = connection.getMBeanCount();
        System.out.println(count);

        ObjectName objectName=new ObjectName("jboss.web:type=Manager,path=/Log4jDemo,host=default-host");
        Integer sessionMaxAliveTime=(Integer)connection.getAttribute(objectName, "sessionMaxAliveTime");
        Integer maxInactiveInterval=(Integer)connection.getAttribute(objectName, "maxInactiveInterval");
        Integer activeSessions=(Integer)connection.getAttribute(objectName, "activeSessions");
        Integer sessionCounter=(Integer)connection.getAttribute(objectName, "sessionCounter");
        Integer sessionAverageAliveTime=(Integer)connection.getAttribute(objectName, "sessionAverageAliveTime");
        Long processingTime=(Long)connection.getAttribute(objectName, "processingTime");
        Integer sessionIdLength=(Integer)connection.getAttribute(objectName, "sessionIdLength");
        Integer maxActive=(Integer)connection.getAttribute(objectName, "maxActive");
        Integer maxActiveSessions=(Integer)connection.getAttribute(objectName, "maxActiveSessions");
        Integer expiredSessions=(Integer)connection.getAttribute(objectName, "expiredSessions");
        Integer rejectedSessions=(Integer)connection.getAttribute(objectName, "rejectedSessions");

        System.out.println("	maxInactiveInterval     = "+maxInactiveInterval);
        System.out.println("	activeSessions          = "+activeSessions);
        System.out.println("	sessionCounter          = "+sessionCounter);
        System.out.println("	sessionAverageAliveTime = "+sessionAverageAliveTime);
        System.out.println("	sessionAverageAliveTime = "+sessionAverageAliveTime);
        System.out.println("	processingTime          = "+processingTime);
        System.out.println("	sessionIdLength         = "+sessionIdLength);
        System.out.println("	maxActiveSessions       = "+maxActiveSessions);
        System.out.println("	maxActive               = "+maxActive);
        System.out.println("	expiredSessions         = "+expiredSessions);

        jmxConnector.close();
    }
}

/*  Make sure that the following System property is enable in your JBoss

    <system-properties>
        <property name="org.apache.tomcat.util.ENABLE_MODELER" value="true"/>
    </system-properties>
*/

***NOTE***: In the above program we are trying to access various attributes present inside the ObjectName “jboss.web:type=Manager,path=/Log4jDemo,host=default-host” where “Log4jDemo” is the Context-Root of My WebApplication which i wanted to monitor. And th edefault Host-Name is “default-host”, In your case these values might be different so better use the JConsole to connect to JBoss Locally and then get the exact Object name from it.

Step-3). Now oipen a Terminal where we need to set the PATh and CLASSPATH like following:

For UNIX Based Operating System:

export PATH=/home/userone/jdk1.6.0_21/bin:$PATH
export CLASSPATH=/home/userone/jboss-as-7.1.1.Final/bin/client/jboss-client.jar:$CLASSPATH:.:

++++++++++++++++++++++++++++++++
For Windows Based Operating System

set PATH=C:jdk1.6.0_21bin;%PATH%
set CLASSPATH=c:jboss-as-7.1.1.Finalbinclientjboss-client.jar;%CLASSPATH%;.;

***NOTE***: It is must that your JMX Client should include the “jboss-client.jar” in it’s classpath as above.

Step-4). Now compile and run the above program:

[userone@localhost JmxDemo]$ javac JBossJMXClient.java
[userone@localhost JmxDemo]$ java JBossJMXClient

	****  urlString: service:jmx:remoting-jmx://localhost:9999

May 20, 2012 9:54:12 AM org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
May 20, 2012 9:54:12 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
May 20, 2012 9:54:12 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.3.GA
243
	maxInactiveInterval     = 1800
	activeSessions          = 3
	sessionCounter          = 3
	sessionAverageAliveTime = 0
	sessionAverageAliveTime = 0
	processingTime          = 0
	sessionIdLength         = 18
	maxActiveSessions       = -1
	maxActive               = 3
	expiredSessions         = 0

Accessing MBeans using JConsole Locally

As mentioned earlier that If you will not add the above System property (org.apache.tomcat.util.ENABLE_MODELER=true) for your JBoss then JBoss will not expose some of the MBeans which are available as part of “jboss.web:type=*” So after enabling it Just start the Server and Open the “$JAVA_HOME/bin/jconsole” . jconsole will be able to detect any locally running JAVA process just connect to your JBoss process through it then you will be able to see the following kind of JBoss MBeans inside jconsole:

JConsole_WebContainerMBean_Access_JBossAS711

.
.
Thanks 🙂
Middleware Magic Team


Listing All MBeans present inside JBossAS7 programatically

Hi,

In this demonstration we will see ow we can get all the MBeans present inside JBoss AS7 CR1b, because many of the developers want to talk to JBoss using their own mbean based java code. In this example we will see that we need not to add any additional JAVA_OPTS in our JBoss configuration files in order to access these MBeans.

Once you get to know the ObjectName of the MBean present inside JBoss AS7 then it becomes very easy to programatically access it’s various operations and attributes. You can refer to some of the previous demos present in middlewaremagic for further research on this direction. For Example: Getting WebService Statistics using MBean Code

JBoss side Configuration

Step1). Open the “/home/userone/jboss-as-7.1.0.CR1b/standalone/configuration/standalone-full.xml” file and edit the subsystem “urn:jboss:domain:jmx:1.1” as following:

        <subsystem xmlns="urn:jboss:domain:jmx:1.1">
            <show-model value="true"/>
            <jmx-connector registry-binding="jmx-connector-registry" server-binding="jmx-connector-server"/>
        </subsystem>

Step2). Restart your JBoss Profile from “/home/userone/jboss-as-7.1.0.CR1b/bin” directory like following:

[userone@localhost bin]$ ./standalone.sh -c standalone-full.xml

Step3). Now Somewhere in your filesystem (like /home/userone/MBeanDemo directory) write a Java Program “TestMBeanServiceMonitor.java” as following:

import java.util.*;
import java.util.Hashtable;
import java.io.IOException;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.lang.management.MemoryMXBean;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import javax.management.*;
import javax.management.openmbean.CompositeDataSupport;
 
public class TestMBeanServiceMonitor
{
    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    public static void Connection(String hostname, String port) throws IOException
    {
        Integer portInteger = Integer.valueOf(port);
        Hashtable h = new Hashtable();
        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+hostname+":"+port+"/jmxrmi");
        connector = JMXConnectorFactory.connect(address,null);
        connection = connector.getMBeanServerConnection();
        System.out.println("GOT THE MBeanServerConnection---SUCCESSFULLY");
    }
  
    private static void listAllJBossAS7MBeans() throws Exception
    {
        //ObjectName serviceRef=new ObjectName("jboss.as:*");
        ObjectName serviceRef=new ObjectName("*.*:*");
        Set<ObjectName> mbeans = connection.queryNames(serviceRef, null);
        for (ObjectName on : mbeans) {
                  System.out.println("t ObjectName : "+on);
        }
    }

    private static void getThreadDetails() throws Exception
    {
        ObjectName serviceRef=new ObjectName("java.lang:type=Threading");
        Integer daemonThreadCount=(Integer)connection.getAttribute(serviceRef, "DaemonThreadCount");
        System.out.println("t daemonThreadCount : "+daemonThreadCount);
    }

    public static void main(String[] args) throws Exception
    {
        String hostname = args[0];
        String port = args[1];    
        /*
        ***** The port binding should be defined inside your "standalone-full.xml" file.  *****
        *  
        <subsystem xmlns="urn:jboss:domain:jmx:1.1">
            <show-model value="true"/>
            <jmx-connector registry-binding="jmx-connector-registry" server-binding="jmx-connector-server"/>
        </subsystem>
        */

        Connection(hostname, port); 
        System.out.println("nt All JBoss AS7 MBean Listing nn");
        listAllJBossAS7MBeans() ;
    }
}

Step4). Now we will write a simple Ant build script to build and execute the above program. So write an Ant build script “/home/userone/MBeanDemo/build.xml” file in the same directory where the above program is placed.

<project name="JBoss_Monitor" default="run">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.CR1b/" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="base.dir" value="." />
 
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>
   </path>
 
   <target name="run">
       <javac srcdir="${base.dir}" destdir="${base.dir}"  includes="TestMBeanServiceMonitor.java" classpathref="jboss.classpath"/>
       <java classname="TestMBeanServiceMonitor">
           <classpath>
              <pathelement location="${base.dir}"/>
              <path refid="jboss.classpath"/>
           </classpath>
           <arg line="localhost 1090"/>
       </java>
   </target>
</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

NOTE: Also Make sure that you are writing the correct HostName and Port in the above ant script of your JBoss AS7 here arg line=”localhost 1090″

Step5). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/apache-ant-1.8.2/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/apache-ant-1.8.2/bin;%PATH%

Step7). Run the command “ant” or “ant run” which will internally build/compile and run our MBean Code

[userone@localhost Monitoring]$ ant
Buildfile: /home/userone/jboss-as-7.1.0.CR1b/standalone/MBeanDemo/build.xml

run:
    [javac] /home/userone/jboss-as-7.1.0.CR1b/standalone/MBeanDemo/build.xml:13: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
      GOT THE MBeanServerConnection---SUCCESSFULLY
      
      	 All JBoss AS7 MBean Listing 
      
      
      	 ObjectName : jboss.as:core-service=server-environment
      	 ObjectName : jboss.as:extension=org.jboss.as.web
      	 ObjectName : jboss.as:extension=org.jboss.as.remoting
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,remote-destination-outbound-socket-binding=mail-smtp
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=jacorb-ssl
      	 ObjectName : jboss.as:subsystem=ejb3,cache=simple
      	 ObjectName : jboss.as:core-service=management,management-interface=native-interface
      	 ObjectName : jboss.as:deployment=EE6_BeanValidationDemo.war
      	 ObjectName : jboss.as:subsystem=security,security-domain=jboss-web-policy,authorization=classic
      	 ObjectName : jboss.as:extension=org.jboss.as.weld
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.aries.util
      	 ObjectName : jboss.as:subsystem=naming
      	 ObjectName : jboss.as:extension=org.jboss.as.connector
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,security-setting=#,role=guest
      	 ObjectName : jboss.as:subsystem=jca,workmanager=default
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate
      	 ObjectName : jboss.as:subsystem=logging,logger=org.apache.tomcat.util.modeler
      	 ObjectName : java.lang:type=MemoryPool,name=Code Cache
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,connection-factory=RemoteConnectionFactory
      	 ObjectName : jboss.as:deployment=Log4jDemo.war
      	 ObjectName : jboss.as:subsystem=ee
      	 ObjectName : jboss.as:subsystem=ejb3,thread-pool=default
      	 ObjectName : jboss.as:subsystem=webservices,endpoint-config=Standard-Endpoint-Config
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=entity
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=jacorb
      	 ObjectName : jboss.as:subsystem=datasources,data-source=H2DS
      	 ObjectName : jboss.as:subsystem=ejb3,service=async
      	 ObjectName : jboss.as:subsystem=jca,bean-validation=bean-validation
      	 ObjectName : jboss.as:subsystem=security,security-domain=jboss-ejb-policy
      	 ObjectName : jboss.as:extension=org.jboss.as.jpa
      	 ObjectName : java.lang:type=MemoryPool,name=PS Eden Space
      	 ObjectName : java.lang:type=Memory
      	 ObjectName : jboss.as:deployment=MyDemoMDB.jar
      	 ObjectName : jboss.as:subsystem=logging,console-handler=CONSOLE
      	 ObjectName : jboss.as:subsystem=ejb3,cache=passivating
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=jmx-connector-server
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=remoting
      	 ObjectName : jboss.as:extension=org.jboss.as.security
      	 ObjectName : jboss.as:extension=org.jboss.as.ejb3
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.aries.jmx
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.xerces
      	 ObjectName : jboss.as:extension=org.jboss.as.transactions
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-connector=netty-throughput,param=batch-delay
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets
      	 ObjectName : jboss.as:subsystem=deployment-scanner
      	 ObjectName : jboss.as:deployment=MyDemoMDB.jar,subsystem=ejb3,message-driven-bean=MyMDB
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,pooled-connection-factory=hornetq-ra
      	 ObjectName : jboss.as:extension=org.jboss.as.logging
      	 ObjectName : jboss.as:subsystem=jaxrs
      	 ObjectName : jboss.modules:type=ModuleLoader,name=LocalModuleLoader-3
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=management-native
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default
      	 ObjectName : jboss.as:subsystem=jca,archive-validation=archive-validation
      	 ObjectName : jboss.jsr77:j2eeType=JVM,name=default,J2EEServer=default
      	 ObjectName : jboss.as:deployment=TestWebApp.war,subsystem=web,servlet=servlets.TestServlet
      	 ObjectName : jboss.jta:type=ObjectStore
      	 ObjectName : java.lang:type=MemoryPool,name=PS Survivor Space
      	 ObjectName : jboss.as:extension=org.jboss.as.ee
      	 ObjectName : jboss.as:subsystem=logging,periodic-rotating-file-handler=FILE
      	 ObjectName : jboss.modules:type=ModuleLoader,name=ModuleLoaderIntegration-7
      	 ObjectName : jboss.as:subsystem=web,connector=http
      	 ObjectName : java.lang:type=Compilation
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,core-address=jms.topic.testTopic
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.webconsole
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,core-address=jms.queue.testQueue
      	 ObjectName : jboss.as:subsystem=osgi,configuration=org.apache.felix.webconsole.internal.servlet.OsgiManager
      	 ObjectName : jboss.as:subsystem=deployment-scanner,scanner=default
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,jms-queue=testQueue
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.as.osgi.configadmin
      	 ObjectName : jboss.modules:type=ModuleLoader,name=ServiceModuleLoader-5
      	 ObjectName : jboss.as:subsystem=jca,bootstrap-context=default
      	 ObjectName : jboss.as:subsystem=mail
      	 ObjectName : java.lang:type=Runtime
      	 ObjectName : jboss.as:deployment=TestWebApp.war
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.netty
      	 ObjectName : jboss.as:deployment=EE6_BeanValidationDemo.war,subsystem=web,servlet=Faces_Servlet
      	 ObjectName : jboss.as:subsystem=pojo
      	 ObjectName : jboss.as:extension=org.jboss.as.messaging
      	 ObjectName : jboss.ws:service=ServerConfig
      	 ObjectName : jboss.as:management-root=server
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-acceptor=netty-throughput,param=batch-delay
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=timestamps,singleton=eviction
      	 ObjectName : jboss.as:subsystem=jca,workmanager=default,long-running-threads=default-long-running-threads
      	 ObjectName : jboss.as:subsystem=jca,cached-connection-manager=cached-connection-manager
      	 ObjectName : jboss.as:subsystem=ejb3,service=iiop
      	 ObjectName : jboss.as:extension=org.jboss.as.pojo
      	 ObjectName : jboss.as:subsystem=osgi,capability=javax.transaction.api
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.eventadmin
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.osgi.compendium
      	 ObjectName : jboss.jsr77:j2eeType=WebModule,name=TestWebApp.war,J2EEServer=default
      	 ObjectName : jboss.as:subsystem=threads
      	 ObjectName : jboss.jsr77:j2eeType=WebModule,name=Log4jDemo.war,J2EEServer=default
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.configadmin
      	 ObjectName : jboss.as:extension=org.jboss.as.sar
      	 ObjectName : jboss.jsr77:j2eeType=WebModule,name=EE6_BeanValidationDemo.war,J2EEServer=default
      	 ObjectName : java.util.logging:type=Logging
      	 ObjectName : jboss.as:extension=org.jboss.as.mail
      	 ObjectName : jboss.msc:type=container,name=jboss-as
      	 ObjectName : jboss.as:subsystem=infinispan
      	 ObjectName : com.sun.management:type=HotSpotDiagnostic
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-connector=netty-throughput
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=local-query
      	 ObjectName : java.lang:type=GarbageCollector,name=PS Scavenge
      	 ObjectName : jboss.as:subsystem=ejb3,strict-max-bean-instance-pool=mdb-strict-max-pool
      	 ObjectName : jboss.as:extension=org.jboss.as.jsr77
      	 ObjectName : jboss.as:subsystem=transactions
      	 ObjectName : jboss.as:extension=org.jboss.as.jdr
      	 ObjectName : jboss.as:subsystem=security,security-domain=other,authentication=classic
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=messaging
      	 ObjectName : jboss.as:subsystem=security,security-domain=other
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-acceptor=netty-throughput
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.projectodd.stilts
      	 ObjectName : jboss.as:subsystem=ejb3,strict-max-bean-instance-pool=slsb-strict-max-pool
      	 ObjectName : jboss.as:subsystem=webservices,endpoint-config=Recording-Endpoint-Config
      	 ObjectName : jboss.as:core-service=management,security-realm=ManagementRealm,authentication=properties
      	 ObjectName : jboss.as:deployment=BeanValidation_EJB_Demo.ear
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,security-setting=#
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,in-vm-acceptor=in-vm
      	 ObjectName : jboss.as:subsystem=osgi,capability=javax.servlet.api
      	 ObjectName : jboss.as:subsystem=security,security-domain=jboss-ejb-policy,authorization=classic
      	 ObjectName : jboss.as:deployment=BeanValidation_EJB_Demo.ear,subdeployment=localEJB.jar,subsystem=ejb3,stateless-session-bean=CallerName
      	 ObjectName : jboss.as:subsystem=cmp
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=entity,singleton=eviction
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=txn-recovery-environment
      	 ObjectName : jboss.as:extension=org.jboss.as.jaxrs
      	 ObjectName : jboss.as:subsystem=ejb3,service=timer-service
      	 ObjectName : jboss.as:extension=org.jboss.as.webservices
      	 ObjectName : java.lang:type=MemoryPool,name=PS Perm Gen
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=local-query,singleton=expiration
      	 ObjectName : jboss.as:subsystem=webservices
      	 ObjectName : jboss.as:subsystem=jpa
      	 ObjectName : jboss.as:core-service=management
      	 ObjectName : jboss.as:subsystem=logging,logger=jacorb
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.http
      	 ObjectName : java.lang:type=MemoryPool,name=PS Old Gen
      	 ObjectName : jboss.as:subsystem=web,configuration=jsp-configuration
      	 ObjectName : jboss.as:subsystem=web,configuration=static-resources
      	 ObjectName : jboss.as:subsystem=sar
      	 ObjectName : jboss.as:core-service=management,security-realm=ManagementRealm
      	 ObjectName : java.lang:type=GarbageCollector,name=PS MarkSweep
      	 ObjectName : jboss.as:subsystem=jca,workmanager=default,short-running-threads=default-short-running-threads
      	 ObjectName : jboss.as:deployment=BeanValidation_EJB_Demo.ear,subdeployment=localEJB.jar
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=txn-status-manager
      	 ObjectName : jboss.as:deployment=EE6_BeanValidationDemo.war,subsystem=web
      	 ObjectName : jboss.as:subsystem=osgi,property=org.osgi.framework.startlevel.beginning
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,in-vm-connector=in-vm
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,address-setting=#
      	 ObjectName : jboss.as:subsystem=ejb3
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.metatype
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.scr
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.log
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.blueprint
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-acceptor=netty
      	 ObjectName : jboss.as:subsystem=logging
      	 ObjectName : jboss.as:subsystem=jca
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=osgi-http
      	 ObjectName : jboss.as:subsystem=datasources
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.webapp
      	 ObjectName : jboss.jsr77:j2eeType=J2EEDomain,name=jboss.jsr77
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=jmx-connector-registry
      	 ObjectName : jboss.as:subsystem=security
      	 ObjectName : jboss.as:subsystem=jdr
      	 ObjectName : java.lang:type=ClassLoading
      	 ObjectName : jboss.as:subsystem=datasources,jdbc-driver=h2
      	 ObjectName : java.lang:type=Threading
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.logging
      	 ObjectName : jboss.as:subsystem=security,security-domain=jboss-web-policy
      	 ObjectName : jboss.as:subsystem=jmx
      	 ObjectName : jboss.as:subsystem=logging,logger=sun.rmi
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,jms-topic=testTopic
      	 ObjectName : jboss.as:subsystem=ejb3,file-passivation-store=file
      	 ObjectName : jboss.as:deployment=Log4jDemo.war,subsystem=web,servlet=servlets.TestServlet
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=messaging-throughput
      	 ObjectName : jboss.as:subsystem=resource-adapters
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=management-http
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=https
      	 ObjectName : jboss.as:subsystem=jacorb
      	 ObjectName : jboss.as:core-service=service-container
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-acceptor=netty-throughput,param=direct-deliver
      	 ObjectName : jboss.as:extension=org.jboss.as.osgi
      	 ObjectName : jboss.jsr77:j2eeType=J2EEApplication,name=BeanValidation_EJB_Demo.ear,J2EEServer=default
      	 ObjectName : jboss.as:subsystem=remoting,connector=remoting-connector
      	 ObjectName : jboss.as:interface=public
      	 ObjectName : jboss.as:interface=management
      	 ObjectName : jboss.as:extension=org.jboss.as.jacorb
      	 ObjectName : java.lang:type=MemoryManager,name=CodeCacheManager
      	 ObjectName : jboss.as:extension=org.jboss.as.clustering.infinispan
      	 ObjectName : jboss.as:subsystem=ejb3,service=remote
      	 ObjectName : jboss.as:subsystem=weld
      	 ObjectName : jboss.as:deployment=Log4jDemo.war,subsystem=web
      	 ObjectName : jboss.jsr77:j2eeType=J2EEServer,name=default
      	 ObjectName : jboss.as:subsystem=logging,logger=com.arjuna
      	 ObjectName : jboss.as:subsystem=logging,root-logger=ROOT
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.apache.felix.webconsole
      	 ObjectName : jboss.as:deployment=MyDemoMDB.jar,subsystem=ejb3
      	 ObjectName : jboss.as:extension=org.jboss.as.cmp
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=local-query,singleton=eviction
      	 ObjectName : jboss.as:subsystem=remoting
      	 ObjectName : jboss.as:subsystem=logging,logger=jacorb.config
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=entity,singleton=expiration
      	 ObjectName : jboss.as:subsystem=web,virtual-server=default-host
      	 ObjectName : jboss.as:extension=org.jboss.as.deployment-scanner
      	 ObjectName : jboss.as:deployment=BeanValidation_EJB_Demo.ear,subdeployment=localEJB.jar,subsystem=ejb3
      	 ObjectName : jboss.as:extension=org.jboss.as.threads
      	 ObjectName : jboss.as:core-service=management,management-interface=http-interface
      	 ObjectName : jboss.as:extension=org.jboss.as.naming
      	 ObjectName : java.lang:type=OperatingSystem
      	 ObjectName : jboss.as:subsystem=osgi
      	 ObjectName : jboss.as:extension=org.jboss.as.jmx
      	 ObjectName : jboss.as:subsystem=messaging
      	 ObjectName : jboss.as:subsystem=osgi,capability=org.jboss.osgi.jmx
      	 ObjectName : jboss.as:subsystem=infinispan,cache-container=hibernate,local-cache=timestamps
      	 ObjectName : jboss.as:deployment=TestWebApp.war,subsystem=web
      	 ObjectName : jboss.as:subsystem=osgi,capability=javax.api
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,connection-factory=InVmConnectionFactory
      	 ObjectName : jboss.as:socket-binding-group=standard-sockets,socket-binding=http
      	 ObjectName : jboss.as:subsystem=messaging,hornetq-server=default,remote-connector=netty
      	 ObjectName : jboss.as:subsystem=web
      	 ObjectName : jboss.as:subsystem=mail,mail-session=java%x3ajboss/mail/Default
      	 ObjectName : jboss.as:subsystem=jsr77
      	 ObjectName : jboss.as:subsystem=jmx,connector=jmx
      	 ObjectName : jboss.as:subsystem=web,configuration=container

BUILD SUCCESSFUL
Total time: 0 seconds

So like this we got all the list of MBean ObjectName present inside JBoss AS7.
.
.
Thanks 🙂
MiddlewareMagic Team


Getting WebService Statistics using JMX in JBoss AS7

Hi,

In this demonstration we will see how we can query the Statistics of a WebService deployed on JBoss using standard MBean code. In this example we will see that we need not to add any JAVA_OPTS in our JBoss configuration files in order to access these MBeans.

Here we will use a Sample webservice which will be deployed on JBoss AS7, for example you can refer to the following article to know how to deploy the WebService in JBoss: “http://middlewaremagic.com/jboss/?p=980” We will try to access the statistics of this webservice using our Standard JMX code. The statistics will include the following useful informations: “StartTime”, “StopTime”, “MinProcessingTime”, “AverageProcessingTime”, “MaxProcessingTime”, “RequestCount”..etc

JBoss side Configuration ( jboss-as-7.1.0.Beta1 )

Step1). Open the “/home/userone/jboss-as-7.1.0.Beta1/standalone/configuration/standalone-full.xml” file and edit the subsystem “urn:jboss:domain:jmx:1.1” as following:

        <subsystem xmlns="urn:jboss:domain:jmx:1.1" show-model="true">
            <jmx-connector registry-binding="jmx-connector-registry" server-binding="jmx-connector-server"/>
        </subsystem>

Step2). Restart your JBoss Profile from “/home/userone/jboss-as-7.1.0.Beta1/bin” directory like following:

[userone@localhost bin]$ ./standalone.sh -c standalone-full.xml

Step3). Deploy your WebService on JBoss. For Testing you can use the webService mentioned in the following link:
http://middlewaremagic.com/jboss/?p=980

Step4). Now Somewhere in your filesystem write a Java Program “WebServiceMonitor.java” as following:

import java.util.Date;
import java.util.Hashtable;
import java.io.IOException;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import java.lang.management.MemoryMXBean;
import java.lang.management.ManagementFactory;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import javax.management.*;
import javax.management.openmbean.CompositeDataSupport;
 
public class WebServiceMonitor
{
    private static MBeanServerConnection connection;
    private static JMXConnector connector;
    public static void Connection(String hostname, String port) throws IOException
    {
        Integer portInteger = Integer.valueOf(port);
        Hashtable h = new Hashtable();
        JMXServiceURL address = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://"+hostname+":"+port+"/jmxrmi");
        connector = JMXConnectorFactory.connect(address,null);
        connection = connector.getMBeanServerConnection();
        System.out.println("GOT THE MBeanServerConnection---SUCCESSFULLY");
    }
 
    private static void getServiceDetail(String contextRoot,String endPointName) throws Exception
    {
        ObjectName serviceRef=new ObjectName("jboss.ws:context="+contextRoot+",endpoint="+endPointName);
        String address=(String)connection.getAttribute(serviceRef, "Address");
        System.out.println("t Address : "+address);
        Date startTime=(Date)connection.getAttribute(serviceRef, "StartTime");
        System.out.println("t StartTime : "+startTime);
        Long minProcessingTime=(Long)connection.getAttribute(serviceRef, "MinProcessingTime");
        System.out.println("t MinProcessingTime : "+minProcessingTime);
        Long maxProcessingTime=(Long)connection.getAttribute(serviceRef, "MaxProcessingTime");
        System.out.println("t MaxProcessingTime : "+maxProcessingTime);
        Long totalProcessingTime=(Long)connection.getAttribute(serviceRef, "TotalProcessingTime");
        System.out.println("t TotalProcessingTime : "+totalProcessingTime);
        Long requestCount=(Long)connection.getAttribute(serviceRef, "RequestCount");
        System.out.println("t RequestCount : "+requestCount);
        Long responseCount=(Long)connection.getAttribute(serviceRef, "ResponseCount");
        System.out.println("t ResponseCount : "+responseCount);
        Long faultCount=(Long)connection.getAttribute(serviceRef, "FaultCount");
        System.out.println("t FaultCount : "+faultCount);
        Date stopTime=(Date)connection.getAttribute(serviceRef, "StopTime");
        System.out.println("t StopTime : "+stopTime);
        Long averageProcessingTime=(Long)connection.getAttribute(serviceRef, "AverageProcessingTime");
        System.out.println("t AverageProcessingTime : "+averageProcessingTime);
    }
 
    public static void main(String[] args) throws Exception
    {
    String hostname = args[0];
    String port = args[1];
    String contextRoot=args[2];
    String endPointName=args[3];
    Connection(hostname, port);
    System.out.println("------------------Getting Service Details------------------");
    System.out.println("jboss.ws:context=CXFTimeoutClientDemo,endpoint=Test_CXF_WS");
    System.out.println("-----------------------------------------------------------");
    getServiceDetail(contextRoot,endPointName);

    // ObjectName will be in the following format
    // "jboss.ws:context="+contextRoot+",endpoint="+endPointName
    //       Example:
    //       jboss.ws:context=CXFTimeoutClientDemo,endpoint=Test_CXF_WS
    }
}

Step5). Now we will write a simple Ant build script to build and execute the above program. So write an Ant build script “build.xml” file in the same directory where the above program is placed.

<project name="JBoss_Monitor" default="run">
<property name="jboss.home" value="/NotBackedUp/JBoss_All/jboss-as-7.1.0.Beta1" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="base.dir" value="." />
 
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>
     </fileset>  
   </path>

   <target name="run">
       <javac srcdir="${base.dir}" destdir="${base.dir}"  includes="WebServiceMonitor.java" classpathref="jboss.classpath"/>
       <java classname="WebServiceMonitor">
           <classpath>
              <pathelement location="${base.dir}"/>
              <path refid="jboss.classpath"/>
           </classpath>
           <arg line="localhost 1090  CXFTimeoutClientDemo Test_CXF_WS"/>
       </java>
   </target>  
</project>

NOTE: The only change in the above file you need to do is to change the “jboss.home” directory path in the second line of the above script is to point to your own JBoss AS7 directory home directory.

Step6). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step7). Run the command “ant” or “ant run” which will internally build the WebService and deploy it inside the JBoss AS7 standalone profile.

[userone@localhost Monitoring]$ ant run
Buildfile: /home/userone/Monitoring/build.xml

run:
      GOT THE MBeanServerConnection---SUCCESSFULLY
      ------------------Getting Service Details------------------
      jboss.ws:context=CXFTimeoutClientDemo,endpoint=Test_CXF_WS
      -----------------------------------------------------------
      	 Address : http://localhost:8080/CXFTimeoutClientDemo
      	 StartTime : Tue Nov 29 01:17:23 BTT 2011
      	 MinProcessingTime : 8
      	 MaxProcessingTime : 15191
      	 TotalProcessingTime : 15310
      	 RequestCount : 3
      	 ResponseCount : 3
      	 FaultCount : 0
      	 StopTime : null
      	 AverageProcessingTime : 5103

BUILD SUCCESSFUL
Total time: 2 seconds

Step8). If you want to run the above program manually then you will need to run the following command

.
java WebServiceMonitor localhost 1090 CXFTimeoutClientDemo Test_CXF_WS
.

NOTE: Here we are passing 4 Arguments
“localhost” (Here our JBoss is running),
“1090” (This is the jmx-connector-registry connector port of JBoss which is enabled in the step1),
“CXFTimeoutClientDemo” (This is the Context Root of our WebService Application)
“Test_CXF_WS” (This is the Endpoint Name of our WebService)
.
.
.
Thanks
MiddlewareMagic Team


Copyright © 2010-2012 Middleware Magic. All rights reserved. |