0

我有一个执行 jmx get 任务的 ant 脚本:

<jmx:get
                name="java.lang:type=GarbageCollector,name=Copy" 
                attribute="LastGcInfo"
                resultproperty="CopyLastGcInfo"
                />

现在,LastGcInfo 属性有一个名为 memoryUsageBeforeGC 的映射 Map。在这张地图中,有一对带有名为“值”的键。尽管我无法引出并打印出来。我试图这样完成它:

    <echo>${CopyLastGcInfo.memoryUsageBeforeGc.value.used}</echo>
    <echo>${CopyLastGcInfo.memoryUsageBeforeGc.0.used}</echo>
    <echo>${CopyLastGcInfo.memoryUsageBeforeGc.used}</echo>

那没有用。你对如何解决这个问题有什么建议吗?

谢谢。

4

1 回答 1

1

以下示例对我有用:

<project name="Catalina Ant JMX" xmlns:jmx="antlib:org.apache.catalina.ant.jmx" default="jmx">

    <target name="jmx" description="Show JMX stats">
        <jmx:open host="localhost" port="9012" username="controlRole" password="tomcat"/>

        <jmx:get name="java.lang:type=GarbageCollector,name=Copy" 
                 attribute="LastGcInfo"
                 resultproperty="CopyLastGcInfo"
                 echo="false"
                 />

        <echo>
        memoryUsageBeforeGc
        ===================
        Perm Gen.used=${CopyLastGcInfo.memoryUsageBeforeGc.Perm Gen.used}
        Tenured Gen.used=${CopyLastGcInfo.memoryUsageBeforeGc.Tenured Gen.used}
        Eden Space.used=${CopyLastGcInfo.memoryUsageBeforeGc.Eden Space.used}
        Code Cache.used=${CopyLastGcInfo.memoryUsageBeforeGc.Code Cache.used}
        Survivor Space.used=${CopyLastGcInfo.memoryUsageBeforeGc.Survivor Space.used}
        </echo>
    </target>

</project>

示例输出

jmx:
     [echo] 
     [echo]         memoryUsageBeforeGc
     [echo]         ===================
     [echo]         Perm Gen.used=9660888
     [echo]         Tenured Gen.used=8393792
     [echo]         Eden Space.used=4456448
     [echo]         Code Cache.used=2038016
     [echo]         Survivor Space.used=172784
     [echo]         

笔记

  • “jmx:query”任务的“echo”属性可用于查看任务创建的 ANT 属性和值。对故障排除很有用。
于 2012-08-27T20:30:37.890 回答