🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to enable Java & Tomcat monitoring using JMX in Zabbix?

What is JMX?

Java Management Extensions (JMX) is a Java technology that supplies tools for managing and monitoring applications, system objects, devices and service-oriented networks. Those resources are represented by objects called MBeans. In the API, classes can be dynamically loaded and instantiated.

JMX monitoring can be used to monitor JMX counters of a Java application.

JMX monitoring has native support in Zabbix in the form of a Zabbix daemon called “Zabbix Java gateway”, introduced since Zabbix 2.0.

To retrieve the value of a particular JMX counter on a host, Zabbix server queries the Zabbix Java gateway, which in turn uses the JMX management API to query the application of interest remotely.

Zabbix Java gateway

The so-called Zabbix Java Gateway is a special bollard process that can retrieve data via JMX. Unlike the previously mentioned boll processes, this is not an “internal” process within the Zabbix server. The Java Gateway is a stand-alone daemon that provides data to the Zabbix server through a TCP port. The Java Gateway is Java software that requires a JRE.

How Zabbix-Server Monitor Java Apps using JMX?

When Zabbix-Server needs to know a performance of a Java application, it starts its own Zabbix-JavaPollers process to connect to Zabbix-JavaGateway requesting data, and ZabbixJavagateway receives the request and uses the JMXmanagement API to query a specific application, provided that the application requires’-Dcom.sun.management.jmxremo’when it startsTe”parameter to open JMX remote queries.The Java program starts its own simple applet port 12345 to provide the requested data to Zabbix-JavaGateway.

From the schematic diagram above, you can see that the key points to configuring Zabbix monitoring Java applications are configuring Zabbix-JavaGateway, enabling Zabbix-Server to connect to Zabbix-JavaGateway, Tomcat to turn on JVM remote monitoring capabilities, and so on.

Prerequisite

Step 1 – Locate a VM where you want to run JAVA Application & Install JAVA

Step 2 – Install and Verify Tomcat


$ apt install unzip wget 
$ cd /opt/
$ wget https://apachemirror.wuchna.com/tomcat/tomcat-8/v8.5.66/bin/apache-tomcat-8.5.66.zip
$ unzip apache-tomcat-8.5.66.zip

# Tomcat 9 Install Guide

$ /opt/
$ wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.60/bin/apache-tomcat-9.0.60.zip
$ yum install unzip
$ unzip apache-tomcat-9.0.60.zip
$ cd apache-tomcat-9.0.60
$ cd bin/
$ chmod -R 775 *
$ ls -la
$ ./startup.sh
$ ps -eaf | grep tomcat


Step 3 – Install and Verify Sample Apps in Tomcat


$ cd /opt/apache-tomcat-8.5.66/webapps
$ wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
$ chmod 755 sample.war

Step 4 – Enable JMX in Tomcat


Enabling remote JMX monitoring for Java application in Zabbix Agent Where Java Apps is installed

A Java application does not need any additional software installed, but it needs to be started with the command-line options specified below to have support for remote JMX monitoring.

As a bare minimum, if you just wish to get started by monitoring a simple Java application on a local host with no security enforced, start it with these options:

$ cd /opt/apache-tomcat-8.5.66/bin
$ vi setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=52.66.202.226 -Djava.net.preferIPv4Stack=true"
$ chmod -R 755 .
$ ./startup.sh
$ ps -eaf | grep tomcat
$ ps -eaf | grep jmx
$ netstat -nl | grep -E -i "proto|8080|12345"
# Verify http://IP-ADD:8080/sample/

NOTE: 
- java.rmi.server.hostname = A Place where JMX is running and accessible. Ie. Tomcat server

- Communication between Java gateway and the monitored JMX application should not be firewalled. So disable the server level internal firewall in the linux client using the below command. $ systemctl disable firewalld

OR
java \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=12345 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.registry.ssl=false \
-jar /usr/share/doc/openjdk-6-jre-headless/demo/jfc/Notepad/Notepad.jar


Step 5 – Configuring JMX interfaces and items in Zabbix frontend

With Java gateway running, server knowing where to find it and a Java application started with support for remote JMX monitoring, it is time to configure the interfaces and items in Zabbix GUI.

Before retrieving data from the JMX interface, you must specify for each host on which IP address and on which TCP port the JMX interface of the Java program listens. Navigate to the host configuration and add a JMX interface. If you want to monitor several Java programs via JMX on a host, you must use different TCP ports.

  • Create a host at Zabbix Server with a IP address where you enabled JMX with a port – 12345
  • Apply Apache Tomcat JMX template to a host
  • Validate a Latest data of Of Java at Zabbix FrontEnd

Step 6 – Check the Latest Data

Reference

  • https://www.zabbix.com/documentation/5.4/en/manual/concepts/java
  • https://www.zabbix.com/documentation/5.4/en/manual/config/items/itemtypes/jmx_monitoring
  • https://blog.zabbix.com/new-monitoring-possibilities-for-java-applications-in-zabbix-3-4/5972/

Some Rough Work

