The need for monitoring
Many software projects are constructed out of many components which sometimes can 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.
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.
Monitor your Magnolia instance by including JavaMelody
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 like in the scenario mentioned above, please refer to the previous blog post about how to setup a JNDI based data source in Tomcat.
Magnolia project setup
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.
Magnolia webapp POM
<!-- 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>
Basic web.xml setup
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 name for the filter and not monitoring like 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 you’re project - which is nowadays very common.
See this issue on GitHub for more information about this problem.
With this configuration, you already have 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.
Setup with advanced configuration options
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
- add credentials for basic authentication
- modify the path where JavaMelody can be accessed
- change the directory for storage of historical data
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.