LinuxCommandLibrary

jstat

Monitor Java Virtual Machine (JVM) statistics

SYNOPSIS

jstat [option] [-t] [-h<lines>] <vmid> [<interval>[s|ms] [<count>]]

PARAMETERS

-class
    Class loader statistics (loaded, unloaded, time)

-compiler
    Compiler statistics (JIT compilations, standard/time)

-gc
    Heap garbage collection statistics (S0/S1/E/O/P usage, times)

-gccapacity
    GC heap capacity statistics (max capacities per generation)

-gccause
    GC statistics with last GC cause (like -gc + cause column)

-gcnew
    Young generation GC statistics (Eden/Survivors usage, times)

-gcnewcapacity
    Young generation GC capacity statistics

-gcold
    Old generation GC statistics (usage, times)

-gcoldcapacity
    Old generation GC capacity statistics

-gcpermcapacity
    Permanent generation capacity (pre-Java 8)

-gcutil
    GC utilization statistics (% occupancy per space)

-printcompilation
    Compilation method statistics (size, type, status)

-t
    Add timestamp column (seconds since JVM start)

-h
    Print header every n samples (e.g., -h5)

-J
    Pass JVM flag (e.g., -J-Xmx32m)

-V
    Print version information


    JVM identifier (PID locally; host:port remotely)

[s|ms]
    Sampling interval (default seconds)


    Number of samples to take (default infinite)

DESCRIPTION

jstat is a command-line utility from the Java Development Kit (JDK) that monitors and prints statistics from a Java Virtual Machine (JVM). It provides real-time insights into key JVM activities such as garbage collection (GC), class loading, compiler performance, and heap usage. Ideal for troubleshooting memory leaks, GC pauses, or compilation bottlenecks in Java applications.

Usage involves specifying a statistics option (e.g., -gc for GC stats), the target JVM ID (VMID, typically the process ID or remote host:port), and optional sampling interval and count. Output columns include metrics like S0C (Survivor 0 capacity), Eden space usage, Metaspace, and GC times. Headers can be repeated with -h for multi-sample runs.

It's lightweight, non-intrusive, and doesn't require JVM suspension, making it suitable for production monitoring. Works on HotSpot JVMs; requires the JDK tools.jar or jstat binary in PATH.

CAVEATS

Requires JDK installation and PATH setup. Needs attach permission to target JVM (same user or -Djava.security.policy). Remote VMID requires JMX/RMI setup on target. Output format JVM-version dependent; pre-Java 8 uses PermGen, post uses Metaspace. No effect on JVM performance.

VMID FORMATS

Local: PID (use jps to list). Remote: [protocol:][//]hostname:port or /hostname:port/sessionid (requires target JVM export JMX)

EXAMPLE USAGE

jstat -gcutil 1234 1s 10 : GC % every second, 10 samples on PID 1234.
jstat -gc localhost:1099 : Remote GC stats.

HISTORY

Introduced in JDK 5 (2004) as part of Java Mission Control tools for HotSpot JVM diagnostics. Enhanced in JDK 6/7 with more GC options; Java 8 shifted to Metaspace. Maintained in OpenJDK.

SEE ALSO

jps(1), jmap(1), jcmd(1), jstack(1)

Copied to clipboard