diff --git a/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java b/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java index 540112b21..7f3f295c2 100644 --- a/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java +++ b/core/src/main/java/com/taobao/arthas/core/command/monitor200/JvmCommand.java @@ -14,6 +14,7 @@ import com.taobao.text.ui.TableElement; import com.taobao.text.util.RenderUtil; import java.lang.management.*; +import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; @@ -74,12 +75,27 @@ public class JvmCommand extends AnnotatedCommand { table.row("", ""); table.row(true, label("THREAD").style(Decoration.bold.bold())); drawThreadTable(table); - + table.row("", ""); + table.row(true, label("FILE-DESCRIPTOR").style(Decoration.bold.bold())); + drawFileDescriptorTable(table); process.write(RenderUtil.render(table, process.width())); process.write(affect.toString()).write("\n"); process.end(); } + private void drawFileDescriptorTable(TableElement table) { + table.row("MAX-FILE-DESCRIPTOR-COUNT", "" + invokeFileDescriptor(operatingSystemMXBean, "getMaxFileDescriptorCount")) + .row("OPEN-FILE-DESCRIPTOR-COUNT", "" + invokeFileDescriptor(operatingSystemMXBean, "getOpenFileDescriptorCount")); + } + private long invokeFileDescriptor(OperatingSystemMXBean os, String name) { + try { + final Method method = os.getClass().getDeclaredMethod(name); + method.setAccessible(true); + return (Long) method.invoke(os); + } catch (Exception e) { + return -1; + } + } private String toCol(Collection strings) { final StringBuilder colSB = new StringBuilder(); if (strings.isEmpty()) { diff --git a/site/src/site/sphinx/en/jvm.md b/site/src/site/sphinx/en/jvm.md index 25fe20325..b787281b7 100644 --- a/site/src/site/sphinx/en/jvm.md +++ b/site/src/site/sphinx/en/jvm.md @@ -84,8 +84,14 @@ $ jvm THREAD COUNT 16 DAEMON-COUNT 10 - LIVE-COUNT 18 + PEAK-COUNT 18 STARTED-COUNT 19 + DEADLOCK-COUNT 0 + + FILE-DESCRIPTOR + + MAX-FILE-DESCRIPTOR-COUNT 10240 + OPEN-FILE-DESCRIPTOR-COUNT 648 Affect cost in 2 ms. ``` @@ -93,5 +99,12 @@ Affect cost in 2 ms. * COUNT: the count of active threads * DAEMON-COUNT: the count of active daemon threads -* LIVE-COUNT: the maximum count of the live threads since JVM starts +* PEAK-COUNT: the maximum count of the live threads since JVM starts * STARTED-COUNT: the total count of the created threads since JVM starts +* DEADLOCK-COUNT: the count of deadlock threads + + +### fileDescriptor-related + +* MAX-FILE-DESCRIPTOR-COUNT:the count of max file descriptor JVM process can open +* OPEN-FILE-DESCRIPTOR-COUNT:the current count of file descriptor JVM process open \ No newline at end of file diff --git a/site/src/site/sphinx/jvm.md b/site/src/site/sphinx/jvm.md index 14989e5c3..4e668aca7 100644 --- a/site/src/site/sphinx/jvm.md +++ b/site/src/site/sphinx/jvm.md @@ -87,6 +87,11 @@ $ jvm PEAK-COUNT 18 STARTED-COUNT 19 DEADLOCK-COUNT 0 + + FILE-DESCRIPTOR + + MAX-FILE-DESCRIPTOR-COUNT 10240 + OPEN-FILE-DESCRIPTOR-COUNT 648 Affect cost in 2 ms. ``` @@ -95,5 +100,11 @@ Affect cost in 2 ms. * COUNT: JVM当前活跃的线程数 * DAEMON-COUNT: JVM当前活跃的守护线程数 -* LIVE-COUNT: 从JVM启动开始曾经活着的最大线程数 -* STARTED-COUNT: 从jvm启动开始总共启动过的线程次数 \ No newline at end of file +* PEAK-COUNT: 从JVM启动开始曾经活着的最大线程数 +* STARTED-COUNT: 从JVM启动开始总共启动过的线程次数 +* DEADLOCK-COUNT: JVM当前死锁的线程数 + +### 文件描述符相关 + +* MAX-FILE-DESCRIPTOR-COUNT:JVM进程最大可以打开的文件描述符数 +* OPEN-FILE-DESCRIPTOR-COUNT:JVM当前打开的文件描述符数