可以运用jdk工具监控java应用性能,再配合 jmeter 进行了一个长时间的加压,在加压过程中重点关注了系统资源的使用情况

D:\Program Files (x86)\Java\jdk1.8.0_111\bin

这个目录下的工具

jps - Lists the instrumented Java Virtual Machines (JVMs) on the target system
jarsigner - Signs and verifies Java Archive (JAR) files.

=================================
jconsole

本地进程
远程进程

=================================
java mission control
jmc
=================================
jvisualVM

本地
远程
jstatd连接

jmx连接
两种地址
1、ip:port
2、jmx service url (service:jmx:rmi:///jndi/rmi://192.168.3.15:9999/jmxrmi)
service:jmx:rmi:///jndi/rmi://localhost:7091/jmxrmi
service:jmx:rmi:///jndi/rmi://<hostname>/jmxrmi

另外我们还可以为VisualVM安装一些插件,比如GC,MBeans等等。满足自己的需要。
=================================
jstatd
jstatd是一个rmi的server应用,用于监控jvm的创建和结束,并且提供接口让监控工具可以远程连接到本机的jvm 。jstatd位于 $JAVA_HOME/bin目录下
jstatd是一个监控 JVM 从创建到销毁过程中资源占用情况并提供远程监控接口的 RMI ( Remote Method Invocation ,远程方法调用)服务器程序,它是一个 Daemon 程序,要保证远程监控软件连接到本地的话需要 jstatd 始终保持运行。

jmx
JMX:Java Management Extensions ,即 Java 管理扩展 , 是一个为应用程序、设备、系统等植入管理功能的框架。 JMX 可以跨越一系列异构操作系统平台、系统体系结构和网络传输协议,灵活的开发无缝集成的系统、网络和服务管理应用 。而Visual VM是通过 JMX 来和远程 Java 应用联系的
=================================

在需要被监控的服务器上面,通过jstatd来启动RMI服务

新建文件,编辑内容,启动守护,再visualVM添加jstatd连接
[root@localhost bin]# pwd
/root/jdk1.8.0_144/bin

jstatd运行需要通过 -J-Djava.security.policy=*** 指定安全策略,因此我们需要在服务器上建立一个指定安全策略的文件jstatd.all.policy ,文件内容如下:

[root@localhost bin]# cat jstatd.all.policy
grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};

grant codebase "file:${java.home}/../lib/tools.jar" {
permission java.security.AllPermission;
};

上面内容格式不正确,可能导致不能正常连接

看man jstatd,里面都有解释

       -Joption
Passes option to the JVM, where option is one of the options described on the reference page for the Java application launcher. For example, -J-
Xms48m sets the startup memory to MB. See java().

[root@localhost bin]# ./jstatd -J-Djava.security.policy=jstatd.all.policy
默认就是1099

jstatd -J-Djava.security.policy=/root/jstatd.policy -p 2099

要使Java VisualVM 成功连接到远程服务器上,服务器端应该在 /etc/hosts 文件中把本机地址设为本机的 IP 地址。使用 hostname -i 命令查看,如果显示的是 127.0.0.1 或者与本机实际 IP 不一致的话,需要把 /etc/hosts 文件中相应的地址改为本机实际 IP 。

