可以运用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. 记录--js中出现的数组排序问题

    这是今天在写vue项目时发生的一个小问题,在此记录一下,方便自己的回顾.项目是前后端分离的,前台主要使用了vue-cli3.0 + mintui,是一个移动端的web app包括了后台发布管理的一些功 ...

  2. another-redis-desktop-manager

    brew cask install another-redis-desktop-manager

  3. 如何对Win10电脑文件夹选项进行设置?

    文件夹选项是Windows系统中非常重要的一个功能,在这里能对电脑内的文件及文件夹进行各种各样的设置以及操作.在Windows系统升级到Win10版本后,许多界面都发生了变化,文件夹选项也是如此,打开 ...

  4. windows漏洞MS03_026

    话不多说,直接进入正题 第一步查看是否能ping通,第二步就是扫描端口,开放了端口才能进行攻击 linux进入msfconsole,搜索03_026 search 03_026 等待一会,返回漏洞的全 ...

  5. HTML实现背景颜色的渐变

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. PHP swoole websocket协议上机指南

    这一上机实验的开发环境用的是jetbrain公司的phpstorm 上级步骤如下: 创建websocket服务端 <?php $server = ); function onopen($serv ...

  7. 【Winfrom-Button】 重写Button,去掉获取焦点时的边框

    Winfrom Button 去掉获取焦点时的边框: 自定义一个Button,重写ShowFocusCues方法 /// <summary> /// 去掉获取焦点的边框 /// </ ...

  8. Python 爬虫十六式 - 第六式:JQuery的假兄弟-pyquery

    PyQuery:一个类似jquery的python库 学习一时爽,一直学习一直爽   Hello,大家好,我是 Connor,一个从无到有的技术小白.上一次我们说到了 BeautifulSoup 美味 ...

  9. SpringBoot项目中,Mybatis的使用

    项目中使用MyBatis的地方很少,可以说是基本不用,慕课网上面这个项目介绍给也就是一些比较简单的使用例子,我用JPA比较的多,MyBatis有两种使用方式 1.导入MyBatis的依赖 <de ...

  10. 征途堆积出友情的永恒「堆优化dp」

    直接写题解: 很简单的dp暴力转移式子:f[i]=MAX{f[j]+max(tax[j],sum[i]-sum[j])} 观察式子,只有一个变量sum[i]; 而其他都为定量; 则考虑维护 两个定量: ...