Showing posts with label Remoting JMX. Show all posts
Showing posts with label Remoting JMX. Show all posts

Friday, January 23, 2015

JBoss7.1.1 Remoting JMX | JBoss AS 7.1.1 - Enable JMX

If you want to monitor if JBoss is running via JMX (Remoting JMX). This article is for you.

Update JBoss Configuration File for Remoting JMX

First, you need to add the following into $JBOSS_HOME/standalone/configuration/standalone.xml,
<server xmlns="urn:jboss:domain:1.2">
  <extensions>
    <extension module="org.jboss.as.jmx"/>
  </extensions>
  <profile>
    <subsystem xmlns="urn:jboss:domain:jmx:1.1">
      <show-model value="true"/>
      <remoting-connector/>
    </subsystem>
  </profile>
</server>
Then, run the server in the STANDALONE mode.

Dependent Jars for Maven or Normal Java Projects

Next, in your Maven project, add the following dependencies,
<dependency>
  <groupId>org.jboss.remotingjmx</groupId>
  <artifactId>remoting-jmx</artifactId>
  <version>1.0.2.Final</version>
</dependency>
<dependency>
  <groupId>org.jboss.marshalling</groupId>
  <artifactId>jboss-marshalling-river</artifactId>
  <version>1.3.11.GA</version>
</dependency>
<dependency>
  <groupId>org.jboss.sasl</groupId>
  <artifactId>jboss-sasl</artifactId>
  <version>1.0.0.Final</version>
</dependency>
<dependency>
  <groupId>org.jboss.xnio</groupId>
  <artifactId>xnio-nio</artifactId>
  <version>3.0.3.GA</version>
</dependency>
If the project is a basic Java project, add the following to the classpath:
remoting-jmx-1.0.2.Final.jar
jboss-logmanager-1.2.2.GA.jar
jboss-logging-3.1.0.GA.jar
jboss-marshalling-1.3.9.GA.jar
jboss-remoting-3.2.2.GA.jar
xnio-api-3.0.3.GA.jar
jboss-marshalling-river-1.3.11.GA.jar
jboss-sasl-1.0.0.Final.jar
xnio-nio-3.0.3.GA.jar
You can find the locations of these jars in $JBOSS_HOME/bin/jconsole.sh or jconsole.bat.

Keep in mind that JBoss does not use standard JMX and use its own remoting JMX instead. So make sure you have include the remoting jmx jars. The shortcoming for doing this is your project will depend on some JBoss jars.
AVG AntiVirus 2015

Code Snippet for JBoss Monitoring via JMX 

To test it, use the code snippet:
//the remoting JMX service URL; port 9999 is the default one.
String serverUrl = "service:jmx:remoting-jmx://localhost:9999";

JMXServiceURL url = new JMXServiceURL(serverUrl);

JMXConnector jmxc = JMXConnectorFactory.connect(url, null);

MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

//find the object to be monitored 
ObjectName objectName = new ObjectName("jboss.as:management-root=server");

//serverState has a couple of possible values, like running, starting, stopping and stopped.
Object response = mbsc.getAttribute(objectName, "serverState");

jmxc.close();


Create a Successful Online Store at Bigcommerce! Try it Free Now!