Teach you how to monitor Tomcat's JVM memory through JConsoler

Teach you how to monitor Tomcat's JVM memory through JConsoler

Monitoring Tomcat's JVM memory through JConsoler

1. How to monitor Tomcat

  • Simple commands
  • Ready-made scripts
  • Custom monitoring through zabbix

Custom monitoring: anything that can be obtained by command can be monitored

Monitoring java through jmx

  • Other monitoring

Monitoring hardware via ipmi

Monitor network devices through snmp, as long as they support snmp

2. Java's own monitoring commands

  • jps exports java related processes
  • Format: jps -lvm
  • Parameter options: -lvm most detailed
[root@localhost ~]# jps -lvm
7457 org.apache.catalina.startup.Bootstrap start start -Djava.util.logging.config.file=/application/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/application/tomcat -Dcatalina.home=/application/tomcat -Djava.io.tmpdir=/application/tomcat/temp
7525 org.apache.catalina.startup.Bootstrap start start -Djava.util.logging.config.file=/application/tomcat_8082/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/application/tomcat_8082 -Dcatalina.home=/application/tomcat_8082 -Djava.io.tmpdir=/application/tomcat_8082/temp
9144 sun.tools.jps.Jps -lvm -Denv.class.path=.:/application/jdk/lib:/application/jdk/jre/lib:/application/jdk/lib/tools.jar -Dapplication.home=/application/jdk1.8.0_60 -Xms8m
7482 org.apache.catalina.startup.Bootstrap start start -Djava.util.logging.config.file=/application/tomcat_8081/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -Dcatalina.base=/application/tomcat_8081 -Dcatalina.home=/application/tomcat_8081 -Djava.io.tmpdir=/application/tomcat_8081/temp
  • jmap exports jvm information, often used for custom monitoring
  • Format: jmap pid
  • Parameter: -heap
[root@localhost ~]# jmap -heap 7457
Attaching to process ID 7457, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.60-b23

using thread-local object allocation.
Mark Sweep Compact GC

Heap Configuration:
   MinHeapFreeRatio = 40
   MaxHeapFreeRatio = 70
   MaxHeapSize = 255852544 (244.0MB)
   NewSize = 5570560 (5.3125MB)
   MaxNewSize = 85262336 (81.3125MB)
   OldSize = 11206656 (10.6875MB)
   NewRatio = 2
   SurvivorRatio = 8
   MetaspaceSize = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize = 17592186044415 MB
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage: #For monitoring, pay attention to this column New Generation (Eden + 1 Survivor Space):
   capacity = 12779520 (12.1875MB)
   used = 11689352 (11.147834777832031MB)
   free = 1090168 (1.0396652221679688MB)
   91.46941356169872% used
Eden Space: #For monitoring, please pay attention to this column capacity = 11403264 (10.875MB)
   used = 11059616 (10.547271728515625MB)
   free = 343648 (0.327728271484375MB)
   96.98640669899426% used
From Space: #For monitoring, please pay attention to this column capacity = 1376256 (1.3125MB)
   used = 629736 (0.6005630493164062MB)
   free = 746520 (0.7119369506835938MB)
   45.75718470982143% used
To Space: #For monitoring, please pay attention to this column capacity = 1376256 (1.3125MB)
   used = 0 (0.0MB)
   free = 1376256 (1.3125MB)
   0.0% used
tenured generation: #For monitoring, please pay attention to this column capacity = 28164096 (26.859375MB)
   used = 18313224 (17.46485137939453MB)
   free = 9850872 (9.394523620605469MB)
   65.02329774760035% used

21146 interned Strings occupying 1882520 bytes.
  • jstatck exports Java process information, which is often used for Java program failures. It is necessary to export thread information for research with developers.
  • Format: jstack -l pid

[root@localhost ~]# jstack -l 7457

3. Tomcat troubleshooting case

The system load is high and Tomcat occupies a high CPU

  • 1. jps/top/htop accurately determine which java process caused
  • 2.jstack exports java threads
  • 3.catalina.out log analysis
  • 4.jmap exports jvm information, which can be analyzed by mat tool

4. Configure Tomcat JMX monitoring

  • Custom monitoring: Write the script directly on the tomcat server and in the zabbix configuration file
  • First, you need to install zabbix-java-gateway on the zabiix server and then enable the monitoring function on the tomcat server.
  • tomcat enables jmx monitoring function
