Analyze a JVM, on a remote server, in real time with a JMX connection.
Explore the Oracle docs
View Demo
·
Report Bug
·
Request Feature
You need to create or open a start-my-application.sh script on your server, because we are going to modify the options passed at the start of the JVM, so that it knows that you will use the JMX connection to analyze its operation in remote mode.
The launch line of your JVM will looks like this in the <strat_my_application.sh> script
java -jar -Dspring.config.location=$install_dir/conf/<my_application_repository>/application.properties -Dlogback.configurationFile=$install_dir/conf/<my_application_repository>/logback.xml -Dconfig.file.path=$install_dir/conf/<my_application_repository>/business/businessConfiguration.xml $install_dir/jars/<my_application_name.jar> &
We will now add a number of new options that I will detail :
- Option N°1
-Dcom.sun.management.jmxremote
Tell the JVM that you will use JMX mode. JMX is the acronym for Java Management Extensions. JMX is a specification that defines an architecture, an API, and services to help you monitor and manage Java resources. JMX makes it possible to set up, using a standard, a system for monitoring and managing an application, a service or a resource without having to make a lot of effort.
- Option N°2
-Dcom.sun.management.jmxremote.port=9876
Indicates the port number on which your JVM will listen. It is this port that we will use from the Visual VM JAVA tool to connect to the JVM we are going to analyze.
- Option N°3
-Dcom.sun.management.jmxremote.ssl=false
Indicates that we will not use SSL mode to connect to our server from a computeur. For development environments we do not need SSL connection. For other environment should be set to true, but it leads to correctly set the server for this type of connection works with the JMX mode.
- Option N°4
-Dcom.sun.management.jmxremote.authenticate=false
Indicates that we will not use login and password to connect to the JVM. For dev environments is not required, but it may be necessary for other environments to set up this type of security.
- Option N°5
-Djava.rmi.server.hostname=<server_logical_name>
Specifies the logical name of the server on which the JVM that you want to monitor is running.
To obtain the logical address of your server, proceed as follows.
ifconfig
You get inet configuration information from your server, you must copy the IP address and use it with the following command.
nslookup <xxx.xxx.xxx.xxx>
You get the logical address of your server on the screen, it should be used in preference to IP addresses, because IP addresses can be changed when you change the runtime environment of the application, so that normally your logical address will not change.
So in summary, in your <start_my_application.sh> script, you'll end up with the following launch line for your JVM.
java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9876 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=<server_logical_name> -Dspring.config.location=$install_dir/conf/<my_application_repository>/application.properties -Dlogback.configurationFile=$install_dir/conf/<my_application_repository>/logback.xml -Dconfig.file.path=$install_dir/conf/<my_application_repository>/business/businessConfiguration.xml -jar $install_dir/jars/<my_application_name.jar> &
The JAVA Visual VM tool is available in all versions of Java JDK, to run it you simply need to open a command prompt on your computer and type the following command.
jvisualvm
You then get the next application.
In the Visual VM application, right click in the white area on the left below Snapshots. This will open a small window where you have to click on the Add JMX connection option.
You then get a window that will allow you to indicate on which remote machine you want to connect.
WARNING: the Visual VM application will then try to connect to your server and the specified port and will finally try to access the JVM, so you have to have launched your JVM before trying to connect to it.
If the remote connection to the JVM on your server is going well, you must obtain a new machine in the remote section of the Visual VM application.
To start analyzing how your JVM works, you have to right click on the name of the JVM and choose the menu option called "Open".
A window with the description of your JVM and these launch parameters will appear on the right.
Finally, in the tabs of this window, you need to choose the one called "Monitor", this tab will allow you to have the CPU usage information, memory, classes and threads.
To get a local copy up and running follow these simple steps.
- Clone the repo
git clone https://github.com/AntoineMeheut/JavaVisualVMGuide
Clone this project to use it for your developments or simply copy/paste the java script for your startmyapplication.sh
See the Project for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GNU General Public License v3.0 License. See LICENSE
for more information.
If you want to contact me just clic
Project Link: https://github.com/AntoineMeheut/JavaVisualVMGuide
This page was created by using it on au project and informations collected on Oracle VisualVM documentation.