JVM metrics

Updated at:

Learn how the ARMS agent collects JVM metrics for memory, GC, threads, classes, and file descriptors.

Memory metrics

The ARMS agent has a scheduled task that periodically calls the JDK interface java.lang.management.ManagementFactory#getPlatformMXBeans(java.lang.Class<T>) with the parameter java.lang.management.MemoryPoolMXBean.class to obtain memory metrics.

This method returns a list where each element reflects the memory usage of a different JVM memory space. The following code snippet shows how to use this method.

public static void printCurrentJVMMemoryUsage() {
    List<MemoryPoolMXBean> beans = ManagementFactory.getPlatformMXBeans(MemoryPoolMXBean.class);
    for (MemoryPoolMXBean bean : beans) {
        System.out.printf("area=%s\tname=%s\tinitial=%d\tmax=%d\tcommited=%d\tuse=%d\n", bean.getType().name(),
                bean.getName(), bean.getUsage().getInit(), bean.getUsage().getMax(), bean.getUsage().getCommitted(), bean.getUsage().getUsed());
    }
}

Output varies by JVM version. The following example shows the type, name, initial size, maximum size, committed size, and used size of each memory space.

area=NON_HEAP	name=Code Cache	initial=2555904	max=134217728	commited=3211264	use=3139712
area=NON_HEAP	name=Metaspace	initial=0	max=-1	commited=8388608	use=7950584
area=NON_HEAP	name=Compressed Class Space	initial=0	max=1073741824	commited=1048576	use=919408
area=HEAP	name=PS Eden Space	initial=67108864	max=1409286144	commited=67108864	use=39057856
area=HEAP	name=PS Survivor Space	initial=11010048	max=11010048	commited=11010048	use=0
area=HEAP	name=PS Old Gen	initial=179306496	max=2863661056	commited=179306496	use=0

The ARMS agent periodically collects and reports these metrics without additional processing. The following table lists the metrics.

Metric

Description

arms_jvm_mem_init_bytes

The initial memory size.

arms_jvm_mem_max_bytes

The maximum memory size.

arms_jvm_mem_committed_bytes

The committed memory size.

arms_jvm_mem_used_bytes

The used memory size.

The following table describes two key dimensions.

Dimension

Description

Example

area

The memory space type.

heap, nonheap

id

The memory space name.

eden, survivor, total

For information about JVM memory spaces, see JVM memory details.

GC metrics

  • Agents earlier than V4.4.0: Metrics are retrieved by a scheduled task that periodically calls the JDK interface java.lang.management.ManagementFactory#getPlatformMXBeans(java.lang.Class<T>) and passes the java.lang.management.GarbageCollectorMXBean parameter.

  • Agents V4.4.0 and later: Metrics are retrieved by subscribing to the GarbageCollectionNotificationInfo event of GarbageCollectorMXBean.

This method returns a list where each element reflects the status of a different garbage collector in the JVM. The following code snippet shows how to use this method.

public static void printGC() {
    List<GarbageCollectorMXBean> beans = ManagementFactory.getPlatformMXBeans(GarbageCollectorMXBean.class);
    for (GarbageCollectorMXBean  bean : beans) {
        System.out.printf("name=%s\tgcCount=%d\tgcTime=%d\n", bean.getName(),
                bean.getCollectionCount(), bean.getCollectionTime());
    }
}

Output varies by JVM version. The following example shows each garbage collector name, the number of GC occurrences, and the GC time consumed.

name=PS Scavenge	gcCount=0	gcTime=0
name=PS MarkSweep	gcCount=0	gcTime=0

Because this data is cumulative since JVM startup, the ARMS agent subtracts the previous collection value to calculate the GC count and time consumed within the current period (default: 15 seconds). It then reports these metrics as described in the following table.

Note

For GC types other than ZGC and Shenandoah, GC duration refers to the stop-the-world (STW) duration, during which all Java application threads are paused. For ZGC and Shenandoah, Pauses corresponds to the STW duration, while Cycles represents the total duration of a GC event.

Metric

Description

arms_jvm_gc_delta

The number of GC occurrences in the current cycle.

arms_jvm_gc_seconds_delta

The GC time consumed in the current cycle.

