Java运行环境JVM GC和线程堆栈查询
JVM相关查询
jps 查看运行中的java进程及其启动类名和参数, JVM参数
jps -lmv
输出
24929 sun.tools.jps.Jps -lmv -Dapplication.home=/home/es/software/jdk1.8.0_181 -Xms8m
19092 ager.jar -Xms16G -Xmx16G -XX:MetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError -Dspring.profiles.active=dev -Duser.timezone=GMT+8
15785 arthas-boot.jar
6105 org.neo4j.server.CommunityEntryPoint --home-dir=/opt/neo4j-community --config-dir=/opt/neo4j-community/conf -Xms10485760k -Xmx10485760k -XX:+UseG1GC -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -XX:+UnlockExperimentalVMOptions -XX:+TrustFinalNonStaticFields -XX:+DisableExplicitGC -XX:MaxInlineLevel=15 -XX:-UseBiasedLocking -Djdk.nio.maxCachedBufferSize=262144 -Dio.netty.tryReflectionSetAccessible=true -Djdk.tls.ephemeralDHKeySize=2048 -Djdk.tls.rejectClientInitiatedRenegotiation=true -XX:FlightRecorderOptions=stackdepth=256 -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints -Dlog4j2.disable.jmx=true -Dfile.encoding=UTF-8
jstat 查看GC情况
# 每隔1000毫秒, 打印 19092 这个进程的jvm的gc情况
jstat -gcutil 19092 1000
输出
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 100.00 79.79 8.90 95.06 85.38 31 2.333 0 0.000 2.333
0.00 100.00 79.79 8.90 95.06 85.38 31 2.333 0 0.000 2.333
0.00 100.00 79.79 8.90 95.06 85.38 31 2.333 0 0.000 2.333
jstack 查看jvm中, 各个线程的堆栈情况, 当一个线程长时间未返回时, 可以通过这个命令查看卡在哪里
# 查看 19092 这个进程下, java各线程的堆栈
jstack -l 19092
输出
"TDO-thread-17" #6669 prio=5 os_prio=0 cpu=4.90ms elapsed=63147.14s tid=0x00007f7e88034000 nid=0x4446 waiting on condition [0x00007f7e76ceb000]
java.lang.Thread.State: WAITING (parking)
at jdk.internal.misc.Unsafe.park(java.base@11/Native Method)
- parking to wait for <0x0000000402abefa0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(java.base@11/LockSupport.java:194)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@11/AbstractQueuedSynchronizer.java:2081)
at java.util.concurrent.LinkedBlockingQueue.take(java.base@11/LinkedBlockingQueue.java:433)
at java.util.concurrent.ThreadPoolExecutor.getTask(java.base@11/ThreadPoolExecutor.java:1054)
at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11/ThreadPoolExecutor.java:1114)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11/ThreadPoolExecutor.java:628)
at java.lang.Thread.run(java.base@11/Thread.java:834)
Locked ownable synchronizers:
- None
"TDO-thread-18" #6670 prio=5 os_prio=0 cpu=0.87ms elapsed=63089.62s tid=0x00007f7e0403f800 nid=0x461e waiting on condition [0x00007f7e75edd000]
java.lang.Thread.State: WAITING (parking)
at jdk.internal.misc.Unsafe.park(java.base@11/Native Method)
- parking to wait for <0x0000000402abefa0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(java.base@11/LockSupport.java:194)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@11/AbstractQueuedSynchronizer.java:2081)
at java.util.concurrent.LinkedBlockingQueue.take(java.base@11/LinkedBlockingQueue.java:433)
at java.util.concurrent.ThreadPoolExecutor.getTask(java.base@11/ThreadPoolExecutor.java:1054)
at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11/ThreadPoolExecutor.java:1114)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11/ThreadPoolExecutor.java:628)
at java.lang.Thread.run(java.base@11/Thread.java:834)
Locked ownable synchronizers:
- None
基础环境查询
综合
# top
top
# 运行时间, 负载
uptime
# virtual memory statistics
vmstat
CPU 相关
# 查看CPU个数
grep "processor" /proc/cpuinfo| wc -l
# 查看所有CPU的负载情况
mpstat
输出
7.x86_64 (anyhost) 07/29/2022 _x86_64(40 CPU)
10:16:56 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
10:16:56 AM all 1.24 0.00 0.17 0.07 0.00 0.00 0.00 0.00 0.00 98.53
内存相关
free -h
输出
total used free shared buff/cache available
Mem: 62G 37G 9.6G 12G 15G 12G
Swap: 0B 0B 0B
磁盘相关, 查看磁盘情况
df -h
du / -d1 -h
磁盘IO情况
iostat -h
输出
Linux 3.10.0-327.el7.x86_64 (anyhost) 07/29/2022 _x86_64(40 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
1.24 0.00 0.17 0.07 0.00 98.53
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 37.37 73.32 799.55 571577817 6233264651
dm-0 29.89 70.40 460.19 548840983 3587664105
dm-1 28.53 0.17 113.95 1303200 888320856
dm-2 32.86 0.14 131.28 1109529 1023466028
dm-3 11.15 2.60 94.13 20292242 733811333
进程和线程
统计各进程及其线程数量, 看程序名和PID
pstree
# 查看各进程及其下面的线程
pstree -p
# 查看指定的进程及其下面的线程
pstree -p pid
查看具体进程, 这样能看到进程的执行参数
ps aux|grep java