Recipe for setting up remote monitoring of Tomcat and Jetty containers using standard JDK tools
Conducting interviews with Java developers for about 6 years, I noticed that no one of the candidates who came came to know that it was possible to remotely monitor the state of the JVM with servlet containers using standard JDK tools. Therefore, further step by step recipe, how to configure and use this great opportunity
Monitoring tools
JConsole is a GUI tool for monitoring and managing both local and remote JVM and applications. We read about the official docks
Both software products are located in % JAVA_HOME% / bin JDK and use JMX technology - Java Management Extensions
Tomcat setup
% CATALINA_HOME% is the directory where Tomcat is installed. ')
In the directory % CATALINA_HOME% / conf create a config file remote.users with the contents of the form
_1 _1 _2 _2
The name of the file can be given any at your discretion. The file contains logins and passwords in an explicit (unfortunately) form of users who will be entitled to perform remote monitoring. For example:
tartaren from_tarascon portos passwordportos
In the directory % CATALINA_HOME% / conf create a config file remote.acl with the contents of the form
_1 _ _2 _
The name of the file can be given any at your discretion. ACCESS RIGHT - one of two readwrite or readonly constants. For example:
tartaren readonly portos readwrite
chmod 400 remote.users
chmod 400 remote.acl
chown tomcat: tomcat remote.users (user and tomcat group may need to be replaced according to the situation)
chown tomcat: tomcat remote.acl (user and tomcat group may need to be replaced according to the situation)
Find the run script catalina.sh (usually found in % CATALINA_HOME% / bin )
In the script before the launch section add the command:
IP_ADRES - The IP address of the Tomcat server. PORT NUMBER — The port number on which the Tomcat server will respond to JConsole or JVisualVM requests. For example:
* * * fi CATALINA_OPTS="$CATALINA_OPTS$JPDA_OPTS"shiftfi CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote.password.file=/usr/share/apache-tomcat-7.0.22/conf/remote.users -Dcom.sun.management.jmxremote.access.file=/usr/share/apache-tomcat-7.0.22/conf/remote.acl -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7777 -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=1.1.1.1"if [ "$1" = "debug" ] ; thenif$os400; thenecho"Debug command not available on OS400"exit 1 * * *
If you want to disable password authentication, you need to add -Dcom.sun.management.jmxremote.authenticate = false to the list of parameters CATALINA_OPTS
To make changes in the config and script take effect, you need to restart Tomcat using standard tools.
Jetty Setup
Create files remote.users and remote.acl (or with any other names at your discretion) in the directories that suit you.
chmod 400 remote.users
chmod 400 remote.acl
chown jetty: jetty remote.users (user and jetty group may need to be replaced according to the situation)
chown jetty: jetty remote.acl (user and tomcat group may need to be replaced according to the situation)
Most often, Jetty is used in conjunction with Maven. To run create script reboot.sh
Start (restart) Jetty with the command ./reboot.sh
JConsole connection
run jconsole
in the form that appears:
select remote access mode
enter the IP or domain name of the servlet container with the port number in the format IP_OR_DOMEN: NUMBER_PORT
fill in the Username and Password
press the [Connect] button
JConsole does not save connection settings and must be entered every time. If you disable monitoring password authentication in the servlet container, you can connect using the jconsole IP_ORI_DOMEN: PORT NUMBER command
JVisualVM connection
run JVisualVM
choose in the menu File-> Add JMX connection
in the form that appears:
Connection - enter the IP or domain name of the servlet container with the port number in the format IP_OR_DOMEN: NUMBER_PORT
if there is a desire - turn on the "checkbox" Display name and enter the desired alias for this connection
enable checkbox Use security credentials
fill in the Username and Password
optionally enable “daw” Save security credentials
Click [OK]
in the left tree, in the Remote item a new section will appear with our container
On this container, right-click and select the Open item.