JVM metrics
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 thejava.lang.management.GarbageCollectorMXBeanparameter. -
Agents V4.4.0 and later: Metrics are retrieved by subscribing to the
GarbageCollectionNotificationInfoevent ofGarbageCollectorMXBean.
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.
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 |
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.

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. |
For live threads, the following different states are counted separately.
|
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. |