Chapter 17. Monitoring Java Applications

Among all the other features that Zabbix can query directly is monitoring Java application servers using the Java Management Extensions (JMX) protocol. Actually, it's not just application servers—other server software written in Java can be monitored as well. Even standalone Java applications can be monitored, as the JMX framework does not have to be implemented by application developers—it is provided with Java. The main Zabbix daemons are written in C, but the JMX protocol is somewhat complicated, especially all the authorization and encryption methods. Thus, a separate component is used for JMX monitoring: the Zabbix Java gateway. This gateway runs as a separate process and queries JMX interfaces on behalf of Zabbix Server. In this chapter, we will set up the Java gateway and monitor a simple property on it.

Setting up the Zabbix Java gateway

Let's start by getting the gateway up and running. If you installed from packages, there likely is a Java gateway package available—just install that one. If you installed from source, the Java gateway can be compiled and installed by running the following from the Zabbix source directory:

$ ./configure --enable-java && make install

Tip

If the compilation fails because it is unable to find javac, you might be missing Java development packages. The package name could be similar to java-1_7_0-openjdk-devel. Consult your distribution's documentation for the exact package name.

By default, when compiling from source, the Zabbix Java gateway files are placed in the /usr/local/sbin/zabbix_java directory. From here on, we will use files found in that directory. If you installed from packages, consult the package configuration information to locate those files.

Let's try something simple: just starting up the gateway. Go to the Java gateway directory and run this:

# ./startup.sh

The Zabbix Java gateway comes with a convenient startup script, which we used here. If all went well, you should see no output, and a Java process should appear in the process list. Additionally, the gateway should listen on port 10052. While this port is not an officially registered port for the Zabbix Java gateway, it's just one port above the Zabbix trapper port, and there does not seem to be any other application using that port. With the gateway running, we still have to tell Zabbix Server where the gateway is to be found. Open zabbix_server.conf and look for the JavaGateway parameter. By default, it is not set, and we have to configure the gateway IP or hostname here. As we can point the server at a remote system, we are not required to run the Java gateway on the same system where Zabbix Server is located—in some cases, we might want to place the gateway closer to the Java application server, for example. Set this parameter to the localhost IP address:

JavaGateway=127.0.0.1

Right below is a parameter called JavaGatewayPort. By default, it is set to 10052—the same unregistered port as our running gateway already listens on—so we won't change that. The next parameter is StartJavaPollers. The same as with IPMI pollers, no Java pollers are started by default. We won't hammer our Java gateway much, so enable a single Java poller:

StartJavaPollers=1

With this, Zabbix Server should be sufficiently configured. Restart it to apply the Java gateway configuration changes. Great, we have the gateway running, and Zabbix Server knows where it is. Now, we just need something to monitor. If you have a Java application server that you can use for testing, try monitoring it. If not, or for something more simple to start with, you could monitor the gateway itself. It is a Java application, and thus, the JMX infrastructure is available. There's one thing we should change before enabling JMX for the gateway. Java is quite picky about DNS and name resolution in general. If JMX functionality is enabled and the local system hostname does not resolve, Java applications are likely to fail to start up. For a local Java gateway, check the /etc/hosts file. If there is no entry for the current hostname, add a line like this:

127.0.0.1 testhost

We're ready to enable JMX functionality for the gateway now; it is not enabled by default. To enable JMX on the Zabbix Java gateway, edit the startup.sh script we used earlier, and look for this line:

# uncomment to enable remote monitoring of the standard JMX objects on the Zabbix Java Gateway itself

As the first line says, uncomment the two lines following it.

Tip

A single variable is assigned across two lines there.

One parameter in there is worth paying extra attention to:

-Dcom.sun.management.jmxremote.port=12345

This sets the JMX port—the one that the gateway itself will query. Yes, in this case, we will start a process that will connect to itself on that port to query JMX data. The port is definitely not a standard one—as you might guess, it's just a sequence of 1-2-3-4-5. Other Java applications will most likely use a different port, which you will have to find out.

If you installed from packages, a recent package should include the same lines in the init script. If not, consider reporting that to the package maintainers, and use the following parameters in addition to the port parameter, listed in the previous code:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

The first parameter tells Java to enable JMX, and the last two parameters instruct Java not use any authentication or encryption.

Note

At the time of writing this book, JMX functionality in the Zabbix gateway does not work with Java 1.9. The solution is to downgrade to Java 1.8.

With this change done, run the shutdown and startup scripts:

# ./shutdown.sh
# ./startup.sh

We are finally ready for adding actual hosts and JMX items.

Note

Currently, Zabbix only supports a hardcoded Remote Method Invocation (RMI) endpoint for JMX monitoring. Java application servers that use other protocols are not supported—that includes JBoss 6 and later. Do not use RMI parameters to enable JMX on JBoss—they can prevent JBoss from starting.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.131.213