1. 程式人生 > >jconsole 和jvisualVM 監控遠程 spring boot程序

jconsole 和jvisualVM 監控遠程 spring boot程序

inf active src con 服務 nohup 端口 man boot

監控java 程序 增加啟動參數

java \

-Djava.rmi.server.hostname=192.168.2.39 \

-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=1099 \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
-jar /root/app/data-test-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev >nohup 2>&1 &

由於啟動參數過長,我們可以定義系統環境變量來表示 在/etc/profile 最後一行增加

export JAVA_OPTS=‘-Djava.rmi.server.hostname=192.168.2.39 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false‘

然後 source /etc/profile 是文件生效。

啟動時我們就可以用 nohup java $JAVA_OPTS -jar /root/app/data-center-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev >nohup 2>&1 & 這個腳本。

JMX端口為1099 ;

如果不設置服務器主機名 -Djava.rmi.server.hostname 到時候可能連不上。

1.在本機命令行輸入jconsole命令調出界面

在遠程進程中 輸入 主機名:端口號即可
技術分享圖片

2.jvisualvm 首先建立遠程連接,在新建好的遠程連接右擊,創建jmx連接

技術分享圖片

jconsole 和jvisualVM 監控遠程 spring boot程序