#Modify bin/catalina.sh
[root@localhost tomcat]# vim bin/catalina.sh
#Note that you cannot write it in separate lines, otherwise you will get an error message saying that the command cannot be found. Write it on one line CATALINA_OPTS="$CATALINA_OPTS"
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jxmremote.ssl=false
-Djava.rmi.server.hostname="192.168.81.210"
#Correct way to write CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jxmremote.ssl=false -Djava.rmi.server.hostname=192.168.81.210"


#DescriptionCATALINA_OPTS="$CATALINA_OPTS" #Modify the tomcat startup parameters -Dcom.sun.management.jmxremote #Enable the tomcat remote management function -Dcom.sun.management.jmxremote.port=12345 #In addition to port 12345, the remote management function will also generate 2 random ports. We can open all ports Dcom.sun.management.jmxremote.authenticat=false #Is authentication required during monitoring? -Dcom.sun.management.jmxremote.ssl=false #Is SSL connection enabled? -Djava.rmi.server.hostname="192.168.81.210" #Set the ip of the server where tomcat is located

After the configuration is complete, restart tomcat and you can use the ps command to see that the output information has a few more lines we wrote [root@localhost tomcat]# ps aux | grep java
root 17786 5.7 10.6 2306592 105860 pts/1 Sl 15:52 0:08 /application/jdk/bin/java
-Djava.util.logging.config.file=/application/tomcat/conf/logging.properties 
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 
-Djdk.tls.ephemeralDHKeySize=2048 
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
-Dorg.apache.catalina.security.SecurityListener.UMASK=0027
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.authenticate=false 
-Dcom.sun.management.jxmremote.ssl=false 
-Djava.rmi.server.hostname=192.168.81.210 
-Dignore.endorsed.dirs= 
-classpath /application/tomcat/bin/bootstrap.jar:/application/tomcat/bin/tomcat-juli.jar 
-Dcatalina.base=/application/tomcat 
-Dcatalina.home=/application/tomcat 
-Djava.io.tmpdir=/application/tomcat/temp org.apache.catalina.startup.Bootstrap start

Use the ss/netstat command to see the three additional ports [root@localhost tomcat]# ss -lnptu | grep java
tcp LISTEN 0 100 :::8080 :::* users:(("java",pid=17786,fd=56))
#Our set tcp LISTEN 0 50 :::12345 :::* users:(("java",pid=17786,fd=22))
#Random 1
tcp LISTEN 0 50 :::46272 :::* users:(("java",pid=17786,fd=21))
# Random 2
tcp LISTEN 0 50 :::46081 :::* users:(("java",pid=17786,fd=24))
tcp LISTEN 0 1 ::ffff:127.0.0.1:8005 :::* users:(("java",pid=17786,fd=65))

5. Use Jsconsole to connect to JMX to view monitoring data

insert image description here

This is the end of this article on how to monitor Tomcat's JVM memory through JConsoler. For more information about JConsoler monitoring Tomcat JVM memory, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JVM Introduction: Memory Structure (Heap, Method Area)
  • A brief discussion on JVM using JFR to solve memory leaks
  • Huawei technical experts explain the JVM memory model (collection)
  • Docker View JVM Memory Usage

<<:  Convert psd cut image to div+css format

>>:  Sample code for implementing markdown automatic numbering with pure CSS

Recommend

How to start and restart nginx in Linux

Nginx (engine x) is a high-performance HTTP and r...

How to modify the group to which a user belongs in Linux

Modify the group to which a user belongs in Linux...

What is Makefile in Linux? How does it work?

Run and compile your programs more efficiently wi...

Summary of the differences between Html, sHtml and XHtml

For example: <u> This has no ending characte...

Example code of vue icon selector

Source: http://www.ruoyi.vip/ import Vue from ...

Detailed explanation of Nginx static file service configuration and optimization

Root directory and index file The root directive ...

27 Linux document editing commands worth collecting

Linux col command The Linux col command is used t...

SQL implementation of LeetCode (197. Rising temperature)

[LeetCode] 197.Rising Temperature Given a Weather...

JavaScript to implement the back to top button

This article shares the specific code for JavaScr...

The whole process of configuring reverse proxy locally through nginx

Preface Nginx is a lightweight HTTP server that u...

Implementation code for operating mysql database in golang

Preface Golang provides the database/sql package ...

How to replace all tags in html text

(?i) means do not match case. Replace all uppercas...

Linux process management tool supervisor installation and configuration tutorial

Environment: CentOS 7 Official documentation: htt...

How to deploy nginx with Docker and modify the configuration file

Deploy nginx with docker, it's so simple Just...