Posts Tagged Hibernate

How to monitor your Java application

It is very good to have your application and your database running on a Linux or Windows server, but who will tell you if your website is down? Who said “the users”? ๐Ÿ˜ฏ No, you won’t look very professional if you wait for a user complaint.

What you need to do is to monitor your server. But which tools to use? There are so many on the market… ๐Ÿ™

I tested a few of them (Hyperic, Nagios, Zenoss, Cacti, Monitis) but the one I choose is Zabbix. What I like with Zabbix is its price (free ๐Ÿ˜Ž ) and the fact that it is easy to configure and very flexible. Indeed, you can monitor anything you want on the machine (CPU, network, disk space, services, etc)! ๐Ÿ™‚

However, if you also want to monitor your Tomcat application server or even Hibernate Java library, you need some more work.

To monitor Tomcat, you first need to enable JMX Remote. To do so, you can have a look at the official documentation or simply add the following parameters to your Tomcat startup script:

export CATALINA_OPTS='-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false'

Then, I will recommend you to deploy Zapcat JMX Zabbix Bridge in your Tomcat web server. This tool has been developed to simplify the communication between the JMX management API inside Java applications and the Zabbix monitoring tool.

To read the installation instructions for Tomcat, please click on the following link:
http://www.kjkoster.org/zapcat/Tomcat_How_To.html

Finally, if you are using Hibernate in your Java application and would like to monitor it, you have to instantiate and configure a Hibernate MBean (org.jboss.hibernate.jmx.Hibernate) that will be responsible for constructing a Hibernate SessionFactory and exposing it to your application through JNDI.

Here are the lines you need to add to your context XML file:

<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
    <property name="server" ref="mbeanServerFactory"/>
    <property name="beans">
        <map>
            <entry key="org.hibernate:type=statistics"  value-ref="hibernateMBean"/>
        </map>
    </property>
</bean>

<bean id="mbeanServerFactory" class="org.springframework.jmx.support.MBeanServerFactoryBean">
    <property name="locateExistingServerIfPossible" value="true"/>
</bean>

<bean id="hibernateMBean" class="org.hibernate.jmx.StatisticsService">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="statisticsEnabled" value="true"/>
</bean>

, , , , , , ,

No Comments