jstat
Monitor Java Virtual Machine (JVM) statistics
SYNOPSIS
jstat [ options ] <vmid> [ <interval> [ <count> ]]
Where:
<vmid>: The Virtual Machine Identifier, typically the Process ID (PID) of the target Java application.
<interval>: Sampling interval in milliseconds. An optional 's' suffix can be used for seconds (e.g., '1s').
<count>: The number of samples to take. If omitted, jstat will run continuously until terminated.
PARAMETERS
<vmid>
The Virtual Machine Identifier, usually the operating system's Process ID (PID) of the target Java application.
<interval>
The sampling interval, specified in milliseconds. Optionally, append 's' for seconds (e.g., '1s').
<count>
The number of samples to take. If omitted, jstat will display statistics continuously.
-class
Displays statistics on the behavior of the class loader.
-compiler
Displays statistics on the behavior of the HotSpot Just-In-Time (JIT) compiler.
-gc
Displays statistics on garbage collection activity.
-gccapacity
Displays statistics on the capacities of the generations and their corresponding spaces.
-gcnew
Displays statistics on the behavior of the new generation (Eden and Survivor spaces).
-gcnewcapacity
Displays statistics on the capacities of the new generation.
-gcold
Displays statistics on the behavior of the old generation.
-gcoldcapacity
Displays statistics on the capacities of the old generation.
-gcutil
Displays garbage collection statistics with information on the utilization of each memory area.
-gcmetacapacity
Displays statistics on the capacities of the Metaspace.
-gcmetautil
Displays statistics on the utilization of the Metaspace.
-t
Displays a timestamp column at the beginning of the output.
-h<lines>
Displays column headers every specified number of lines of data samples.
-J<option>
Passes <option> directly to the Java VM where jstat is running (e.g., for setting heap size).
DESCRIPTION
jstat (Java Statistics Monitoring Tool) is a command-line utility provided with the Java Development Kit (JDK) designed to monitor the performance and resource consumption of an instrumented HotSpot Java Virtual Machine (JVM). It provides various categories of statistics, including garbage collection (GC) behavior, heap memory usage, class loading, and JIT compilation activity.
This tool is invaluable for diagnosing performance bottlenecks, identifying potential memory leaks, and gaining a deeper understanding of how a Java application behaves under different loads. By connecting to a running JVM process via its Process ID (PID), jstat can display real-time or snapshot data. It supports a continuous monitoring mode, similar to tools like top or vmstat, allowing users to observe trends over time by specifying an update interval and an optional sample count. Its primary use case is direct server-side JVM monitoring, providing raw data for quick analysis.
CAVEATS
• Permissions: jstat typically requires the user running the command to have the same user privileges as the target JVM process, or elevated permissions (e.g., root) to attach to it.
• Local Monitoring: By default, jstat is designed for local monitoring. For remote JVM monitoring, the jstatd daemon must be running on the target host with appropriate security policies configured.
• Output Interpretation: The raw numerical output from jstat can be challenging to interpret without a solid understanding of the JVM's memory model (Eden, Survivor, Old Gen, Metaspace) and various Garbage Collection algorithms.
• Performance Impact: While generally low, continuous monitoring with very short intervals can introduce a minor performance overhead on the monitored JVM.
• Modern Alternatives: For more detailed diagnostics, especially for heap analysis or thread dumps, other JDK tools like jcmd or graphical tools like JConsole and JVisualVM might offer more comprehensive features.
UNDERSTANDING OUTPUT METRICS
The columns in jstat's output vary by report type. For example, with -gcutil, you might see columns like S0C (Survivor 0 Capacity), S1U (Survivor 1 Used), EC (Eden Capacity), EU (Eden Used), OC (Old Gen Capacity), OU (Old Gen Used), MC (Metaspace Capacity), MU (Metaspace Used), YGC (Young GC Count), FGC (Full GC Count), and GCT (Total GC Time). Interpreting these requires familiarity with JVM memory areas and GC cycles.
REMOTE MONITORING WITH JSTATD
To monitor a JVM on a remote host using jstat, the jstatd daemon must be running on the target machine. This daemon acts as a RMI server, allowing remote tools like jstat to connect and retrieve JVM statistics. Proper security policies (`java.policy` file) must be configured to allow remote access to the JVM's instrumentation.
LISTING AVAILABLE OPTIONS
To see the specific report options available for your installed JDK version, you can run the command jstat -options
. This is useful as the set of available options can sometimes vary slightly between JDK versions or custom JVM builds.
HISTORY
jstat has been a fundamental part of the Java Development Kit (JDK) since early versions, notably appearing in JDK 1.4.2 and becoming a standard tool in JDK 5.0 and beyond. Its primary purpose has always been to provide command-line access to internal JVM performance counters. Over time, it has been updated to reflect changes in JVM memory management (e.g., the introduction of Metaspace replacing PermGen) and new garbage collection algorithms. While its core functionality remains consistent, the broader landscape of JVM diagnostic tools has evolved, with tools like jcmd and robust graphical interfaces offering more advanced capabilities. Despite these advancements, jstat remains a quick and efficient utility for real-time, basic JVM health checks and performance insights directly from the command line.