[root@localhost ~]# jstatd -J-Djava.security.policy=/root/jdk1.8.0_144/bin/jstatd.all.policy -J-Djava.rmi.server.logCalls=true
Jun 17, 2019 2:43:02 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(1)-127.0.0.1: [127.0.0.1: sun.rmi.registry.RegistryImpl[0:0:0, 0]: void rebind(java.lang.String, java.rmi.Remote)]
Jun 17, 2019 2:43:02 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(2)-127.0.0.1: [127.0.0.1: sun.rmi.transport.DGCImpl[0:0:0, 2]: java.rmi.dgc.Lease dirty(java.rmi.server.ObjID[], long, java.rmi.dgc.Lease)]
Jun 17, 2019 2:43:02 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-192.168.3.169: [192.168.3.169: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Jun 17, 2019 2:43:07 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(3)-192.168.3.169: [192.168.3.169: sun.rmi.registry.RegistryImpl[0:0:0, 0]: java.rmi.Remote lookup(java.lang.String)]
Jun 17, 2019 2:43:11 PM sun.rmi.server.UnicastServerRef logCall
上面是没有改hosts文件时的console输出
下面是改后的console输出
FINER: RMI TCP Connection(4)-192.168.3.169: [192.168.3.169: sun.tools.jstatd.RemoteVmImpl[-6199bad7:16b6432834d:-7ff8, 7381047654591843568]: public abstract byte[] sun.jvmstat.monitor.remote.RemoteVm.getBytes() throws java.rmi.RemoteException]
Jun 17, 2019 2:51:01 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(4)-192.168.3.169: [192.168.3.169: sun.tools.jstatd.RemoteVmImpl[-6199bad7:16b6432834d:-7ff2, 5427747741497180388]: public abstract byte[] sun.jvmstat.monitor.remote.RemoteVm.getBytes() throws java.rmi.RemoteException]
Jun 17, 2019 2:51:01 PM sun.rmi.server.UnicastServerRef logCall
FINER: RMI TCP Connection(4)-192.168.3.169: [192.168.3.169: sun.tools.jstatd.RemoteHostImpl[-6199bad7:16b6432834d:-7fff, 8336527158749228898]: public abstract int[] sun.jvmstat.monitor.remote.RemoteHost.activeVms() throws java.rmi.RemoteException,sun.jvmstat.monitor.MonitorException]
Jun 17, 2019 2:51:01 PM sun.rmi.server.UnicastServerRef logCall

=================================

jps

pid java应用主类名称
[root@test1 ~]# jps
5729 Bootstrap
5782 Jstatd

PID: 5782
Host: 192.168.3.15
Main class: sun.tools.jstatd.Jstatd

PID: 5729
Host: 192.168.3.15
Main class: org.apache.catalina.startup.Bootstrap

[root@test1 bin]# jps
Bootstrap
Jps
[root@test1 bin]# jps -q [root@test1 bin]# jps -l
org.apache.catalina.startup.Bootstrap
sun.tools.jps.Jps
[root@test1 bin]# jps -m
Bootstrap start
Jps -m
[root@test1 bin]# jps -lm
org.apache.catalina.startup.Bootstrap start
sun.tools.jps.Jps -lm
[root@test1 bin]# jps -v
Bootstrap -Djava.util.logging.config.file=/root/apache-tomcat-8.5./conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize= -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.3.15 -Dcom.sun.management.jmxremote.port= -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcatalina.base=/root/apache-tomcat-8.5. -Dcatalina.home=/root/apache-tomcat-8.5. -Djava.io.tmpdir=/root/apache-tomcat-8.5./temp
Jps -Dapplication.home=/root/jdk1..0_144 -Xms8m
[root@test1 bin]# jps -lvm
org.apache.catalina.startup.Bootstrap start -Djava.util.logging.config.file=/root/apache-tomcat-8.5./conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize= -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.3.15 -Dcom.sun.management.jmxremote.port= -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcatalina.base=/root/apache-tomcat-8.5. -Dcatalina.home=/root/apache-tomcat-8.5. -Djava.io.tmpdir=/root/apache-tomcat-8.5./temp
sun.tools.jps.Jps -lvm -Dapplication.home=/root/jdk1..0_144 -Xms8m

=================================

为tomcat 配置 jvm 启动参数,以便监控

CATALINA_OPTS="$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.3.225
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false"

==================================
[root@test1 bin]# jps
Bootstrap
Jps
得到pid jstat - Monitors Java Virtual Machine (JVM) statistics. [root@test1 bin]# jstat -help
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. [root@test1 bin]# jstat -options
-class
-compiler
-gc
-gccapacity
-gccause
-gcmetacapacity
-gcnew
-gcnewcapacity
-gcold
-gcoldcapacity
-gcutil
-printcompilation
得到options [root@test1 bin]# jstat -compiler
Compiled Failed Invalid Time FailedType FailedMethod
9.06
[root@test1 bin]# jstat -gc
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
18432.0 20480.0 480.0 0.0 103936.0 12717.6 142336.0 11663.3 20736.0 19683.0 2560.0 2207.3 0.178 0.033 0.211
[root@test1 bin]# jstat -gcutil
S0 S1 E O M CCS YGC YGCT FGC FGCT GCT
2.60 0.00 12.27 8.19 94.92 86.22 0.178 0.033 0.211 ============================================
jstack - Prints Java thread stack traces for a Java process, core file, or remote debug server. [root@test1 bin]# jstack
Usage:
jstack [-l] <pid>
(to connect to running process)
jstack -F [-m] [-l] <pid>
(to connect to a hung process)
jstack [-m] [-l] <executable> <core>
(to connect to a core file)
jstack [-m] [-l] [server_id@]<remote server IP or hostname>
(to connect to a remote debug server) Options:
-F to force a thread dump. Use when jstack <pid> does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message [root@test1 bin]# jstack -l
-- ::
Full thread dump Java HotSpot(TM) -Bit Server VM (25.144-b01 mixed mode): "Attach Listener" # daemon prio= os_prio= tid=0x00007f5f3c013800 nid=0x1928 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE Locked ownable synchronizers:
- None

java二进制工具的更多相关文章

  1. java开发工具比较(16个工具修订版)

    1.JDK (Java Development Kit)Java开发工具集 SUN的Java不仅提了一个丰富的语言和运行环境,而且还提了一个免费的Java开发工具集(JDK).开发人员和最终用户可以利 ...

  2. 十四种Java开发工具点评

    在计算机开发语言的历史中,从来没有哪种语言象Java那样受到如此众多厂商的支持,有如此多的开发工具,Java菜鸟们如初入大观园的刘姥姥,看花了眼,不知该何种选择.的确,这些工具各有所长,都没有绝对完美 ...

  3. Java开发工具全面比较

    1.JDK (Java Development Kit)Java开发工具集 从初学者角度来看Java开发工具,采用JDK开发Java程序能够很快理解程序中各部分代码之间的关系,有利于理解Java面向对 ...

  4. Java效率工具Lombok使用与原理

    Java效率工具Lombok使用与原理 我个人觉得 Lombok是一个优化Java代码以及提升开发效率不错的工具.Lombok 的Github地址为:https://github.com/rzwits ...

  5. 【转】高效Java编程工具集锦

    原文地址:http://geek.csdn.net/news/detail/57469 Java 开发者常常都会想办法如何更快地编写 Java 代码,让编程变得更加轻松.目前,市面上涌现出越来越多的高 ...

  6. Java开发工具安装步骤内容如下

    Java开发工具安装步骤内容如下 安装 开发工具 STS 链接下载网址 eclipse 链接下载网址 JDK安装 jdk链接下载地址 Marven环境 marven链接下载地址 Tomcat tomc ...

  7. Java 二进制与十六进制转换

    Java 二进制与十六进制转换 二进制转换十六进制 /** * @description 将二进制转换成16进制 * * @param buf * @return */ public static S ...

  8. JAVA开发工具eclipse中@author怎么改

    1:JAVA开发工具eclipse中@author怎么改,开发的时候为了注明版权信息. 用eclipse开发工具默认的是系统用户,那么怎么修改呢 示例如图所示 首先打开Eclipse--->然后 ...

  9. Java Properties工具类详解

    1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...

随机推荐

  1. JMeter函数整理

    "_intSum” 功能:用于计算多个整数的和,可以是计算正整数和负整数的和,它有N个参数,最少有3个参数,最多不限.最后一个参数是函数名称,前面的其它参数是要求和的整数.这个函数在函数对话 ...

  2. [AWS - EC2]如何使用 PuTTY 连接到 Amazon Linux 2 实例。How to Connect Amazon Linux 2 Instance from Windows Using PuTTY

    1. 下载 PuTTY 2. 安装到任意目录 3. 打开 PuTTYgen (注意不是 PuTTY), 如图: 选择 RSA , 点击 Load. 找到从 AWS 创建实例的时候生成的 key,要选择 ...

  3. python小练手题1

    1. """ Write a program which can compute the factorial of a given numbers. The result ...

  4. Myeclipse中左边的项目目录没了

    切换一下Perspective, java, resource都有项目窗口 具体的 Window->Open Perspective 如果项目窗口被关了的话 windows->show v ...

  5. 喜大普奔!.NET界面控件DevExpress v19.2发布,快来下载体验

    DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...

  6. 源码安装 qemu-2.0.0 及其依赖 glib-2.12.12

    源码安装qemu-2.0.0 下载源代码并解压 http://wiki.qemu-project.org/download/qemu-2.0.0.tar.bz2 .tar.gz 编译及安装: cd q ...

  7. [学习笔记] 平衡树——Treap

    前置技能:平衡树前传:BST 终于学到我们喜闻乐见的平衡树啦! 所以我们这次讲的是平衡树中比较好写的\(Treap\). (以后会写splay的先埋个坑在这) 好了,进入正题. step 1 我们知道 ...

  8. JavaScript关系运算符

    ★关系运算符 通过关系运算符可以比较两个值之间的大小关系 如果关系成立它会返回true,如果关系不成立立即返回false   ㈠大于号 (>) ⑴判断符号左侧的值是否大于右侧的值 ⑵如果关系成立 ...

  9. 简单的c程序分析

    1.裸函数 c语言的普通函数中即使什么都不写,编译器在编译时也会给它加上一些汇编代码:比如开栈.返回等: 裸函数就是编译器什么都不管,一切都需要自己来处理: 裸函数的优点是自由度高,可以应用在钩子程序 ...

  10. [Linux]ubuntu16.04 nginx彻底删除与重新安装

    nginx彻底删除与重新安装 查看nginx正在运行的进程,如果有就kill掉 sudo netstat -ntlp | grep nginx sudo kill -9 进程id 删除nginx,pu ...