您的位置:首页 > 编程语言 > ASP

使用Kieker(基于AspectJ)监控Java桌面应用的基本方法

2013-08-03 13:32 1051 查看
这篇日志里简单总结一下使用基于AspectJ的Kieker监控Java桌面应用的步骤,希望对初学的朋友有所帮助。(这篇日志主要是师弟总结的经验,我只是加上一些细节信息)

我们以Makagiga这个私人信息管理系统为例来进行说明。我们在这里下载其3.8.2版本:http://sourceforge.net/projects/makagiga/files/Source/3.8.2/
将压缩包解压之后,和我之前的一篇日志一样(这里仍然是以Kieker
1.4为例进行说明),将”kieker-1.4″下”dist”文件夹下的”kieker-1.4.jar”和”lib”文件夹下的”aspectjweaver-1.6.11.jar”和”commons-logging-1.1.1.jar”三个jar包拷贝进解压后目录中的”lib”文件夹下。再将这篇日志里说的文件夹META-INF放到build目录下。

其次,需要对build.xml文件进行修改,首先在这里:

<target name="compile">
<echo>HINT: Type "ant help" to see all Ant targets</echo>
<!-- NOTE: sync. with "test" -->
<mkdir dir="${build_dir}" />
<javac
classpath=".:lib/desklet.jar"
srcdir="src"
destdir="${build_dir}"
deprecation="on"
source="1.6"
target="1.6"
>
<compilerarg line="-g:lines,source -Xlint:all,-serial -Xmaxerrs 5" />
</javac>
<!-- excludes="**/package-info.java" -->

<copy todir="${build_dir}/META-INF/services">
<fileset dir="${top_dir}/src/META-INF/services" />
</copy>
</target>


增加刚才添加的几个jar包,将上面内容中的classpath修改为:

classpath=".:lib/desklet.jar:lib/commons-logging-1.1.1.jar:lib/kieker-1.4.jar"


然后,将这一部分:

<!-- run -->
<target name="run">
<condition property="need_compile_properties">
<not>
<available file="${build_dir}/org/makagiga/resources/Main.class" />
</not>
</condition>
<antcall target="compile-properties-quick" />

<java
classname="org.makagiga.Main"
classpath="${top_dir}:${top_dir}/i18n:${top_dir}/src:${build_dir}:${lib_dir}/desklet.jar"
fork="on"
>
<!-- -splash:${top_dir}/splash.png -->
<jvmarg line="-Xverify:none -Xms16m -Xmx128m ${java_args}" />
<!--<jvmarg line="-Xverify:none -Xms16m -Xmx128m ${java_args} -agentpath:${nb_dir}/profiler3/lib/deployed/jdk16/linux/libprofilerinterface.so=${nb_dir}/profiler3/lib,5140" />-->
<arg line="${prog_args}" />
</java>
</target>


修改为:

<!-- run -->
<target name="run">
<condition property="need_compile_properties">
<not>
<available file="${build_dir}/org/makagiga/resources/Main.class" />
</not>
</condition>
<antcall target="compile-properties-quick" />

<property name="jvm" value="java"/>
<property name="jvm.type" value="-javaagent"/>

<java
classname="org.makagiga.Main"
classpath="${top_dir}:${top_dir}/i18n:${top_dir}/src:${build_dir}:${lib_dir}/desklet.jar:${lib_dir}/kieker-1.4.jar:${lib_dir}/commons-logging-1.1.1.jar"
fork="on"
>
<!-- -splash:${top_dir}/splash.png -->
<jvmarg value="${jvm.type}:lib\aspectjweaver-1.6.11.jar"/>
<jvmarg line="-Xverify:none -Xms16m -Xmx128m ${java_args}" />
<!--<jvmarg line="-Xverify:none -Xms16m -Xmx128m ${java_args} -agentpath:${nb_dir}/profiler3/lib/deployed/jdk16/linux/libprofilerinterface.so=${nb_dir}/profiler3/lib,5140" />-->
<arg line="${prog_args}" />
</java>
</target>


然后再修改META-INF中aop.xml文件中指定的被监控的类,如下面这个配置文件所示:

<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.aspectj.org/dtd/aspectj_1_5_0.dtd">

<aspectj>
<weaver options=""> <!-- options="-verbose" -->

<!-- Use the exclude/include directives to specify which classes
are (not) to be considered for weaving.
Some examples are given below.
-->
<include within="org.makagiga..*"/>

</weaver>

<aspects>
<!-- Use the aspect directives to specify the aspect(s) to use (typically only one). -->

<!--<aspect name="kieker.monitoring.probe.aspectJ.operationExecution.OperationExecutionAspectAnnotation"/>-->
<!--<aspect name="kieker.monitoring.probe.aspectJ.operationExecution.OperationExecutionAspectAnnotationServlet"/>-->
<aspect name="kieker.monitoring.probe.aspectJ.operationExecution.OperationExecutionAspectFull"/>
<!-- <aspect name="kieker.monitoring.probe.aspect.JoperationExecution.OperationExecutionAspectFullServlet"/> -->
</aspects>
</aspectj>


最后,一般来说Kieker的输出文件在类似于C:\Documents and Settings\Administrator\Local Settings\Temp这样的位置,为了方便起见,我们可以改成在指定的文件夹位置,这时候需要修改META-INF中kieker.monitoring.properties文件,将下面这一部分改成如下形式:

#####
#kieker.monitoring.writer=kieker.monitoring.writer.filesystem.AsyncFsWriter
#
## In order to use the default temporary directory, set the property value of
## storeInJavaIoTmpdir to true.
kieker.monitoring.writer.filesystem.AsyncFsWriter.storeInJavaIoTmpdir=false
#
## In order to use a custom directory, set storeInJavaIoTmpdir=false
## and set customStoragePath as desired. Examples:
## /var/kieker or "C:\KiekerData" (ensure the folder exists).
kieker.monitoring.writer.filesystem.AsyncFsWriter.customStoragePath=F:\\Projects\\makagiga-monitor-data


这样就在F:\Projects\makagiga-monitor-data这个文件夹底下会产生监控数据。将以上这些内容设置好之后,我们在命令行下定位到刚才的文件夹,运行“ant”命令(这里简单说一下ant的环境变量配置,首先增加一个ANT_HOME环境变量,定位到如“D:\Projects\apache-ant-1.9.0”的文件夹,再在Path环境变量中增加“%ANT_HOME%\bin”),就可以启动makagiga并生成监控数据了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