1.查询java相关进程
代码语言:javascript复制ps -ef | grep java
2. jinfo
查看java程序运行的环境参数,包括Java System属性和JVM命令行参数.。
代码语言:javascript复制[root@jr-test ~]# jinfo 28843
Attaching to process ID 28843, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.201-b09
Java System Properties:
java.runtime.name = Java(TM) SE Runtime Environment
java.vm.version = 25.201-b09
sun.boot.library.path = /usr/local/jdk1.8/jre/lib/amd64
java.protocol.handler.pkgs = org.springframework.boot.loader
java.vendor.url = http://java.oracle.com/
java.vm.vendor = Oracle Corporation
path.separator = :
file.encoding.pkg = sun.io
java.vm.name = Java HotSpot(TM) 64-Bit Server VM
sun.os.patch.level = unknown
sun.java.launcher = SUN_STANDARD
user.country = CN
user.dir = /home/fsp/servers
java.vm.specification.name = Java Virtual Machine Specification
PID = 28843
java.runtime.version = 1.8.0_201-b09
java.awt.graphicsenv = sun.awt.X11GraphicsEnvironment
os.arch = amd64
java.endorsed.dirs = /usr/local/jdk1.8/jre/lib/endorsed
org.jboss.logging.provider = slf4j
line.separator =
java.io.tmpdir = /tmp
java.vm.specification.vendor = Oracle Corporation
os.name = Linux
LOG_LEVEL_PATTERN = %5p [fsp-credit,%X{X-B3-TraceId:-},%X{X-B3-SpanId:-},%X{X-Span-Export:-}]
sun.jnu.encoding = UTF-8
java.library.path = /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
spring.beaninfo.ignore = true
sun.nio.ch.bugLevel =
java.specification.name = Java Platform API Specification
java.class.version = 52.0
apollo.meta = http://192.168.173.152:8081
sun.management.compiler = HotSpot 64-Bit Tiered Compilers
os.version = 3.10.0-957.10.1.el7.x86_64
user.home = /root
user.timezone = Asia/Shanghai
catalina.useNaming = false
java.awt.printerjob = sun.print.PSPrinterJob
file.encoding = UTF-8
@appId = fsp-credit
java.specification.version = 1.8
catalina.home = /tmp/tomcat.3369909202060990389.8860
user.name = root
java.class.path = credit-web-1.0-RELEASE.jar
java.vm.specification.version = 1.8
sun.arch.data.model = 64
sun.java.command = credit-web-1.0-RELEASE.jar --eureka.client.service-url.defaultZone=http://192.168.173.95:8761/eureka/ --apollo.meta=http://192.168.173.152:8081 --spring.profiles.active=qa --spring.cloud.config.profile=qa --spring.cloud.config.label=qa --jasypt.encryptor.password=bd154!*74e-9fba0-1fe1a
java.home = /usr/local/jdk1.8/jre
user.language = zh
java.specification.vendor = Oracle Corporation
awt.toolkit = sun.awt.X11.XToolkit
java.vm.info = mixed mode
java.version = 1.8.0_201
java.ext.dirs = /usr/local/jdk1.8/jre/lib/ext:/usr/java/packages/lib/ext
sun.boot.class.path = /usr/local/jdk1.8/jre/lib/resources.jar:/usr/local/jdk1.8/jre/lib/rt.jar:/usr/local/jdk1.8/jre/lib/sunrsasign.jar:/usr/local/jdk1.8/jre/lib/jsse.jar:/usr/local/jdk1.8/jre/lib/jce.jar:/usr/local/jdk1.8/jre/lib/charsets.jar:/usr/local/jdk1.8/jre/lib/jfr.jar:/usr/local/jdk1.8/jre/classes
java.awt.headless = true
java.vendor = Oracle Corporation
catalina.base = /tmp/tomcat.3369909202060990389.8860
file.separator = /
java.vendor.url.bug = http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding = UnicodeLittle
sun.font.fontmanager = sun.awt.X11FontManager
sun.cpu.endian = little
sun.cpu.isalist =
VM Flags:
Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=325058560 -XX:MaxHeapSize=325058560 -XX:MaxNewSize=108003328 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=108003328 -XX:OldSize=217055232 -XX: UseCompressedClassPointers -XX: UseCompressedOops -XX: UseFastUnorderedTimeStamps -XX: UseParallelGC
Command line: -Xmx310m -Xms310m
3.jmap
查看运行中的jvm物理内存的占用情况。 参数如下: -heap :打印jvm heap的情况 -histo: 打印jvm heap的直方图。其输出信息包括类名,对象数量,对象占用大小。 -histo:live : 同上,但是只答应存活对象的情况 -permstat: 打印permanent generation heap情况 1.查看jvm heap的情况 jmap -heap 28843
代码语言:javascript复制[root@jr-test ~]# jmap -heap 28843
Attaching to process ID 28843, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.201-b09
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100
MaxHeapSize = 325058560 (310.0MB)
NewSize = 108003328 (103.0MB)
MaxNewSize = 108003328 (103.0MB)
OldSize = 217055232 (207.0MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
PS Young Generation
Eden Space:
capacity = 100663296 (96.0MB)
used = 33428584 (31.879981994628906MB)
free = 67234712 (64.1200180053711MB)
33.20831457773844% used
From Space:
capacity = 3670016 (3.5MB)
used = 852544 (0.81304931640625MB)
free = 2817472 (2.68695068359375MB)
23.22998046875% used
To Space:
capacity = 3670016 (3.5MB)
used = 0 (0.0MB)
free = 3670016 (3.5MB)
0.0% used
PS Old Generation
capacity = 217055232 (207.0MB)
used = 70369184 (67.10928344726562MB)
free = 146686048 (139.89071655273438MB)
32.41994369433122% used
38863 interned Strings occupying 4582536 bytes.
2.查看存活的对象 jmap -histo:live 28843
可以找找自己的对象
4.jstat 参数如下: -class:统计class loader行为信息 -compile:统计编译行为信息 -gc:统计jdk gc时heap信息 -gccapacity:统计不同的generations(不知道怎么翻译好,包括新生区,老年区,permanent区)相应的heap容量情况 -gccause:统计gc的情况,(同-gcutil)和引起gc的事件 -gcnew:统计gc时,新生代的情况 -gcnewcapacity:统计gc时,新生代heap容量 -gcold:统计gc时,老年区的情况 -gcoldcapacity:统计gc时,老年区heap容量 -gcpermcapacity:统计gc时,permanent区heap容量 -gcutil:统计gc时,heap情况
jstat -gcnew 28843 1000 10 统计gc时新生代的情况,每间隔1000ms统计一次,共统计10次
代码语言:javascript复制[root@jr-test /]# jstat -gc 28843
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
3584.0 3584.0 0.0 0.0 98304.0 1759.5 211968.0 67101.6 98856.0 95696.7 11688.0 11087.4 259 1.750 7 1.763 3.513
[root@jr-test /]# jstat -gcnew 28843
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1767.8 259 1.750
[root@jr-test /]# jstat -class 28843 1000 5
Loaded Bytes Unloaded Bytes Time
16778 31214.1 139 202.3 16.56
16778 31214.1 139 202.3 16.56
16778 31214.1 139 202.3 16.56
16778 31214.1 139 202.3 16.56
16778 31214.1 139 202.3 16.56
[root@jr-test /]# jstat -gcnew 28843 1000 10
S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
3584.0 3584.0 0.0 0.0 15 15 3584.0 98304.0 1878.9 259 1.750
5.jstack
代码语言:javascript复制[root@jr-test /]# jstack 28843
"container-0" #20 prio=5 os_prio=0 tid=0x00007f0321b90000 nid=0x7275 waiting on condition [0x00007f0300805000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:427)
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer$1.run(TomcatEmbeddedServletContainer.java:177)
"ContainerBackgroundProcessor[StandardEngine[Tomcat]]" #19 daemon prio=5 os_prio=0 tid=0x00007f0321bf2800 nid=0x7274 waiting on condition [0x00007f0300906000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1355)
at java.lang.Thread.run(Thread.java:748)
"logback-2" #14 daemon prio=5 os_prio=0 tid=0x00007f03202d0800 nid=0x715e waiting on condition [0x00007f03030db000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000000ed0e3be0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1088)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
"Service Thread" #8 daemon prio=9 os_prio=0 tid=0x00007f032018f800 nid=0x70e7 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C1 CompilerThread2" #7 daemon prio=9 os_prio=0 tid=0x00007f0320184800 nid=0x70e6 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread1" #6 daemon prio=9 os_prio=0 tid=0x00007f0320182800 nid=0x70e5 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" #5 daemon prio=9 os_prio=0 tid=0x00007f032017f800 nid=0x70e4 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" #4 daemon prio=9 os_prio=0 tid=0x00007f032017e000 nid=0x70e3 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" #3 daemon prio=8 os_prio=0 tid=0x00007f032014b000 nid=0x70e2 in Object.wait() [0x00007f0303bfa000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
- locked <0x00000000eca334b8> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)
"Reference Handler" #2 daemon prio=10 os_prio=0 tid=0x00007f0320148800 nid=0x70e1 in Object.wait() [0x00007f0303cfb000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:502)
at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
- locked <0x00000000eca1a940> (a java.lang.ref.Reference$Lock)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)
"VM Thread" os_prio=0 tid=0x00007f032013e800 nid=0x70e0 runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x00007f032001e800 nid=0x70db runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x00007f0320020800 nid=0x70dd runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x00007f0320022800 nid=0x70de runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x00007f0320024000 nid=0x70df runnable
"VM Periodic Task Thread" os_prio=0 tid=0x00007f0320192800 nid=0x70e8 waiting on condition
JNI global references: 329
6.jstat
代码语言:javascript复制Usage: jstat -help|-options
jstat -<option> [-t] [-h<lines>] <vmid> [<interval> [<count>]]
Definitions:
<option> An option reported by the -options option
<vmid> Virtual Machine Identifier. A vmid takes the following form:
<lvmid>[@<hostname>[:<port>]]
Where <lvmid> is the local vm identifier for the target
Java virtual machine, typically a process id; <hostname> is
the name of the host running the target Java virtual machine;
and <port> is the port number for the rmiregistry on the
target host. See the jvmstat documentation for a more complete
description of the Virtual Machine Identifier.
<lines> Number of samples between header lines.
<interval> Sampling interval. The following forms are allowed:
<n>["ms"|"s"]
Where <n> is an integer and the suffix specifies the units as
milliseconds("ms") or seconds("s"). The default units are "ms".
<count> Number of samples to take before terminating.
-J<flag> Pass <flag> directly to the runtime system.
使用实例 jstat -gcutil 28843 2000 20 查看jc情况,间隔2000ms,统计20次
代码语言:javascript复制[root@jr-test /]# jstat -gcutil 28843
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 8.86 31.66 96.80 94.86 259 1.750 7 1.763 3.513
[root@jr-test /]# jstat -gcutil 28843 2000 20
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
0.00 0.00 10.74 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 10.74 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 10.74 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.34 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.34 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.34 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.34 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.38 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.39 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.40 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.40 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.40 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.40 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.40 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
0.00 0.00 11.41 31.66 96.80 94.86 259 1.750 7 1.763 3.513
参数解释:
Options — 选项,我们一般使用 -gcutil 查看gc 情况
vmid — VM 的进程号,即当前运行的java 进程号
interval– 间隔时间,单位为秒或者毫秒
count — 打印次数,如果缺省则打印无数次
S0 — Heap 上的 Survivor space 0 区已使用空间的百分比 S1 — Heap 上的 Survivor space 1 区已使用空间的百分比 E — Heap 上的 Eden space 区已使用空间的百分比 O — Heap 上的 Old space 区已使用空间的百分比 P — Perm space 区已使用空间的百分比 YGC — 从应用程序启动到采样时发生 Young GC 的次数 YGCT– 从应用程序启动到采样时 Young GC 所用的时间( 单位秒 ) FGC — 从应用程序启动到采样时发生 Full GC 的次数 FGCT– 从应用程序启动到采样时 Full GC 所用的时间( 单位秒 ) GCT — 从应用程序启动到采样时用于垃圾回收的总时间( 单位秒)
代码语言:javascript复制[root@jr-test /]# jstat -gccapacity 28843
NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC MCMN MCMX MC CCSMN CCSMX CCSC YGC FGC
105472.0 105472.0 105472.0 3584.0 3584.0 98304.0 211968.0 211968.0 211968.0 211968.0 0.0 1136640.0 98856.0 0.0 1048576.0 11688.0 259 7
3.netstat
-a:列出所有当前的连接; -t:列出tcp协议的连接; -u:列出udp协议的连接; -n:禁用域名解析功能; -l:列出正在监听的连接; -p:查看进程信息,此选项,必须运行在root权限之下; -ep:可以同时查看进程名和用户名,-n 和 -e 选项一起使用,User 列的属性就是用户的 ID 号,而不是用户名; -r:打印内核路由信息;
代码语言:javascript复制[root@jr-test ~]# netstat -tunlep
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 31499895 6452/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 32370 5319/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 0 32709 5717/master
tcp6 0 0 :::8870 :::* LISTEN 0 55745768 29858/java
tcp6 0 0 :::8840 :::* LISTEN 0 61729747 13243/java
tcp6 0 0 :::8810 :::* LISTEN 0 62751531 19181/java
tcp6 0 0 :::3306 :::* LISTEN 999 54846766 23929/mysqld
tcp6 0 0 :::45901 :::* LISTEN 0 47434177 2137/java
tcp6 0 0 :::9999 :::* LISTEN 0 14255557 7835/java
tcp6 0 0 :::8880 :::* LISTEN 0 62703302 7173/java
tcp6 0 0 :::8080 :::* LISTEN 0 36976347 19553/java
tcp6 0 0 :::9777 :::* LISTEN 0 41184824 9276/java
tcp6 0 0 :::8850 :::* LISTEN 0 69728215 21203/java
tcp6 0 0 :::22 :::* LISTEN 0 32372 5319/sshd
tcp6 0 0 :::9880 :::* LISTEN 0 49800052 26632/java
tcp6 0 0 :::8761 :::* LISTEN 0 54847044 21952/java
tcp6 0 0 ::1:25 :::* LISTEN 0 32710 5717/master
tcp6 0 0 :::9850 :::* LISTEN 0 69728189 21203/java
tcp6 0 0 :::8890 :::* LISTEN 0 69672077 6771/java
tcp6 0 0 :::8860 :::* LISTEN 0 62294727 28843/java
tcp6 0 0 :::8830 :::* LISTEN 0 19462602 10242/java
tcp6 0 0 :::7777 :::* LISTEN 0 41198322 9276/java
tcp6 0 0 :::44162 :::* LISTEN 1001 47434383 2935/java
tcp6 0 0 :::8899 :::* LISTEN 0 14254332 7835/java
tcp6 0 0 :::9092 :::* LISTEN 0 47437963 2137/java
tcp6 0 0 :::9860 :::* LISTEN 0 32336444 2933/java
tcp6 0 0 :::2181 :::* LISTEN 1001 47433554 2935/java
参考:https://blog.csdn.net/chenleixing/article/details/43230099 https://www.cnblogs.com/kongzhongqijing/articles/3630264.html