To simplify interpretation, the ARMS agent maps garbage collector names to "Young" and "Old" and records them in the dimensions listed in the following table.

Dimension

Description

Example

gen

The GC type.

young, old

cause

The GC trigger, supported in agents V4.4.0 and later.

System.gc(), Heap Dump Initiated GC, Allocation Failure

View value descriptions

  • System.gc(): When the program explicitly callsSystem.gc()This cause is triggered when garbage collection is requested.

  • FullGCAlot/ScavengeAlot: These causes may be related to testing or debugging scenarios where frequent full GC or small GC ("scavenge") are triggered intentionally.

  • Allocation Profiler: This garbage collection reason may involve memory allocation profiling to better understand memory usage.

  • JvmtiEnv ForceGarbageCollection: Indicates that the Java Virtual Machine Tool Interface (JVMTI) issued a request to force garbage collection.

  • Heap Inspection Initiated GC & Heap Dump Initiated GC: These are generally not routine operations but are used to inspect the heap or take a heap dump.

  • WhiteBox Initiated Young/Full GC & Run to Breakpoint: These are triggered by WhiteBox tests and are usually used for JVM internal testing purposes.

  • No GC: The JVM may trigger GC based on internal heuristics (such as heap usage trend prediction in the CMS algorithm) rather than specific conditions (such as insufficient memory), so it is displayed as No GC.

  • Allocation Failure: A garbage collection triggered because the JVM cannot allocate memory for a new object, indicating a possible memory pressure situation.

  • CodeCache GC Threshold/Aggressive: Involves code cache, which stores compiled code. GC may be triggered when the cache reaches a certain threshold or requires active management.

  • Metadata GC Threshold/Clear Soft References: GC triggered by metadata space thresholds or soft reference clearing can release memory without affecting application execution.

  • G1 Evacuation Pause / Compaction Pause / Humongous Allocation / Periodic Collection: These are specific GC reasons related to G1 garbage collector, which is optimized for low pause times.

  • Diagnostic Command: Triggered by a diagnostic command, usually used for internal monitoring or diagnostic purposes.

  • Shenandoah GC Causes: These are related to the Shenandoah garbage collector, which is designed to reduce pause times through concurrent operations.

  • Z Garbage Collector Causes (Timer, Warmup, etc.): These are specific to ZGC (Z Garbage Collector) and focus on performance tuning aspects such as warm-up, allocation rates, and proactive measures.

  • ILLEGAL VALUE: Indicates an illegal or unrecognized garbage collection cause value, as a protection against unexpected situations.

The following table describes the mapping relationships.

Garbage collector name

Gen value

Copy

young

G1 Young Gen

young

G1 Old Gen

old

G1 Young Generation

young

G1 Old Generation

old

ParNew

young

ConMarkSweep

old

ConcurrentMarkSweep

old

PS Scavenge

young

PS MarkSweep

old

PS Serial

young

MarkSweepCompact

old

Because ZGC redesigns GC behavior significantly, the simple Young/Old classification no longer applies. ZGC collectors are mapped separately as follows.

Garbage collector name

Gen value

ZGC Cycles

cycles

ZGC Pauses

pauses

ZGC Minor Cycles

young_cycles

ZGC Minor Pauses

young_pauses

ZGC Major Cycles

old_cycles

ZGC Major Pauses

old_pauses

The ARMS console displays a "Thread Stack Usage" chart as shown below. This metric is not collected by the ARMS agent; it is calculated by multiplying the current live thread count by 1 MB. By default, the JVM allocates 1 MB per thread for storing the local variable table, operand stack, dynamic links, and method return addresses within stack frames.

image.png

Thread metrics

The ARMS agent has a scheduled task that periodically calls the JDK interface java.lang.management.ManagementFactory#getThreadMXBean to obtain thread metrics.

This method returns a java.lang.management.ThreadMXBean instance that reflects the current JVM thread status. The following code snippet shows how to use this method.

