VisualVM 简介:一个轻量级的Java进程监控软件
VisualVM 安装介绍(Mac 使用 brew 安装)
➜ ~ brew uninstall visualvm==> Uninstalling Cask visualvm
==> Backing App 'VisualVM.app' up to '/opt/homebrew/Caskroom/visualvm/2.1.10/VisualVM.app'
==> Removing App '/Applications/VisualVM.app'
==> Purging files for version 2.1.10 of Cask visualvm
==> Autoremoving 2 unneeded formulae:
groonga
protobuf
Uninstalling /opt/homebrew/Cellar/groonga/13.0.5... (905 files, 82.6MB)
Uninstalling /opt/homebrew/Cellar/protobuf/24.3... (395 files, 13.2MB)
➜ ~ brew install visualvm ==> Caveats
visualvm requires Java. You can install the latest version with:brew install --cask temurin==> Downloading https://github.com/oracle/visualvm/releases/download/2.1.10/VisualVM_2110.dmg
Already downloaded: /Users/malin/Library/Caches/Homebrew/downloads/bce3b75b8ee0760bfa4ea868a367248018724998ad715cfb8ede21fa5d9effae--VisualVM_2110.dmg
==> Installing Cask visualvm
==> Moving App 'VisualVM.app' to '/Applications/VisualVM.app'
🍺 visualvm was successfully installed!
准备一个被监控的Java服务(部署到远程机器)
[root@172-26-51-193 ~]# java -Dcom.sun.management.jmxremote \
> -Dcom.sun.management.jmxremote.port=9010 \
> -Dcom.sun.management.jmxremote.authenticate=false \
> -Dcom.sun.management.jmxremote.ssl=false \
> -Dcom.sun.management.jmxremote.rmi.port=9010 \
> -jar mock-http-endpoint.jar
检查服务是否生效(远程环境)
看到 jinfo 输出项中存在jmx加入的参数即可
[root@172-26-51-193 ~]# jps -l
219299 org.apache.catalina.startup.Bootstrap
432498 mock-http-endpoint.jar
432825 sun.tools.jps.Jps
[root@172-26-51-193 ~]# jinfo -flags 432498
Attaching to process ID 432498, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.332-b09
Non-default VM flags: -XX:CICompilerCount=12 -XX:InitialHeapSize=524288000 -XX:+ManagementServer -XX:MaxHeapSize=8378122240 -XX:MaxNewSize=2792357888 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=174587904 -XX:OldSize=349700096 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
Command line: -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.rmi.port=9010
检查端口是否正常9010(远程环境)
[root@172-26-51-193 ~]# lsof -i:9010
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 432498 root 15u IPv6 106323314 0t0 TCP *:sdr (LISTEN)
客户端检查是否可达(客户端)
➜ ~ telnet 172.26.51.193 9010
Trying 172.26.51.193...
Connected to 172.26.51.193.
Escape character is '^]'.
远程检查是否有 防火墙 或 iptables 的限制
# 检查防火墙状态
firewall-cmd --state# 允许 9010 端口
firewall-cmd --zone=public --add-port=9010/tcp --permanent# 重新加载防火墙配置
firewall-cmd --reload# iptables 检查
iptables -nvL# 如何没有允许规则添加即可
sudo iptables -I INPUT -p tcp --dport 9010 -j ACCEPT
最终效果