mouse 发表于 2018-12-6 10:33:56

jprofiler远程监控tomcat服务器

  写的web程序,有时候可能服务器挂了,要找bug,比较辛苦,有了监控工具就好多了。现记录下 jprofiler 远程监控tomcat的安装,与起步。
  先来说我的环境:客户机,windows/java 1.6/jprofiler 5.1.2。可以看另一篇文章:jprofiler 试用 。
  
服务器:centos 5.1/java 1.6/jprofiler 5.1.2。下载linux版:http://download.ej-technologies.com/jprofiler/jprofiler_linux_5_1_2.tar.gz
  1、下载并安装,其实直接解压就得了。
  

  
# pwd
  
/usr/local
  
# wget http://download.ej-technologies.com/jprofiler/jprofiler_linux_5_1_2.tar.gz
  
# tar zxf jprofiler_linux_5_1_2.tar.gz
  

  2、打开windows中的jprofiler,配置远程的session。
  2.1、Shift+F1打开“QuickStart"对话框,选择“An application server, locally or remotely”,然后“Next”,如图:
http://blog.chenlb.com/wp-content/uploads/2008/11/quick-start.jpg
  2.2、选择服务器为:Apache Tomcat 6.x,Next,然后选择“On a remote computer”,再选择“Linux X86/AMD64”。
  2.3、Next,输入远程机子IP地址,我这里是:Remote address 192.168.1.80。Next,输入远程jprofiler5的安装目录,我这里是Installation directory /user/local/jprofiler5
  2.4、Next,输入本地tomcat的启动脚本,如:M:\apache-tomcat-6.0.18\bin\startup.sh。其实jprofiler是根据startup.sh生成新的启动脚本,新的脚本加了一些参数,如图。
http://blog.chenlb.com/wp-content/uploads/2008/11/select-local-tomcat-startup-sh-600x415.jpg
  2.5、Next,选择JVM版,如:JVM Vender Sun,Version 1.6.0,Mode hotspot。Next,选择监控远程服务器的端口,如:JProfiler port: 8849 default。
  2.6、Next,选择启动方式,选择:Don't wait, startup immediately,如图:
http://blog.chenlb.com/wp-content/uploads/2008/11/not-wait-600x415.jpg
  选择了此项,下一步会让你选择配置文件同步方式,我选择“Manual synchroization”,并且输入配置文件在远程服务器的位置,如:/usr/local/jprofiler5,当然其它目录也一样的。
  2.7、Next,后,会有 summary 配置信息列出,如图:
http://blog.chenlb.com/wp-content/uploads/2008/11/summary-600x474.jpg
  2.8、Next,选择“No, I will start the session later”,Finish。
  3、服务器端配置,从 summary 的信息可以知道,C:\Documents and Settings\chenlb\.jprofiler5\config.xml 文件copy到/usr/local/jprofiler5目录下。把windows中的jprofiler5生成的tomcat的启动脚本放到服务器的 tomcat/bin目录下,如我这里,把M:\apache-tomcat-6.0.18\bin\startup_jprofiler.sh 文件copy到/usr/local/tomcat-6.0.18/bin目录下。startup_jprofiler.sh 只加了启动参数让jprofiler可以去监控tomcat,打开startup_jprofiler.sh 文件看一下,在启动tomcat前面(即:exec "$PRGDIR"/"$EXECUTABLE" run "$@" 前面加)了:


[*]# The following lines have been added by the
[*]# application server integration wizard of JProfiler
[*]
[*]LD_LIBRARY_PATH="/user/local/jprofiler5/bin/linux-x86:$LD_LIBRARY_PATH"
[*]export LD_LIBRARY_PATH
[*]CATALINA_OPTS="-agentlib:jprofilerti=port=8849,nowait,id=101,config=/usr/local/jprofiler5/config.xml -Xbootclasspath/a:/user/local/jprofiler5/bin/agent.jar $CATALINA_OPTS"
[*]export CATALINA_OPTS
[*]
[*]# end of modifications
  其中,id=101是config里的session的id。
  4、启动tomcat,然后,非常让人失望,报ERROR: Invalid license key.
  

  
# bin/startup_jprofiler5.sh
  
Using CATALINA_BASE: /usr/local/tomcat-6.0.18
  
Using CATALINA_HOME: /usr/local/tomcat-6.0.18
  
Using CATALINA_TMPDIR: /usr/local/tomcat-6.0.18/temp
  
Using JRE_HOME: /usr/local/jdk1.6.0_10
  
# tail logs/catalina.out
  
JProfiler> 32-bit library
  
JProfiler> Don't wait for frontend to connect.
  
JProfiler> Using config file /usr/local/jprofiler5/config.xml (id: 101)
  
JProfiler> Listening on port: 8849.
  
JProfiler> Instrumenting native methods.
  
JProfiler> Native library initialized
  
JProfiler> Using dynamic instrumentation
  
JProfiler> Time measurement: elapsed time
  
JProfiler> CPU profiling enabled
  
JProfiler> ERROR: Invalid license key.
  
#
  

  想一想,windows下用的是破解的,破解是替换了dll文件的,而linux下没有破解,然后去官方注册一个key,可以免费用10天,注册地址:http://www.ej-technologies.com/download/jprofiler/trial.php。
  注册了新key后,在/usr/local/jprofiler5/config.xml文件licenseKey标签里改下。就得了。 http://blog.chenlb.com/wp-includes/images/smilies/icon_ok.gif 再启动tomcat正常了,
  

  
# tail logs/catalina.out
  
JProfiler> Using config file /usr/local/jprofiler5/config.xml (id: 101)
  
JProfiler> Listening on port: 8849.
  
JProfiler> Instrumenting native methods.
  
JProfiler> Native library initialized
  
JProfiler> Using dynamic instrumentation
  
JProfiler> Time measurement: elapsed time
  
JProfiler> CPU profiling enabled
  
JProfiler> Hotspot compiler enabled
  
JProfiler> Starting org/apache/catalina/startup/Bootstrap ...
  

  

  5、好,现在可以本地windows的jprofiler监控远程tomcat了,打开本地jprofiler,Session->start center,然后双击“Apache Tomcat 6.x on 192.168.1.80”,如图
http://blog.chenlb.com/wp-content/uploads/2008/11/start-center.jpg
  6、开始后,可以地址栏输入http://192.168.1.80:8080/,再去看下jprofiler,恩,太可爱了,有动静,Thead views 如图:
http://blog.chenlb.com/wp-content/uploads/2008/11/run-tomcat-600x442.jpg
  那最下面的http-8080-1的线程就是打开上面的url后出现的。
  好了,先写到这里,怎么用好就要靠自己了。


页: [1]
查看完整版本: jprofiler远程监控tomcat服务器