2
votes

I'm trying to configure JMX with JBoss EAP 6.1, for this I've added jmx-console.war in my JBoss and put jboss-service.xml in my application. I'm trying to load a properties file and want to get it registered with JMX. JMX is showing all system beans but not loading my application's bean. This thing was working in AS version of JBoss. Is there some other way of configuring JMX with JBoss EAP? I've googled with all the combination but not finding any suitable answer. My jboss-service.xml looks like this:

   <?xml version="1.0" encoding="UTF-8"?>

<!-- ===================================================================== -->
<!-- JBoss Server Configuration -->
<!-- ===================================================================== -->

<server>
    <mbean code="com.asd.store.util.mbean.SystemConfig"
        name="com.asd.store.util.mbean:service=jmx-common">
        <constructor>
            <arg type="java.lang.String" value="store-properties.xml"/>
            <arg type="java.lang.String" value="${jboss.server.home.dir}/conf"/>
        </constructor>
    </mbean>
</server>
1

1 Answers

1
votes

JBoss AS 7.x does that slightly differently.

Here's a nice article on 'How to create SAR on JBoss AS7': http://middlewaremagic.com/jboss/?p=366

You can see JBoss and your MBeans by using jconsole, e.g. JBOSS_HOME/bin/jconsole.sh and see MBeans tab. I guess your jmx-console.war would work too.

It seems your MBeans did not get instantiated and registered properly by your application.

There are few ways to register your MBeans, see the article above for one possible way.

Here is another way that you can create and register your MBean using @Singleton, @Startup EJB bean: - make your MBean @Singleton, @Startup EJB - register your MBean in @PostConstruct lifecycle method - unregister you MBean in your @PreDestroy lifecycle method

Here's an example MBean that tracks current number of users, maximum number of users, performance, etc...

MBean interface, e.g. MonitoringResourceMXBean.java:

package examples.mymonitoring;

public interface MonitoringResourceMXBean {

    // current user count
    long getCurrentUsers();
    void countUserUp();
    void countUserDown();

    // maximum user count
    long getMaximumUsers();
    void setMaximumUsers(long max);

    // request count
    long getRequests();
    long countRequest();

    // maximum duration of request
    long getMaximumWait();
    void reportWait(long wait);

}

MBean implementation, e.g.

package examples.mymonitoring;

import java.lang.management.ManagementFactory;
import java.util.concurrent.atomic.AtomicLong;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.management.MBeanServer;
import javax.management.ObjectName;

@Singleton
@Startup
public class MonitoringResource implements MonitoringResourceMXBean {

    private MBeanServer platformMBeanServer;
    private ObjectName objectName = null; 

    private long maximumUsers = 100; 
    private AtomicLong requestCount = new AtomicLong(0);
    private AtomicLong currentUsers = new AtomicLong(0);
    private long maximumWait = 0;

    @PostConstruct
    public void registerInJMX() {
        try {
            objectName = new ObjectName("MyMonitoring:type=" + this.getClass().getName());
            platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
            platformMBeanServer.registerMBean(this, objectName);
        } catch (Exception e) {
            throw new IllegalStateException("Problem during registration of Monitoring into JMX:" + e);
        }
    }

    @PreDestroy
    public void unregisterFromJMX() {
        try {
            platformMBeanServer.unregisterMBean(this.objectName);
        } catch (Exception e) {
            throw new IllegalStateException("Problem during unregistration of Monitoring into JMX:" + e);
        }
    }

    @Override
    public long getCurrentUsers() {
        return this.currentUsers.get();
    }

    @Override
    public void countUserUp() {
        this.currentUsers.incrementAndGet();
    }

    @Override
    public void countUserDown() {
        this.currentUsers.decrementAndGet();
    }

    @Override
    public long getMaximumWait() {
        return this.maximumWait;
    }

    @Override
    public long getMaximumUsers() {
        return this.maximumUsers;
    }

    @Override
    public void setMaximumUsers(long max) {
        this.maximumUsers = max;
    }

    @Override
    public void reportWait(long wait) {
        if ( wait > maximumWait ) maximumWait = wait;
    }

    @Override
    public long getRequests() {
        return this.requestCount.get();
    }

    @Override
    public long countRequest() {
    return this.requestCount.incrementAndGet(); 
    }

}

Hope the example helps.

Cheers!