java二进制工具
可以运用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二进制工具的更多相关文章
- java开发工具比较(16个工具修订版)
1.JDK (Java Development Kit)Java开发工具集 SUN的Java不仅提了一个丰富的语言和运行环境,而且还提了一个免费的Java开发工具集(JDK).开发人员和最终用户可以利 ...
- 十四种Java开发工具点评
在计算机开发语言的历史中,从来没有哪种语言象Java那样受到如此众多厂商的支持,有如此多的开发工具,Java菜鸟们如初入大观园的刘姥姥,看花了眼,不知该何种选择.的确,这些工具各有所长,都没有绝对完美 ...
- Java开发工具全面比较
1.JDK (Java Development Kit)Java开发工具集 从初学者角度来看Java开发工具,采用JDK开发Java程序能够很快理解程序中各部分代码之间的关系,有利于理解Java面向对 ...
- Java效率工具Lombok使用与原理
Java效率工具Lombok使用与原理 我个人觉得 Lombok是一个优化Java代码以及提升开发效率不错的工具.Lombok 的Github地址为:https://github.com/rzwits ...
- 【转】高效Java编程工具集锦
原文地址:http://geek.csdn.net/news/detail/57469 Java 开发者常常都会想办法如何更快地编写 Java 代码,让编程变得更加轻松.目前,市面上涌现出越来越多的高 ...
- Java开发工具安装步骤内容如下
Java开发工具安装步骤内容如下 安装 开发工具 STS 链接下载网址 eclipse 链接下载网址 JDK安装 jdk链接下载地址 Marven环境 marven链接下载地址 Tomcat tomc ...
- Java 二进制与十六进制转换
Java 二进制与十六进制转换 二进制转换十六进制 /** * @description 将二进制转换成16进制 * * @param buf * @return */ public static S ...
- JAVA开发工具eclipse中@author怎么改
1:JAVA开发工具eclipse中@author怎么改,开发的时候为了注明版权信息. 用eclipse开发工具默认的是系统用户,那么怎么修改呢 示例如图所示 首先打开Eclipse--->然后 ...
- Java Properties工具类详解
1.Java Properties工具类位于java.util.Properties,该工具类的使用极其简单方便.首先该类是继承自 Hashtable<Object,Object> 这就奠 ...
随机推荐
- Linux编译安装GCC
1. 下载gcc安装包 网址:http://ftp.gnu.org/gnu/gcc/ ,下载对应的安装包,我选择gcc-5.5.0.tar.gz 2. 下载依赖库 一个是mpc,一个是gmp,一个是m ...
- 记一次自启动的docker容器将宿主机的开机用户登录界面覆盖事件
宿主机的系统为CentOS7_7.7.1908,默认为GUI启动,安装了宝塔面板,docker-ce为最新版. 在启动了一个centos7的容器(镜像为centos官方镜像)后,将该容器重启策略设置为 ...
- SDU&PDU
SDU(service Data Unit):服务数据单元,又叫业务数据单元,是指定层的用户服务的数据集,传送到接收方的时候同一协议层时数据没有发生变化,即业务部分,然后发给下层之后,下层将其封装在P ...
- 1.opencv_画图
#导入工具包 import numpy as np import cv2 import matplotlib.pyplot as plt # 定义显示图片 def show(image): plt.i ...
- JAVA面试/笔试经典题
1.short s1 = 1; s1 = s1 + 1;有什么错? short s1 = 1; s1 += 1;有什么错? 对于short s1 = 1; s1 = s1 + 1; 由于s1+1运算时 ...
- JS 循环的两种方式
// 1.for循环 for (var i = 0; i <= 10; ++ i) { console.log(i); } // 2.while循环 var i = 0; while (i &l ...
- linux 命令格式和帮助
命令的格式: command [options] [arguments] command:命令 options: --单词全称 或 -单字简称 如: ls --all 等于 ls - ...
- MQTT 入门介绍——菜鸟教程
一.简述 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的"轻量级& ...
- Hadoop-No.7之行键
和哈希表类比,HBase中的行键类似于哈希表中的键.要构造一个良好的HBase模式,关键之一就是选择一个合适的行键. 1 记录检索 行键是HBase中检索记录所使用的键.HBase记录含有的列在数量上 ...
- BZOJ 2157: 旅游 (树链剖分+线段树)
树链剖分后线段树维护区间最大最小值与和. 支持单点修改与区间取反. 直接写个区间取反标记就行了.线段树板题.(200行6000B+ 1A警告) #include <cstdio> #inc ...