Linux Java Monitoring Commands | Thread Dump | Heap Dump | Disk Space

 How to perform a Thread Dump

 

#Option 1)

 

$ kill -3 JBOSSPID

 

#Option 2)

 

$ jstack -l JBOSSPID > jstack.out

 

**#Replace JBOSSPID with the Application server's PID

 



How to count the number of Threads running

 

#On linux architectures, you can count the number of running threads (as lightweight processes) as follows:

 

$ ps -eLf | grep [PID] | wc -l

 

#How to check the CPU usage of a Thread

 

#Thread are qualified by Linux Operating system as lightweight processes. You have to execute at first top to retrieve the CPU usage of a Thread Id:

 

$ top -b -n 1 -H -p JBOSSPID

#Example output:

 

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND           

8374 jboss      25   0 2284m 640m  80m R 39.5 23.7  13:00.64 java              

8465 jboss      25   0 2284m 640m  80m R 19.5 23.7   7:23.10 java

 

#Now that you have identified the top CPU consuming Thread ids (Column PID), check their stack trace to see what's going on

 

How to monitor a Java Process Heap size: (Requires JDK!)

 

jmap -heap PID


#Example:

$ jmap -heap 713

#Attaching to process ID 713, please wait...

#Debugger attached successfully.

#Server compiler detected.

#JVM version is 25.60-b23

 

#using thread-local object allocation.

#Parallel GC with 4 thread(s)

 

#Heap Configuration:

#   MinHeapFreeRatio         = 0

#   MaxHeapFreeRatio         = 100

#   MaxHeapSize              = 1367343104 (1304.0MB)

#   NewSize                  = 22020096 (21.0MB)

#   MaxNewSize               = 455606272 (434.5MB)

#   OldSize                  = 45088768 (43.0MB)

#   NewRatio                 = 2

#   SurvivorRatio            = 8

#   MetaspaceSize            = 21807104 (20.796875MB)

#   CompressedClassSpaceSize = 1073741824 (1024.0MB)

#   MaxMetaspaceSize         = 17592186044415 MB

#   G1HeapRegionSize         = 0 (0.0MB)

#

#Heap Usage:

#PS Young Generation

#Eden Space:

#   capacity = 84934656 (81.0MB)

#   used     = 40320120 (38.45226287841797MB)

#   free     = 44614536 (42.54773712158203MB)

#   47.471929479528356% used

#From Space:

#   capacity = 18874368 (18.0MB)

#   used     = 0 (0.0MB)

#   free     = 18874368 (18.0MB)

#   0.0% used

#To Space:

#   capacity = 23592960 (22.5MB)

#   used     = 0 (0.0MB)

#   free     = 23592960 (22.5MB)

#   0.0% used

#PS Old Generation

#   capacity = 91226112 (87.0MB)

#   used     = 36171208 (34.49555206298828MB)

#   free     = 55054904 (52.50444793701172MB)

#   39.65005984251527% used

 

 


How to monitor IO and Disk Space

 

#How to find the size of a directory, including subdirectories (Especially useful for log files)

 

$ du -sh standalone/log/

600K    standalone/log/

 

 

#How to find space left on a device

$ df -h /

Filesystem               Size  Used Avail Use% Mounted on

/dev/mapper/fedora-root   50G   27G   20G  58% /

 

#How to compare two files side by side (useful to check differences between configuration files)

 

$ sdiff -s standalone1.xml standalone2.xml

<connection-url>jdbc:h2:mem:test</connection-url> | <connection-url>jdbc:h2:mem:other</connection-url

How to find IO statistics per process (useful especially for journal!)

 

 

$ cat /proc/4383/io

rchar: 6311275

wchar: 6525

syscr: 3883

syscw: 40

read_bytes: 3129344

write_bytes: 77688832

cancelled_write_bytes: 0

#In the above example, we are checking IO statistics of the process id 4383.

 


 



 

Comments

Popular posts from this blog

Command Line tool for Android and iOS [ adb and cfgutil ]

Convert Chrome recording to Vugen Script

Jmeter-CheatSheet