Windows用戶端的JProfiler遠程監控Linux上的Tomcat

來源:互聯網
上載者:User

1.測試環境
伺服器:RedHat Linux 3.4.3-9.EL4(核心版本 2.6.9-5.EL),Tomcat5.5.20,Sun JDK 1.5.0_09,JProfiler 4.3.2 for linux(安裝包:jprofiler_linux_4_3_2.sh)
用戶端:Windows XP,JProfiler 4.3.2 for windows(安裝包:jprofiler_windows_4_3_2.exe)

2.JProfiler軟體 http://www.ej-technologies.com/

3.用戶端 JProfiler 安裝 略

4.伺服器端 JProfiler 安裝:
把 jprofiler_linux_4.3.2.sh 上傳到到伺服器,假設路徑為 /opt/jprofiler

# cd /opt/jprofiler
# chmod +x *.sh
# ./jprofiler_linux_4.3.2.sh -c
按照提示來安裝,提示都很簡單,不在多說。安裝直接選取 /opt/jprofiler4

注意,這裡的 -c 意思是用字元方式來安裝,如果機器上沒有 X 則加上該參數.

5.用戶端串連配置
1). 運行 JProfiler 。第一次開啟會有嚮導,忽略它。
2). 選擇 Session->Integration Wizard->New Remote Integratation
3). 選擇 On a remote computer;Platform of remote computer 選擇 Linux x86/AMD 64;Next
4). 輸入伺服器 IP ;Next
5). 輸入伺服器上的 jprofiler 的安裝路徑,如 /opt/jprofiler4 ;next
6). 選擇伺服器的 JDK 環境,這裡是:Sun,1.5.0,hotspot;next
7). 輸入連接埠:這裡是預設值 8849;next
8). 選擇啟動模式:這裡選第一種 wait for a connection from the jprofiler GUI;next
9). 這裡會列出需要在伺服器端做的配置:

Integration type: [Generic application]
Selected JVM: Sun 1.5.0 (hotspot)
Startup mode: Wait for JProfiler GUI

(1) Please insert

-agentlib:jprofilerti=port=8849  -Xbootclasspath/a:/opt/jprofiler4/bin/agent.jar

into the start command of your remote application right after the java command.

(2) Please add

/opt/jprofiler4/bin/linux-x86

to the environment variable LD_LIBRARY_PATH.

A remote session named Remote application on 192.168.40.15 will be created that connects to a running instance of the remote application that is started with the modified start command.


6.伺服器端的配置
(1)修改系統內容設定檔 /etc/profile ,增加

JPROFILER_HOME=/opt/jprofiler4/bin/linux-x86
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JPROFILER_HOME

(2)修改TOMCAT開機檔案catalina.sh,添加-agentlib:jprofilerti=port=8849  -Xbootclasspath/a:/opt/jprofiler4/bin/agent.jar 內容到CATALINA_OPTS中;
“-agentlib:jprofilerti=port=8849  -Xbootclasspath/a:/opt/jprofiler4/bin/agent.jar ” 此內容由用戶端軟體產生

CATALINA_OPTS="$CATALINA_OPTS -Xms128m -Xmx128m $JPDA_OPTS -agentlib:jprofilerti=port=8849  -Xbootclasspath/a:/opt/jprofiler4/bin/agent.jar"

7.Reboot Linux and startup Tomcat using startup.sh;
   The log of tomcat which is $CATALINA_HOME/logs/catalina.out will show:

 JProfiler> Protocol version 23
 JProfiler> Using JVMTI
 JProfiler> 32-bit library
 JProfiler> Listening on port: 8849.
 JProfiler> Native library initialized
 JProfiler> Waiting for a connection from the  JProfiler GUI 

 

8.啟動用戶端軟體
   點擊jprofiler菜單 session>start center>Open Session
   Available session configurations中列出了剛才配置的串連,選中使用就OK了!!

9.The log of tomcat which is $CATALINA_HOME/logs/catalina.out will show:

 JProfiler> Using dynamic instrumentation
 JProfiler> Time measurement: elapsed time
 JProfiler> CPU profiling enabled
 JProfiler> Hotspot compiler enabled
 JProfiler> Starting org/apache/catalina/startup/Bootstrap 

 

10.當中斷JProfiler串連時
   The log of tomcat which is $CATALINA_HOME/logs/catalina.out will show:

 JProfiler> Disconnected. Waiting for reconnection.
 JProfiler> Listening on port: 8849.

  經過我的測試發現了有以上一些問題
1、)並不是將-agentlib:jprofilerti=port=8849  -Xbootclasspath/a:/opt/jprofiler4/bin/agent.jar 加入到CATALINA_OPTS 中而是加入到 JAVA_OPTS中,加入格式如下所示:
其餘步同上

  JAVA_OPTS="$JAVA_OPTS "-agentlib:jprofilerti=port=8849 
  JAVA_OPTS="$JAVA_OPTS "-Xbootclasspath/a:/opt/jprofiler5/bin/agent.jar

下面是我採用過的一個完整的配置

if [ -r "$CATALINA_HOME"/bin/tomcat-juli.jar ]; then
  JAVA_OPTS="$JAVA_OPTS "-Xms128m 
  JAVA_OPTS="$JAVA_OPTS "-Xmx256m
  JAVA_OPTS="$JAVA_OPTS "-XX:PermSize=32m 
  JAVA_OPTS="$JAVA_OPTS "-XX:MaxNewSize=128m 
  JAVA_OPTS="$JAVA_OPTS "-XX:MaxPermSize=64m 
    JAVA_OPTS="$JAVA_OPTS "-Dcom.sun.management.jmxremote
  JAVA_OPTS="$JAVA_OPTS "-Dcom.sun.management.jmxremote.port=9009
  JAVA_OPTS="$JAVA_OPTS "-Dcom.sun.management.jmxremote.authenticate=false
  JAVA_OPTS="$JAVA_OPTS "-Dcom.sun.management.jmxremote.ssl=false
  JAVA_OPTS="$JAVA_OPTS "-agentlib:jprofilerti=port=8849  
  JAVA_OPTS="$JAVA_OPTS "-Xbootclasspath/a:/opt/jprofiler5/bin/agent.jar
  JAVA_OPTS="$JAVA_OPTS "-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" "-Djava.util.logging.config.file="$CATALINA_BASE/conf/logging.properties"
fi

 

當時遇到的問題是jconsole無法串連上遠程Linux上的JVM,Google看到Sun官方bugdatabase有人講是bug,就沒再理。今天再次Google,在java.sun.com/j2se/1.5.0/docs/guide/management/faq.html#linux2看到

Run "hostname -i" command. If it reports 127.0.0.1, JConsole would not be able to connect to the JVM running on that Linux machine. To fix this issue, edit /etc/hosts so that the hostname resolves to the host address.

馬上修改/etc/hosts,串連成功了。對於上面提到“在一個jsp中進行while (true);死迴圈”的測試,一個個線程查看,發現有一個Thread在_jspService方法上始終處於Runnable狀態。看來Programmer還是得用Google 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.