Posts Tagged Zabbix

Monitor s3sync with Zabbix

s3sync is a ruby program that easily transfers directories between a local directory and an S3 bucket:prefix. It behaves somewhat, but not precisely, like the rsync program.

I am using this tool to automatically backup the important data from Debian servers to Amazon S3. I am not going to explain here how to install s3sync as it is not the purpose of this article. However, you can read this very useful article from John Eberly’s blog: How I automated my backups to Amazon S3 using s3sync.

If you followed the steps from John Eberly’s post, you should have an script and a crontab job which executes this script periodically.

From this point, here is what you need to do to monitor the success of the synchronisation with Zabbix:

  1. Add the following code at the end of your script:
    # print the exit code
    [ $RETVAL -eq 0 ] && echo "Synchronization succeed"
    [ $RETVAL -ne 0 ] && echo "Synchronization failed"
  2. Log the output of the cron script as follow:
    30 2 * * sun /path/to/ > /var/log/s3sync.log 2>&1
  3. On Zabbix, create a new item which will check the existence of the sentence “Synchronization failed” in the file /var/log/s3sync.log:

    Item key: vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed]
  4. Still on Zabbix, define a new trigger for the previously created item:

    Trigger expression: {Template_AmazonCloud_Debian:vfs.file.regmatch[/var/log/s3sync.log,Synchronization failed].last(0)}=1

With these few steps, you should now receive Zabbix alerts when a backup on S3 fails. ๐Ÿ™‚

, , , , , , , , ,

No Comments

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:


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:

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">
            <entry key="org.hibernate:type=statistics"  value-ref="hibernateMBean"/>

<bean id="mbeanServerFactory" class="">
    <property name="locateExistingServerIfPossible" value="true"/>

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

, , , , , , ,

No Comments