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

这篇日志里简单总结一下使用基于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并生成监控数据了。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值