Install and Configure JMX using Zabbix Java Gateway

With the introduction of Zabbix 2.0 & above, the ability to monitor JMX counters without deploying additional software has been introduced in the form of a daemon called “Zabbix Java Gateway“. The most common use of JMX is monitoring thread counts and memory usage of any Java enabled application via the resource objects called MBeans (Managed Beans). See wiki for full explanation.

Zabbix Java Gateway can be installed alongside Zabbix Server or as a standalone server. For the purpose of this post, all Zabbix components will be installed on a single server

Step 1: Install Zabbix Java Gateway

I have documented the installation of zabbix java gateway in a previous post. Click Installing Zabbix 2.0 package from EPEL on CentOS 6.4 for full installation guide

Step 2: Configure Zabbix Java Gateway

After installing the zabbix java gateway, we need to configure it for use by telling the zabbix server where to find it.

– Log into zabbix using Putty. Edit the config file “zabbix_server.conf” using the command “vi /etc/zabbix/zabbix_server.conf“. Un-comment the following lines (JavaGateway, JavaGatewayPort & StartJavaPollers) and enter the  JavaGateway IP address or Hostname, Leave port as default or change it to desired port for security and enter number of pre-forked instances of Java pollers

Note: if you are monitoring servers via zabbix proxy, then the above configuration should be done on the zabbix proxy config file

zabbix-java01

– Restart zabbix server service

[code language=”js”]# service zabbix-server restart[/code]

Step 3: Add JMX interfaces for JMX communication

– On zabbix, click on host (server) running the java application. Under JMX interfaces, click the Add… button to add the IP address, DNS name and Port used by the java application. Save changes

zabbix-java05

Step 4: Add JMX agent item

After setting up and configuring the zabbix java gateway, next is to add a new JMX agent item you desire to monitor. For the purpose of showing you how this works, I will be monitoring the memory used by Java VM that runs the JConsole. I have already installed JConsole on my machine (see Installing JConsole for windows). At this stage I am assuming that you are already familiar with how to create a zabbix item and assign it to a server or a template.

1. First before you can monitor a Java application via JMX, you will need the following information “ &

– Launch jconsole by typing “jconsole” from command prompt. Select “Remote Process“, enter “localhost:0” or “<remote server:0>” where host is localhost or remote server and the port . Click Connect

zabbix-java02

– Click on MBeans tab, expand java.lang and click on Memory. Note the ObjectName value

zabbix-java03

– Expand Attributes and click on HeapMemoryUsage. Note the attribute name. You will also notice at the top the values of the different memory checks we will be monitoring

zabbix-java04

2. Create JMX Item

– See screenshot below to setup monitor for used HeapMemoryUsage. Remember to enter the KEY correctly and also select appropriate JMX Host Interface with correct Port if you have more than one JMX interface/port added. This happens when you have more than one Java enabled application on same server with different port

zabbix-java06

After saving newly created item, Go to Monitoring > Latest Data, select the server this item was created on and check if it’s started receiving updates by clicking on the Graph for the item. I have screenshots of one of my LIVE machines been monitored:

Graph:

zabbix-java07

JConsole:

zabbix-java08

As seen in both diagrams, I have marked out 3 points for comparison and you will notice that the values are same which means we are now able to use Zabbix JMX to monitor Java applications

Any questions, please feel free to ask 🙂

 
comments powered by Disqus