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

Saturday, January 24, 2015

Openfire3.9.1 JMX | Openfire 3.9.1 - Enable Secure/Non-Secure JMX

Openfire System Properties for JMX

First, you need to add the following to System Properties via the Web Admin Console or add into the table ofproperty.
xmpp.jmx.enabled true
xmpp.jmx.port 9111
xmpp.jmx.secure false

Code Snippet

To test it, use the code snippet:
String serverUrl = "service:jmx:rmi:///jndi/rmi://localhost:9111/jmxrmi";

JMXServiceURL url = new JMXServiceURL(serverUrl);

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

MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

ObjectName objectName = new ObjectName("org.eclipse.jetty.webapp:type=webappcontext,id=0,name=ROOT");

Object response = mbsc.getAttribute(objectName, "started");

jmxc.close();
Open your own Online Store and Grow Your Sales! Try it Free Now with Bigcommerce!

Configure Username and Password for Secure JMX

You could tighten the security by change xmpp.jmx.secure to true. In this case, user name and password must be supplied during connection establishment.
String serverUrl = "service:jmx:rmi:///jndi/rmi://localhost:9111/jmxrmi";

JMXServiceURL url = new JMXServiceURL(serverUrl);

Map<String, String[]> map = Collections.singletonMap(JMXConnector.CREDENTIALS, new String[]{"admin", "password"});

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

MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

ObjectName webAppContext = new ObjectName("org.eclipse.jetty.webapp:type=webappcontext,id=0,name=ROOT");

Object response = mbsc.getAttribute(webAppContext, "started");

jmxc.close();

Configure JBoss for Enabling JMX RMI

If you deploy your application to JBoss AS 7.1.1, you also need to update $JBOSS_HOME/modules/sun/jdk/main/module.xml by adding the following:
to the "paths" section.


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

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!