写的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、下载并安装,其实直接解压就得了。
[root@master local]# pwd
/usr/local
[root@master local]# wget http://download.ej-technologies.com/jprofiler/jprofiler_linux_5_1_2.tar.gz
[root@master local]# 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”,如图:
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生成新的启动脚本,新的脚本加了一些参数,如图。
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,如图:
选择了此项,下一步会让你选择配置文件同步方式,我选择“Manual synchroization”,并且输入配置文件在远程服务器的位置,如:/usr/local/jprofiler5,当然其它目录也一样的。
2.7、Next,后,会有 summary 配置信息列出,如图:
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.
[root@master tomcat-6.0.18]# 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
[root@master tomcat-6.0.18]# 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.
[root@master tomcat-6.0.18]#
想一想,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正常了,
[root@master tomcat-6.0.18]# 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”,如图
6、开始后,可以地址栏输入http://192.168.1.80:8080/,再去看下jprofiler,恩,太可爱了,有动静,Thead views 如图:
那最下面的http-8080-1的线程就是打开上面的url后出现的。
好了,先写到这里,怎么用好就要靠自己了。
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com