public static void printThreads() {
    ThreadMXBean threadMXBean = java.lang.management.ManagementFactory.getThreadMXBean();
    int threadCount = threadMXBean.getThreadCount();
    int daemonThreadCount = threadMXBean.getDaemonThreadCount();
    long totalStartedThreadCount = threadMXBean.getTotalStartedThreadCount();
    long terminatedThreadCount = totalStartedThreadCount - threadCount;
    System.out.printf("allStartedThreadCount=%d\tcurrentThreadCount=%d\tdaemonThreadCount=%d\tterminatedThreadCount=%d\n"
            , totalStartedThreadCount, threadCount, daemonThreadCount, terminatedThreadCount);
}

Output varies by JVM version. The following example shows the cumulative threads started, live thread count, daemon thread count, and cumulative terminated threads. All counts except terminated threads are obtained directly from the ThreadMXBean method. The terminated thread count is calculated by subtracting live threads from total started threads.

allStartedThreadCount=5	currentThreadCount=5	daemonThreadCount=4	terminatedThreadCount=0

For live threads, the agent also counts threads in each of the following states: RUNNABLE, BLOCKED, WAITING, and TIMED_WAITING.

The ARMS agent periodically collects and reports these metrics without additional processing. The following table lists the metrics.

Metric

Description

arms_jvm_threads_count

The initial memory size.

Thread types are distinguished by the following key dimensions.

Dimension

Description

Example

state

The thread status.

  • live: the number of live threads.

  • daemon: the number of daemon threads

  • terminated: the number of terminated threads. This is supported only by the ARMS agent 4.x.

For live threads, the following different states are counted separately.

  • new: New state

  • runnable: Runnable state

  • blocked: Blocked state

  • wait: Waiting state

  • timed-wait: Timed waiting state

Class metrics

The ARMS agent has a scheduled task that periodically calls the JDK interface ManagementFactory.getClassLoadingMXBean() to obtain class loading metrics.

This method returns a java.lang.management.ClassLoadingMXBean instance that reflects the current JVM class loading status. The following code snippet shows how to use this method.

public static void printCurrentJVMMemoryUsage() {
    ClassLoadingMXBean classLoaderMXBean = ManagementFactory.getClassLoadingMXBean();
    long totalLoadedClassCount = classLoaderMXBean.getTotalLoadedClassCount();
    long unloadedClassCount = classLoaderMXBean.getUnloadedClassCount();
    System.out.printf("totalLoadedClassCount=%d\tunloadedClassCount=%d\n"
            , totalLoadedClassCount, unloadedClassCount);
}

Output varies by JVM version. The following example shows the cumulative number of classes loaded and unloaded by the JVM.

totalLoadedClassCount=1355	unloadedClassCount=0

Because this data is cumulative since JVM startup, the ARMS agent subtracts the previous collection value to calculate the number of classes loaded and unloaded within the current period (default: 15 seconds). It then reports these metrics as described in the following table.

Metric

Description

arms_class_load_loaded

The number of classes loaded in the current cycle.

arms_class_load_un_loaded

The number of classes unloaded in the current cycle.

File descriptor metrics

The ARMS agent has a scheduled task that periodically calls the JDK interface ManagementFactory.getOperatingSystemMXBean() to obtain file descriptor metrics.

This method returns an java.lang.management.OperatingSystemMXBean instance that provides open file descriptor information for the current JVM. The following code snippet shows how to use this method.

public static void printFDUsage() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    if (!(operatingSystemMXBean instanceof UnixOperatingSystemMXBean)) {
        return;
    }
    long openFDCount = ((UnixOperatingSystemMXBean) operatingSystemMXBean).getOpenFileDescriptorCount();
    long maxFDCount = ((UnixOperatingSystemMXBean) operatingSystemMXBean).getMaxFileDescriptorCount();
    System.out.printf("openFDCount=%d\tfdOpenRatio=%f\n"
            , openFDCount, (double) openFDCount / maxFDCount);
}

Output varies by JVM version. The following example shows the number of open file descriptors and the file descriptor open ratio. The open ratio is calculated by dividing the number of currently open file descriptors by the maximum number of file descriptors the JVM can open.

openFDCount=184	fdOpenRatio=0.017969

The ARMS agent periodically collects and reports these metrics without additional processing. The following table lists the metrics.

Metric

Description

arms_file_desc_open_count

The number of file descriptors opened by the current JVM.

arms_file_desc_open_ratio

The number of classes unloaded in the current cycle.