您的位置:首页 > 运维架构 > Linux

Jprofiler在linux上的安装和配置,以及如何通过windows客户端监控JAVA应用程序

2011-03-23 18:21 1546 查看

下载安装文件

下载windows版本的Jprofiler和Linux版本的Jprofiler,且两者版本保持一致。
Jprofiler下载地址:http://www.ej-technologies.com/
例如本文下载的版本是5.2.4
Windows版本:jprofiler_windows_5_2_4.exe
Linux版本:jprofiler_linux_5_2_4.tar.gz

例子

准备工作完成以后,下面我以一个例子来演示,怎样利用Jprofiler 来监控java程序。
1、编写死循环例子程序,并把它上传到linux服务器
一个死循环的java类TestWhile。然后用jprofiler来监控它消耗cpu的情况。
package com.test;

public class TestWhile extends Thread{
@Override
public void run() {
while(true){
try {
for (int i = 0; i < 20; i++) {
System.out.print("* ");
Thread.sleep(1); //睡眠1ms
}
System.out.println("");
} catch (Exception e) {
}
}
}
public static void main(String[] args) {
new TestWhile().start();
}
}

部署该程序到服务器:例如上传classes文件夹下的目录到/home/mpsp/test/目录下

配置windows 的Jprofile
启动完成后点击菜单Session -àNew Window

选择An application server, locally or remotely 来配置一个服务 --ànext


由于本次例子是来监控一个普通的程序所以选择Generic application -ànext
如果你想用jprofiler监控部署在tomcat5.0的Web应用,那么请选择Apache Tomcat5.x,配置大同小异。



选择LinuxX86/AMD64 -ànext



选择 startup immediately, connect later with the JProfiler GUI -ànext



填写Jprofiler部署路径ànext



Jprofiler config.xml文件所存放的路径,选择在Jpofiler根目录下ànext



根据jdk版本选择,我选择sun-1.5 -ànext



Jprofiler端口默认是8849,由于一些原因我更改为26010端口—>next



这段文字建议保持到一个记事本里。

其中重要的有
Important: The local config file C:/Documents and Settings/wwj/.jprofiler5/config.xml must be copied manually to /home/mpsp/jprofiler5 on the remote computer when the profiling settings are changed.

config.xml存放的路径C:/Documents and Settings/wwj/.jprofiler5/config.xml,把这个文件上传到Jprofiler的根目录下:/home/mpsp/jprofiler5 ,在上传之前,先把config.xml文件中的javaHome="C:/Java/jre1.5.0_15"更改为服务器的JAVA_HOME路径/home/mpsp/jdk1.5.0_19

-agentlib:jprofilerti=port=8849,nowait,id=111,config=/home/mpsp/jprofiler5/config.xml -Xbootclasspath/a:/home/mpsp/jprofiler5/bin/agent.jar
如果要用Jprofiler来监控TestWhile,则需要java 命令前面的加上这些参数
Java -agentlib:jprofilerti=port=8849,nowait,id=111,config=/home/mpsp/jprofiler5/config.xml -Xbootclasspath/a:/home/mpsp/jprofiler5/bin/agent.jar com.test.TestWhile

Please add
/home/mpsp/jprofiler5/bin/linux-x86
to the environment variable LD_LIBRARY_PATH.
在服务器的环境变量里加入LD_LIBRARY_PATH = /home/mpsp/jprofiler5/bin/linux-x86

vi /etc/profiler
在末尾加上
LD_LIBRARY_PATH=/home/mpsp/zj_unioncard/jprofiler5/bin/linux-x86
export LD_LIBRARY_PATH



完成后别忘了运行source /etc/profile 让刚才的配置生效
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: