Published on October 17, 2016 by Lars Fischer
Many software projects are constructed out of numerous components, which can sometimes be hard to monitor. Especially during the development phase of an application, it can be crucial to gain information about possible bottle necks that may prevent successful production usage of your project very early on. One possible performance metric may be the amount of (possibly unnecessary) SQL statements executed while using your application - this is a real use case I had in a large Magnolia project to increase performance.
JavaMelody is an open source project providing tools and a UI to monitor Java applications.
It is not used to simulate load on your system but to provide statistics and logs for analyzing Java applications in production and during the QA phase.
To be able to monitor SQL statements, as in the scenario mentioned above, please refer to the previous blog post about how to setup a JNDI based data source in Tomcat.
Because Magnolia projects are Maven based, we include the needed library in the POM of our Magnolia webapp and also add the JRobin library for managing the created RRD log files.
<!-- https://mvnrepository.com/artifact/net.bull.javamelody/javamelody-core --> <dependency> <groupId>net.bull.javamelody</groupId> <artifactId>javamelody-core</artifactId> <version>1.61.0</version> </dependency> <!-- https://mvnrepository.com/artifact/org.jrobin/jrobin --> <dependency> <groupId>org.jrobin</groupId> <artifactId>jrobin</artifactId> <version>1.5.9</version> </dependency>
To provide the most basic configuration, add the following configuration to web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <description>Magnolia</description> <display-name>magnolia</display-name> <distributable /> <filter> <filter-name>javamelody</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> </filter> <filter-mapping> <filter-name>javamelody</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>net.bull.javamelody.SessionListener</listener-class> </listener> <filter> <display-name>Magnolia global filters</display-name> <filter-name>magnoliaFilterChain</filter-name> <filter-class>info.magnolia.cms.filters.MgnlMainFilter</filter-class> </filter> … more configuration … </web-app>
Please note that I used javamelody as the name for the filter and not monitoring as in most of the examples provided on the web. This is because some of the options shown below will not work if you are going to use Java 8 with your project (which is nowadays very common).
See this issue on GitHub for more information about this problem.
With this configuration, you've already configured JavaMelody to be available with your Magnolia project. After starting your Magnolia instance, go to
to access the JavaMelody UI on your server. The name "monitoring" is the default name for accessing the JavaMelody web interface.
This blog entry written by Siegfried Goeschl provides a nice introduction on how to configure some of the options for usage of JavaMelody within your Java based web application.
Check the refined filter configuraton below:
<filter> <filter-name>javamelody</filter-name> <filter-class>net.bull.javamelody.MonitoringFilter</filter-class> <init-param> <param-name>authorized-users</param-name> <param-value>superuser:superuser</param-value> </init-param> <init-param> <param-name>monitoring-path</param-name> <param-value>/mypath/javamelody</param-value> </init-param> <init-param> <param-name>storage-directory</param-name> <param-value>/Users/exampleuser/temp/javamelody</param-value> </init-param> </filter>
The extended filter configuration shows you how to
Please consult the official project documentation on GitHub for more information on how to configure JavaMelody.
By adding this tool to your Magnolia project, you can quickly gain a tool for monitoring and for gaining statistics about the overall performance of your application.
The screenshot below shows an example of SQL statements executed against the JCR repository while using Magnolia CMS AdminCentral. This is only one of many useful reports you get automatically when integrating JavaMelody into your Magnolia or Java web application.
By including just a few lines of configuration, we were able to gain important performance metrics about our Java based application.
Lars Fischer is an IT professional with more than 15 years of experience covering a wide range of project and technology know how. His main focuses in the last decade have been: enterprise level architecture and development, integration projects; content management and project lead and management. Since 2012, he has been working as a Senior Solution Architect within the Professional Services team at Magnolia, Basel. There he designs and develops solutions and architectures for large scale and mission critical customer projects. He has also acted as principal advisor for websites like Roche.com, the University of Zürich, Generali Switzerland, the Land Rover / Jaguar Club and the Canton of Basel Stadt. You can find more information on his personal website at http://lars-fischer.me.
See all posts on Lars Fischer