DEMO - ubuntu 18.x
[ Changes to be done in Zabbix Server ]
Step 1 - Install & Enable Zabbix Java Gateway
==============================================================
To use JMX monitoring, you must install the Zabbix Java Gateway, which is typically not included in the default installation. If you are using Zabbix LLC DEB or RPM packages , install the Java Gateway as follows. The Java Gateway requires no configuration and can be started immediately.
# Debian/Ubuntu
# wget https://repo.zabbix.com/zabbix/5.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.4-1+ubuntu20.04_all.deb
# dpkg -i zabbix-release_5.4-1+ubuntu20.04_all.deb
# apt update
$ apt-get install zabbix-java-gateway
$ /etc/init.d/zabbix-java-gateway start
# Red Hat/CentOS
$ rpm -Uvh https://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm
# rpm -Uvh https://repo.zabbix.com/zabbix/5.4/rhel/7/x86_64/zabbix-release-5.4-1.el7.noarch.rpm
$ yum clean all
$ yum install zabbix-java-gateway
$ service zabbix-java-gateway start
$ systemctl enable zabbix-java-gateway
# Test if the Java Gateway is running.
$ ps -ef| grep -i java
Step 2 - Configure zabbix server with Zabbix Java Gateway info
=================================================================
Java Gateway as data provider for the Zabbix server
Now that Java gateway is running, you have to tell Zabbix server where to find Zabbix Java gateway. This is done by specifying JavaGateway and JavaGatewayPort parameters in server configuration file.
If the host on which JMX application is running is monitored by Zabbix proxy, then you specify the connection parameters in proxy configuration file instead.
$ vi /etc/zabbix/zabbix_server.conf
JavaGateway=IP address (or hostname) of Zabbix Java gateway.
JavaGatewayPort=10052
By default, server does not start any processes related to JMX monitoring. If you wish to use it, however, you have to specify the number of pre-forked instances of Java pollers. You do this in the same way you specify regular pollers and trappers.
StartJavaPollers=5
Do not forget to restart server or proxy, once you are done with configuring them.
Enter the Java Gateway in the file /etc/zabbix/zabbix_server.conf . In the Zabbix server, activate at least one Java bollard, which "requests" the item data from the Java gateway and forwards the server process. After you make the changes, restart the Zabbix server.
$ zabbix_server -c /etc/zabbix/zabbix_server.conf -R config_cache_reload
$ zabbix_server -R config_cache_reload
NOTE:
This is a one time setup in the zabbix server and need NOT be modified again for every new server that we add to the Zabbix WebUI.
Log - more /var/log/zabbix/zabbix_java_gateway.log
[ server - Where you are running apps and wants to monitor from Zabbix Server ]
Step 1 - Get a VMs(Where we need to run Java App) and Install JAVA in it
==============================================================
- https://www.devopsschool.com/blog/complete-guide-of-java-installation-in-linux/
Step 2 - Install and Verify Tomcat in this VM
==============================================================
$ apt install unzip wget
$ cd /opt/
$ wget https://apachemirror.wuchna.com/tomcat/tomcat-8/v8.5.66/bin/apache-tomcat-8.5.66.zip
$ unzip apache-tomcat-8.5.66.zip
Step 3 - Install and Verify Sample Apps in Tomcat
==============================================================
$ cd /opt/apache-tomcat-8.5.66/webapps
$ wget https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/sample.war
-
Step 4 - Enable JMX in Tomcat
======================================================
Enabling remote JMX monitoring for Java application in Zabbix Agent Where Java Apps is installed
A Java application does not need any additional software installed, but it needs to be started with the command-line options specified below to have support for remote JMX monitoring.
As a bare minimum, if you just wish to get started by monitoring a simple Java application on a local host with no security enforced, start it with these options:
$ cd /opt/apache-tomcat-8.5.66/bin
$ vi setenv.sh
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=52.66.202.226 -Djava.net.preferIPv4Stack=true"
$ chmod -R 755 .
$ ./startup.sh
$ ps -eaf | grep tomcat
$ ps -eaf | grep jmx
$ netstat -nl | grep -E -i "proto|8080|12345"
# Verify http://IP-ADD:8080/sample/
NOTE:
- java.rmi.server.hostname = A Place where JMX is running and accessible. Ie. Tomcat server
- Communication between Java gateway and the monitored JMX application should not be firewalled. So disable the server level internal firewall in the linux client using the below command. $ systemctl disable firewalld
Step 5 - Configuring JMX interfaces and items in Zabbix frontend
======================================================
With Java gateway running, server knowing where to find it and a Java application started with support for remote JMX monitoring, it is time to configure the interfaces and items in Zabbix GUI.
Before retrieving data from the JMX interface, you must specify for each host on which IP address and on which TCP port the JMX interface of the Java program listens. Navigate to the host configuration and add a JMX interface. If you want to monitor several Java programs via JMX on a host, you must use different TCP ports.
Apply the appropriate JMX template to the server in the zabbix webUI like JMX generic template and you can see that the
- Create a Hostgroup for JAVA Apps and Attached to Apache Tomcat JMX template
- Create a Host and Attach and Hostgroup created at Step1.
Ref
https://blog.zabbix.com/new-monitoring-possibilities-for-java-applications-in-zabbix-3-4/5972/
Loading...

Subscribe
Notify of
guest


1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Bill Negrelli
Bill Negrelli
1 year ago

LOL at “ So disable the server level internal firewall in the linux client using the below command. $ systemctl disable firewalld”
yeah don’t bother opening a single port for communication, just disable your entire firewall. who cares about security.

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

1
0
Would love your thoughts, please comment.x
()
x