使用java自带工具监控jvm运行状态

简介:
1.jps:查看当前运行着的java进程(仿linux下的ps),显示进程号
  2. jinfo: 查参数jinfo -flagPermSize 2208(进程号)
jinfo -flag MaxPermSize 2208(进程号)
C:\Users\WILL>jinfo
Usage:
jinfo <option> <pid>
(to connect to a running process)
where <option> is one of:
-flag <name>         to print the value of the named VM flag
-flag [+|-]<name>    to enable or disable the named VM flag
-flag <name>=<value> to set the named VM flag to the given value
-h | -help           to print this help message
   3. jconsole 2208
  用法:
jconsole [ -interval=n ] [ -notile ] [ -pluginpath <path> ] [ -version ] [ connection ...]
-interval   将更新间隔时间设置为 n 秒(默认值为 4 秒)
-notile     最初不平铺显示窗口(对于两个或更多连接)
-pluginpath 指定 jconsole 用于查找插件的路径
-version    输出程序版本
connection = pid || host:port || JMX URL (service:jmx:<protocol>://...)
pid       目标进程的进程 ID
host      远程主机名或 IP 地址
port      用于远程连接的端口号
-J          对正在运行 jconsole 的 Java 虚拟机指定
  输入参数
   4. jstack  2208列出所有线程,以及线程的运行状态
C:\Users\WILL>jstack
Usage:
jstack [-l] <pid>
(to connect to running process)
Options:
-l  long listing. Prints additional information about locks
-h or -help to print this help message


   5. jstat -gcutil 2208 1000(每隔1000毫秒打印一次信息) 10(打印10行)
C:\Users\WILL>jstat
invalid argument count
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.
  C:\Users\WILL>jstat -options
  -class
  -compiler
  -gc
  -gccapacity
  -gccause
  -gcnew
  -gcnewcapacity
  -gcold
  -gcoldcapacity
  -gcpermcapacity
  -gcutil
  -printcompilation
   6. jmap把虚拟机里运行着的所有文件都down下来,相当于快照
C:\Users\WILL>jmap
Usage:
jmap -histo <pid>
(to connect to running process and print histogram of java object heap
jmap -dump:<dump-options> <pid>
(to connect to running process and dump java heap)
dump-options:
format=b     binary default
file=<file>  dump heap to <file>
Example:       jmap -dump:format=b,file=heap.bin <pid>
   7. jhat 对jmap下来的文件进行分析,多个角度
Usage:  jhat [-stack <bool>] [-refs <bool>] [-port <port>] [-baseline <file>] [-
debug <int>] [-version] [-h|-help] <file>
-J<flag>          Pass <flag> directly to the runtime system. For
example, -J-mx512m to use a maximum heap size of 512MB
-stack false:     Turn off tracking object allocation call stack.
-refs false:      Turn off tracking of references to objects
-port <port>:     Set the port for the HTTP server.  Defaults to 7000
-exclude <file>:  Specify a file that lists data members that should
be excluded from the reachableFrom query.
-baseline <file>: Specify a baseline object dump.  Objects in
both heap dumps with the same ID and same class will
be marked as not being "new".
-debug <int>:     Set debug level.
0:  No debug output
1:  Debug hprof file parsing
2:  Debug hprof file parsing, no server
-version          Report version number
-h|-help          Print this help and exit
<file>            The file to read
For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#<number>" to the file name, i.e. "foo.hprof#3".
All boolean options default to "true"
  图片又不能上传。。。就打印出这些帮助参数来,能看懂得了。


最新内容请见作者的GitHub页:http://qaseven.github.io/


相关文章
|
9月前
|
监控 Java Unix
6个Java 工具,轻松分析定位 JVM 问题 !
本文介绍了如何使用 JDK 自带工具查看和分析 JVM 的运行情况。通过编写一段测试代码(启动 10 个死循环线程,分配大量内存),结合常用工具如 `jps`、`jinfo`、`jstat`、`jstack`、`jvisualvm` 和 `jcmd` 等,详细展示了 JVM 参数配置、内存使用、线程状态及 GC 情况的监控方法。同时指出了一些常见问题,例如参数设置错误导致的内存异常,并通过实例说明了如何排查和解决。最后附上了官方文档链接,方便进一步学习。
1358 4
|
4月前
|
监控 Kubernetes Java
使用 New Relic APM 和 Kubernetes Metrics 监控 EKS 上的 Java 微服务
在阿里云AKS上运行Java微服务常遇性能瓶颈与OOMKilled等问题。本文教你通过New Relic实现集群与JVM双层监控,集成Helm部署、JVM代理注入、GC调优及告警仪表盘,打通从节点资源到应用内存的全链路观测,提升排障效率,保障服务稳定。
265 2
|
5月前
|
安全 Oracle Java
JAVA高级开发必备·卓伊凡详细JDK、JRE、JVM与Java生态深度解析-形象比喻系统理解-优雅草卓伊凡
JAVA高级开发必备·卓伊凡详细JDK、JRE、JVM与Java生态深度解析-形象比喻系统理解-优雅草卓伊凡
424 0
JAVA高级开发必备·卓伊凡详细JDK、JRE、JVM与Java生态深度解析-形象比喻系统理解-优雅草卓伊凡
|
8月前
|
存储 监控 算法
Java程序员必学:JVM架构完全解读
Java 虚拟机(JVM)是 Java 编程的核心,深入理解其架构对开发者意义重大。本文详细解读 JVM 架构,涵盖类加载器子系统、运行时数据区等核心组件,剖析类加载机制,包括加载阶段、双亲委派模型等内容。阐述内存管理原理,介绍垃圾回收算法与常见回收器,并结合案例讲解调优策略。还分享 JVM 性能瓶颈识别与调优方法,分析 Java 语言特性对性能的影响,给出数据结构选择、I/O 操作及并发同步处理的优化技巧,同时探讨 JVM 安全模型与错误处理机制,助力开发者提升编程能力与程序性能。
Java程序员必学:JVM架构完全解读
|
6月前
|
存储 运维 Kubernetes
Java启动参数JVM_OPTS="-Xms512m -Xmx1024m -XX:+HeapDumpOnOutOfMemoryError"
本文介绍了Java虚拟机(JVM)常用启动参数配置,包括设置初始堆内存(-Xms512m)、最大堆内存(-Xmx1024m)及内存溢出时生成堆转储文件(-XX:+HeapDumpOnOutOfMemoryError),用于性能调优与故障排查。
613 0
|
6月前
|
存储 监控 算法
企业上网监控场景下布隆过滤器的 Java 算法构建及其性能优化研究
布隆过滤器是一种高效的数据结构,广泛应用于企业上网监控系统中,用于快速判断员工访问的网址是否为违规站点。相比传统哈希表,它具有更低的内存占用和更快的查询速度,支持实时拦截、动态更新和资源压缩,有效提升系统性能并降低成本。
226 0
|
9月前
|
存储 机器学习/深度学习 监控
如何监控员工的电脑——基于滑动时间窗口的Java事件聚合算法实现探析​
在企业管理场景中,如何监控员工的电脑操作行为是一个涉及效率与合规性的重要课题。传统方法依赖日志采集或屏幕截图,但数据量庞大且实时性不足。本文提出一种基于滑动时间窗口的事件聚合算法,通过Java语言实现高效、低资源占用的监控逻辑,为如何监控员工的电脑提供一种轻量化解决方案。
258 3
|
8月前
|
Arthas 存储 算法
深入理解JVM,包含字节码文件,内存结构,垃圾回收,类的声明周期,类加载器
JVM全称是Java Virtual Machine-Java虚拟机JVM作用:本质上是一个运行在计算机上的程序,职责是运行Java字节码文件,编译为机器码交由计算机运行类的生命周期概述:类的生命周期描述了一个类加载,使用,卸载的整个过类的生命周期阶段:类的声明周期主要分为五个阶段:加载->连接->初始化->使用->卸载,其中连接中分为三个小阶段验证->准备->解析类加载器的定义:JVM提供类加载器给Java程序去获取类和接口字节码数据类加载器的作用:类加载器接受字节码文件。
776 55
|
3月前
|
存储 缓存 Java
我们来说一说 JVM 的内存模型
我是小假 期待与你的下一次相遇 ~
341 5
|
3月前
|
存储 缓存 算法
深入理解JVM《JVM内存区域详解 - 世界的基石》
Java代码从编译到执行需经javac编译为.class字节码,再由JVM加载运行。JVM内存分为线程私有(程序计数器、虚拟机栈、本地方法栈)和线程共享(堆、方法区)区域,其中堆是GC主战场,方法区在JDK 8+演变为使用本地内存的元空间,直接内存则用于提升NIO性能,但可能引发OOM。