JVM相关命令
dashboard——当前系统的实时数据面板
显示当前 tomcat 的实时信息。
使用方式:dashboard
数据说明
ID: Java 级别的线程 ID,注意这个 ID 不能跟 jstack 中的 nativeID 一一对应。
NAME: 线程名
GROUP: 线程组名
PRIORITY: 线程优先级, 1~10 之间的数字,越大表示优先级越高
STATE: 线程的状态
CPU%: 线程的 cpu 使用率。比如采样间隔 1000ms,某个线程的增量 cpu 时间为 100ms,则 cpu 使用率=100/1000=10%
DELTA_TIME: 上次采样之后线程运行增量 CPU 时间,数据格式为秒
TIME: 线程运行总 CPU 时间,数据格式为分:秒
INTERRUPTED: 线程当前的中断位状态
DAEMON: 是否是 daemon 线程
thread
查看当前线程信息,查看线程的堆栈。
参数说明
参数名称 | 参数说明 |
---|---|
id | 线程 id |
[n:] | 指定最忙的前 N 个线程并打印堆栈 |
[b] | 找出当前阻塞其他线程的线程 |
[i ] | 指定 cpu 使用率统计的采样间隔,单位为毫秒,默认值为 200 |
[–all] | 显示所有匹配的线程 |
举例:thread -n 3
jvm
查看当前 JVM 信息。
示例:
$ jvm
RUNTIME
--------------------------------------------------------------------------------------------------------------MACHINE-NAME 37@ff267334bb65JVM-START-TIME 2020-07-23 07:50:36MANAGEMENT-SPEC-VERSION 1.2SPEC-NAME Java Virtual Machine SpecificationSPEC-VENDOR Oracle CorporationSPEC-VERSION 1.8VM-NAME Java HotSpot(TM) 64-Bit Server VMVM-VENDOR Oracle CorporationVM-VERSION 25.201-b09INPUT-ARGUMENTS []CLASS-PATH demo-arthas-spring-boot.jarBOOT-CLASS-PATH /usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/classesLIBRARY-PATH /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib--------------------------------------------------------------------------------------------------------------CLASS-LOADING
--------------------------------------------------------------------------------------------------------------LOADED-CLASS-COUNT 7529TOTAL-LOADED-CLASS-COUNT 7529UNLOADED-CLASS-COUNT 0IS-VERBOSE false--------------------------------------------------------------------------------------------------------------COMPILATION
--------------------------------------------------------------------------------------------------------------NAME HotSpot 64-Bit Tiered CompilersTOTAL-COMPILE-TIME 14921(ms)--------------------------------------------------------------------------------------------------------------GARBAGE-COLLECTORS
--------------------------------------------------------------------------------------------------------------PS Scavenge name : PS Scavenge[count/time (ms)] collectionCount : 7collectionTime : 68PS MarkSweep name : PS MarkSweep[count/time (ms)] collectionCount : 1collectionTime : 47--------------------------------------------------------------------------------------------------------------MEMORY-MANAGERS
--------------------------------------------------------------------------------------------------------------CodeCacheManager Code CacheMetaspace Manager MetaspaceCompressed Class SpaceCopy Eden SpaceSurvivor SpaceMarkSweepCompact Eden SpaceSurvivor SpaceTenured Gen--------------------------------------------------------------------------------------------------------------MEMORY
--------------------------------------------------------------------------------------------------------------HEAP-MEMORY-USAGE init : 268435456(256.0 MiB)[memory in bytes] used : 18039504(17.2 MiB)committed : 181403648(173.0 MiB)max : 3817865216(3.6 GiB)NO-HEAP-MEMORY-USAGE init : 2555904(2.4 MiB)[memory in bytes] used : 33926216(32.4 MiB)committed : 35176448(33.5 MiB)max : -1(-1 B)--------------------------------------------------------------------------------------------------------------OPERATING-SYSTEM
--------------------------------------------------------------------------------------------------------------OS LinuxARCH amd64PROCESSORS-COUNT 3LOAD-AVERAGE 29.53VERSION 4.15.0-52-generic--------------------------------------------------------------------------------------------------------------THREAD
--------------------------------------------------------------------------------------------------------------COUNT 30DAEMON-COUNT 24PEAK-COUNT 31STARTED-COUNT 36DEADLOCK-COUNT 0--------------------------------------------------------------------------------------------------------------FILE-DESCRIPTOR
--------------------------------------------------------------------------------------------------------------MAX-FILE-DESCRIPTOR-COUNT 1048576OPEN-FILE-DESCRIPTOR-COUNT 100
Affect(row-cnt:0) cost in 88 ms.
THREAD 相关
COUNT: JVM 当前活跃的线程数
DAEMON-COUNT: JVM 当前活跃的守护线程数
PEAK-COUNT: 从 JVM 启动开始曾经活着的最大线程数
STARTED-COUNT: 从 JVM 启动开始总共启动过的线程次数
DEADLOCK-COUNT: JVM 当前死锁的线程数
文件描述符相关
MAX-FILE-DESCRIPTOR-COUNT:JVM 进程最大可以打开的文件描述符数
OPEN-FILE-DESCRIPTOR-COUNT:JVM 当前打开的文件描述符数
sysprop
查看当前 JVM 的系统属性(System Property)。
使用示例:
$ syspropKEY VALUE
-------------------------------------------------------------------------------------------------------------------------------------java.runtime.name Java(TM) SE Runtime Environmentsun.boot.library.path /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/libjava.vm.version 25.51-b03user.country.format CNgopherProxySet falsejava.vm.vendor Oracle Corporationjava.vendor.url http://java.oracle.com/path.separator :java.vm.name Java HotSpot(TM) 64-Bit Server VMfile.encoding.pkg sun.iouser.country USsun.java.launcher SUN_STANDARDsun.os.patch.level unknownjava.vm.specification.name Java Virtual Machine Specificationuser.dir /private/var/tmpjava.runtime.version 1.8.0_51-b16java.awt.graphicsenv sun.awt.CGraphicsEnvironmentjava.endorsed.dirs /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/endorsedos.arch x86_64java.io.tmpdir /var/folders/2c/tbxwzs4s4sbcvh7frbcc7n000000gn/T/line.separatorjava.vm.specification.vendor Oracle Corporationos.name Mac OS Xsun.jnu.encoding UTF-8java.library.path /Users/wangtao/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.sun.nio.ch.bugLeveljava.specification.name Java Platform API Specificationjava.class.version 52.0sun.management.compiler HotSpot 64-Bit Tiered Compilersos.version 10.12.6user.home /Users/wangtaouser.timezone Asia/Shanghaijava.awt.printerjob sun.lwawt.macosx.CPrinterJobfile.encoding UTF-8java.specification.version 1.8user.name wangtaojava.class.path .java.vm.specification.version 1.8sun.arch.data.model 64java.home /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jresun.java.command Testjava.specification.vendor Oracle Corporationuser.language enawt.toolkit sun.lwawt.macosx.LWCToolkitjava.vm.info mixed modejava.version 1.8.0_51java.ext.dirs /Users/wangtao/Library/Java/Extensions:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/ext:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/javasun.boot.class.path /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/classesjava.vendor Oracle Corporationfile.separator /java.vendor.url.bug http://bugreport.sun.com/bugreport/sun.cpu.endian littlesun.io.unicode.encoding UnicodeBigsun.cpu.isalist
查询指定配置
$ sysprop java.version
java.version=1.8.0_51
修改指定配置
$ sysprop user.country
user.country=US
$ sysprop user.country CN
Successfully changed the system property.
user.country=CN
sysenv
查看当前 JVM 的环境属性(System Environment Variables)。
使用参考:
USAGE:sysenv [-h] [env-name]SUMMARY:Display the system env.EXAMPLES:sysenvsysenv USERWIKI:https://arthas.aliyun.com/doc/sysenvOPTIONS:-h, --help this help<env-name> env name
使用示例
$ sysenvKEY VALUE
----------------------------------------------------------------------------------------------------------------------------PATH /Users/admin/.sdkman/candidates/visualvm/current/bin:/Users/admin/.sdkman/candidates/java/current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Wireshark.app/Contents/MacOSSDKMAN_VERSION 5.7.3+337JAVA_HOME /Users/admin/.sdkman/candidates/java/currentJAVA_MAIN_CLASS_65244 demo.MathGameTERM xterm-256colorLANG zh_CN.UTF-8AUTOJUMP_SOURCED 1COLORTERM truecolorLOGNAME adminXPC_SERVICE_NAME 0PWD /Users/admin/code/ali/arthas/demoTERM_PROGRAM_VERSION 3.2.5_ /Users/admin/.sdkman/candidates/java/current/bin/javaSHELL /bin/bashTERM_PROGRAM iTerm.appSDKMAN_PLATFORM DarwinUSER adminITERM_PROFILE DefaultTMPDIR /var/folders/0r/k561bkk917gg972stqclbz9h0000gn/T/XPC_FLAGS 0x0TERM_SESSION_ID w0t4p0:60BC264D-9649-42AC-A7E4-AF85B69F93F8__CF_USER_TEXT_ENCODING 0x1F5:0x19:0x34Apple_PubSub_Socket_Ren /private/tmp/com.apple.launchd.DwmmjSQsll/RenderderCOLORFGBG 7;0HOME /Users/adminSHLVL 1AUTOJUMP_ERROR_PATH /Users/admin/Library/autojump/errors.log
vmoption
查看,更新 VM 诊断相关的参数。
查看所有option
[arthas@56963]$ vmoptionKEY VALUE ORIGIN WRITEABLE
---------------------------------------------------------------------------------------------HeapDumpBeforeFullGC false DEFAULT trueHeapDumpAfterFullGC false DEFAULT trueHeapDumpOnOutOfMemory false DEFAULT trueErrorHeapDumpPath DEFAULT trueCMSAbortablePrecleanW 100 DEFAULT trueaitMillisCMSWaitDuration 2000 DEFAULT trueCMSTriggerInterval -1 DEFAULT truePrintGC false DEFAULT truePrintGCDetails true MANAGEMENT truePrintGCDateStamps false DEFAULT truePrintGCTimeStamps false DEFAULT truePrintGCID false DEFAULT truePrintClassHistogramBe false DEFAULT trueforeFullGCPrintClassHistogramAf false DEFAULT trueterFullGCPrintClassHistogram false DEFAULT trueMinHeapFreeRatio 0 DEFAULT trueMaxHeapFreeRatio 100 DEFAULT truePrintConcurrentLocks false DEFAULT true
更新指定的option
$ vmoption PrintGC true
Successfully updated the vm option.NAME BEFORE-VALUE AFTER-VALUE
------------------------------------PrintGC false true
getstatic
通过 getstatic 命令可以方便的查看类的静态属性。使用方法为getstatic class_name field_name
$ getstatic demo.MathGame random
field: random
@Random[serialVersionUID=@Long[3905348978240129619],seed=@AtomicLong[120955813885284],multiplier=@Long[25214903917],addend=@Long[11],mask=@Long[281474976710655],DOUBLE_UNIT=@Double[1.1102230246251565E-16],BadBound=@String[bound must be positive],BadRange=@String[bound must be greater than origin],BadSize=@String[size must be non-negative],seedUniquifier=@AtomicLong[-3282039941672302964],nextNextGaussian=@Double[0.0],haveNextNextGaussian=@Boolean[false],serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3],unsafe=@Unsafe[sun.misc.Unsafe@2eaa1027],seedOffset=@Long[24],
]
ognl
执行 ognl 表达式
参数说明
参数名称 | 参数说明 |
---|---|
express | 执行的表达式 |
[c:] | 执行表达式的 ClassLoader 的 hashcode,默认值是 SystemClassLoader |
[classLoaderClass:] | 指定执行表达式的 ClassLoader 的 class name |
[x] | 结果对象的展开层次,默认值 1 |
调用静态函数
$ ognl '@java.lang.System@out.println("hello")'
null
获取静态函数字段
$ ognl '@demo.MathGame@random'
@Random[serialVersionUID=@Long[3905348978240129619],seed=@AtomicLong[125451474443703],multiplier=@Long[25214903917],addend=@Long[11],mask=@Long[281474976710655],DOUBLE_UNIT=@Double[1.1102230246251565E-16],BadBound=@String[bound must be positive],BadRange=@String[bound must be greater than origin],BadSize=@String[size must be non-negative],seedUniquifier=@AtomicLong[-3282039941672302964],nextNextGaussian=@Double[0.0],haveNextNextGaussian=@Boolean[false],serialPersistentFields=@ObjectStreamField[][isEmpty=false;size=3],unsafe=@Unsafe[sun.misc.Unsafe@28ea5898],seedOffset=@Long[24],
]
来源
Arthas官网