Lightweight Application Monitoring with Hawtio and JMX.

In my previous life developing solutions for a biometrics company, we invested quite a bit in monitoring tools to know the status and performance of the cluster of servers on which our application was deployed. The tool of choice was RHQ 4.x, and I must say it served us well in many places. But it came with it’s own complexity, and having discovered the simple but quite efficient HawtIO, I think I have a new permanent member of my arsenal for software delivery and monitoring.

Hawtio is a modular web console that enables you to monitor any JVM based application via JMX, with the use of the Jolokia, a tool for exposing JMX via JSON to enable REST like invocation of JMX beans. All you need to do to get Hawtio working on Jboss7/Wildfly is to follow the instructions here.

My main interest was in profiling the performance of Hibernate within my JavaEE application deployed in JBoss 7, and Markus Eisele’s post on using HawtIO to display Hibernate statistics was just on point. Basically you can follow his instructions and make the following modifications for Jboss7/Wildfly.

1. Include these 2 files from Makus’s post in your project StatisticsService and DelegatingStatisticsService
2. Add a @Singleton @Startup EJB which does the following

public class HibernateMBeanRegistrar {
    private static final Logger logger = LoggerFactory.getLogger(HibernateMBeanRegistrar.class);
    @javax.annotation.Resource(lookup = "java:jboss/MySessionFactory")
    private SessionFactory sessionFactory;
    public void register() {
        try {
            try {
                MBeanServer mbeanServer
                        = ManagementFactory.getPlatformMBeanServer();
                ObjectName on
                        = new ObjectName("Hibernate:type=statistics,application=hibernatestatistics");

                StatisticsService mBean = new DelegatingStatisticsService(sessionFactory.getStatistics());
                mbeanServer.registerMBean(mBean, on);
      "Hibernate Statistics MBean registered successfully ...");
            } catch (MalformedObjectNameException ex) {
                logger.error("", ex);
            } catch (InstanceAlreadyExistsException ex) {
                logger.error("", ex);
            } catch (MBeanRegistrationException ex) {
                logger.error("", ex);
            } catch (NotCompliantMBeanException ex) {
                logger.error("", ex);
        } catch (Exception e) {
            logger.error("Failure obtaining SessionFactory from EMF: "+e.getLocalizedMessage());


3. Add these to your persistence.xml

<property name="hibernate.generate_statistics" value="true"/>
<property name="hibernate.session_factory_name" value="java:jboss/MySessionFactory" /> 

4. Deploy your application alongside the hawtio-no-slf4j-x.x.x.war as stated in the instructions on installing hawtio for JBoss7/Wildfly. I renamed the file to hawtio to make life easier.
5. Once both hawtio and your application are deployed, navigate to http://localhost:8080/hawtio. Click on JMX and you should see a Hibernate–>statistics–>hibernatestatistics node. Clicking on that node should show you something like Markus’s view here. You can even add it to the dasboard if you wish so you get up to the minute figures as your application runs.


HIbernate Statistics

For me it did show that although my entities were being cached in the 2nd level cache, it seemed somehow that query caching was not working. So I’ve got work to do.

Hawtio does have a lot of plugins to display content from other sources, from Elasticsearch to log files. You should definitely give it a shot. Thanks Markus for the Hawtio intro.


Copying a subset of files from a directory on CentOS

I had a huge number xml files (somewhere close to 100k files) and i needed to copy just a 1000 of them for a few tests on CentOS. I wasn’t interested in the order of the files, simply just any 1000 will do.

After trolling all over the internet, if found this simple solution.

 find $targetDir -maxdepth 1 -type f |head -1000|xargs cp -t $destDir

Where $targetDir was the path to the folder containing the large set of files, and $destDir is the folder in which i wanted to copy the 1000 files into.

Sweet and simple. Gleaned from here

JUG Accra Goes Live

In an effort to promote and share knowledge on Java platform technologies and tools in Ghana, a Java User Groups is being started by Java enthusiasts in the capital Accra.

JAccra wishes to promote and strengthen the Ghanaian base of expertise and proficiency in the plethora of Java platform tools and technologies.

As part of it’s start up process, JAccra is scheduled to have its first meeting on Saturday 7th March, and the details are provided below. This meeting will focus on deliberations by members of JAccra on the vision and objectives of JAccra and how those will be achieved.

If you are a Java enthusiast based in Accra, you can’t afford to miss this gathering. To register to join jaccra, just click here. Welcome to Java’s hotbed in Accra.

  • Venue: Meltwater Entrepeneural School of Technology, East Legon, Close to A &C Shopping Mall.
  • Date: Saturday 7th March, 2009
  • Time: 11am – 1pm.

Tweaking JBoss Tools and Eclipse for Tomcat 6

Since I’d been using Eclipse for a while now, I decided to give the JBoss Tools 2.0.1.GA a spin, with a focus on using it with Tomcat 6 instead of JBoss AS. JBoss Tools is a set of plugins released by the JBoss team for rapid Seam application development. However, by default it supports development to the JBoss Application Server, although Seam applications can be deployed to most application servers.

I followed the instructions detailed in the new Chapter 3 of the Seam Reference Manual in Seam 2.0.2.GA, making sure that I rather specified my installed Tomcat 6 instead of JBAS and also specified a WAR instead of EAR structure. After the project structure is created, there are a few changes that need to be made to make things nice and easy.

To make sure that we all have the same view of the project structure, open the Seam perspective.

Tomcat enables us to put resources that are needed in each application (like datasources) in a META-INF/context.xml. Here is what mine looks like.

<?xml version="1.o" encoding="UTF-8"?>

<Context crossContext="true" debug="5" docBase="seamweb" path="/seamweb" reloadable="true">

<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/seamweb" password="" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/seamweb" username="edem"/>


In Eclipse, this file should go into the WebContent/META-INF folder.

Next is to work on the persitence.xml file which will be found under src/model/META-INF. Change the following line in that file which looks like this


to this


This is the standard way of declaring JNDI names, and Tomcat expects that. Also, change the “transaction-type” from “JTA” to “RESOURCE_LOCAL”.

Next thing to deal with is the components.xml file under WebContent/WEB-INF/. Remove the jndi-pattern = “@jndiPattern” attribute since we are not using EJBs here. Your file should now look like this.

<core:init debug="true"/>

<core:manager conversation-timeout="240000" concurrent-request-timeout="500" conversation-id-parameter="cid"/>

<transaction:entity-transaction entity-manager="#{entityManager}"/>

<persistence:entity-manager-factory name="seamweb"/>

<persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{seamweb}"/>

<security:identity authenticate-method="#{authenticator.authenticate}"/>

<event type="org.jboss.seam.notLoggedIn">
<action execute="#{redirect.captureCurrentView}"/>


<event type="org.jboss.seam.postAuthenticate">
<action execute="#{redirect.returnToCapturedView}"/>


Take note of “seamweb” declarations. Its the same as the persistence-unit name provided in the persitence.xml file.

Now delete the WebContent/WEB-INF/jboss-web.xml file. It’s definitely not necessary to tomcat.

The last but most important part of this exercise is making sure you have the right jar files in WEB/lib. After creating the project, JBoss Tools copies all the jar files from seam’s lib folder into your web application. The only way to know the jars needed for tomcat deployment only is to jpa example in seam distribution you have. Follow the instructions on my post about setting up NetBeans 6.0 for Tomcat 6 and you’ll see how i did it.

But to save you that trouble, this list of jars seem to work for me

  1. antlr.jar

  2. asm.jar
  3. cglib.jar

  4. commons-beanutils.jar

  5. common-collections.jar

  6. commons-digester.jar

  7. commons-lang.jar

  8. commons-logging.jar

  9. dom4j.jar

  10. hibernate-annotations.jar

  11. hibernate-commons-annotations.jar

  12. hibernate-entitymanager.jar

  13. hibernate.jar

  14. hibernate-validator.jar

  15. javassist.jar

  16. jbos-archive-browsing.jar

  17. jboss-el.jar

  18. jboss-seam-debug.jar

  19. jboss-seam.jar

  20. jboss-seam-ui.jar

  21. jsf-api.jar

  22. jsf-facelets.jar

  23. jsf-impl.jar

  24. jstl.jar

  25. jta.jar

  26. persistence-api.jar

  27. richfaces-api.jar

  28. richfaces-impl.jar

  29. richfaces-ui.jar

If everything went well, the application should run inside tomcat without a problem.