如何将 perfmon 插件与 jmeter-maven-plugin 一起使用?

How to use perfmon plugins with jmeter-maven-plugin?

我目前正在开发一个基于 jmeter 的项目运行 使用 jmeter maven 插件进行测试。到目前为止,一切正常,直到我添加了 perfmon 插件,添加它们以使用 jmeter UI 获得每秒事务处理和随时间推移的响应时间,按照说明 here

运行 它在 Maven 中的结果现在是:

[INFO] Error in NonGUIDriver java.lang.IllegalArgumentException: Problem loading XML from:'/Users/foo/Tools/src/platform-load-test/jersey2-load-test/target/jmeter/testFiles/JerseyAsync.jmx', missing class com.thoughtworks.xstream.converters.ConversionException:
[INFO] ---- Debugging information ----
[INFO] cause-exception     : com.thoughtworks.xstream.converters.ConversionException
[INFO] cause-message       :
[INFO] first-jmeter-class  : org.apache.jmeter.save.converters.HashTreeConverter.unmarshal(HashTreeConverter.java:67)
[INFO] class               : org.apache.jmeter.save.ScriptWrapper
[INFO] required-type       : org.apache.jorphan.collections.ListedHashTree
[INFO] converter-type      : org.apache.jmeter.save.ScriptWrapperConverter
[INFO] path                : /jmeterTestPlan/hashTree/hashTree/hashTree/kg.apc.jmeter.perfmon.PerfMonCollector
[INFO] line number         : 259
[INFO] version             : 3.1 r1770033
[INFO] -------------------------------

按照 documentation 添加额外的库(因为我已经通过 jmeter ui 的插件管理器添加了 perfmon 侦听器),我更新了我的 pom 添加了 jmeter 扩展部分:

<plugin>
   <groupId>com.lazerycode.jmeter</groupId>
   <artifactId>jmeter-maven-plugin</artifactId>
   <version>2.1.0</version>
   <executions>
      <execution>
         <id>jmeter-tests</id>
         <phase>pre-integration-test</phase>
         <goals>
            <goal>jmeter</goal>
         </goals>
      </execution>
   </executions>
   <configuration>
      <ignoreResultFailures>true</ignoreResultFailures>
      <jmeterExtensions>
         <jmeterExtension>kg.apc:jmeter-plugins-perfmon:2.1</jmeterExtension>
      </jmeterExtensions>
   </configuration>
</plugin>

及分析部分:

<plugin>
    <groupId>com.lazerycode.jmeter</groupId>
    <artifactId>jmeter-analysis-maven-plugin</artifactId>
    <version>1.0.6</version>
    <executions>
        <execution>
            <id>analyze-results</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>analyze</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <source>${project.basedir}/target/jmeter/results/*.jtl</source>
        <targetDirectory>${project.basedir}/target/reports</targetDirectory>
    </configuration>
</plugin>

然而,这导致:

[INFO] -------------------------------------------------------
[INFO]  Configuring JMeter...
[INFO] -------------------------------------------------------
[WARNING] The POM for commons-math3:commons-math3:jar:3.4.1 is missing, no dependency information available
[WARNING] The POM for commons-pool2:commons-pool2:jar:2.3 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.196 s
[INFO] Finished at: 2017-02-16T16:13:31+08:00
[INFO] Final Memory: 20M/437M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.lazerycode.jmeter:jmeter-maven-plugin:2.1.0:configure (configure) on project jersey2-load-test: Failure to find commons-math3:commons-math3:jar:3.4.1 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

其中指出有 假设我在为 jmeter 添加 jar 扩展的正确路径中,我如何排除无效的依赖项并使用插件的 jmeter 扩展部分添加正确的依赖项?否则如何在使用 jmeter maven 插件时正确添加 perfmon 插件依赖项?

您看到的错误是因为 jmeter-plugins 依赖于 JMeter 2.13,它有一个损坏的 maven 依赖树。这是 jmeter-plugins 团队需要解决的问题(他们需要发布一个依赖于 JMeter 3.1 的 jmeter 插件版本)。

构建中断,因为插件正在尝试为 jmeter-plugins 下载一些不存在的传递依赖项,您可以通过设置解决此问题:

<downloadExtensionDependencies>false</downloadExtensionDependencies>

然而,这确实意味着您将需要手动设置 jmeter-plugins 依赖于您的 <jmeterExtensions> 块中的所有依赖项。

这里是依赖树:

[INFO] \- kg.apc:jmeter-plugins-perfmon:jar:2.1:compile
[INFO]    +- kg.apc:jmeter-plugins-cmn-jmeter:jar:0.3:compile
[INFO]    |  +- org.apache.jmeter:jorphan:jar:2.13:compile
[INFO]    |  |  +- bsf:bsf:jar:2.4.0:compile
[INFO]    |  |  +- org.beanshell:bsh:jar:2.0b5:compile
[INFO]    |  |  +- org.bouncycastle:bcmail-jdk15on:jar:1.49:compile
[INFO]    |  |  +- org.bouncycastle:bcprov-jdk15on:jar:1.49:compile
[INFO]    |  |  +- org.bouncycastle:bcpkix-jdk15on:jar:1.49:compile
[INFO]    |  |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO]    |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    |  |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO]    |  |  +- commons-io:commons-io:jar:2.4:compile
[INFO]    |  |  +- commons-jexl:commons-jexl:jar:1.1:compile
[INFO]    |  |  +- org.apache.commons:commons-jexl:jar:2.1.1:compile
[INFO]    |  |  +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO]    |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO]    |  |  +- commons-net:commons-net:jar:3.3:compile
[INFO]    |  |  +- dnsjava:dnsjava:jar:2.1.7:compile
[INFO]    |  |  +- excalibur-datasource:excalibur-datasource:jar:2.1:compile
[INFO]    |  |  |  +- hsqldb:hsqldb:jar:1.8.0.1:compile
[INFO]    |  |  |  +- avalon-framework:avalon-framework-api:jar:4.3:compile
[INFO]    |  |  |  +- avalon-framework:avalon-framework-impl:jar:4.3:compile
[INFO]    |  |  |  |  +- xml-apis:xmlParserAPIs:jar:2.0.2:compile
[INFO]    |  |  |  |  \- jmock:jmock:jar:1.0.1:compile
[INFO]    |  |  |  +- avalon-logkit:avalon-logkit:jar:2.1:compile
[INFO]    |  |  |  |  +- javax.servlet:servlet-api:jar:2.3:compile
[INFO]    |  |  |  |  +- geronimo-spec:geronimo-spec-javamail:jar:1.3.1-rc3:compile
[INFO]    |  |  |  |  \- geronimo-spec:geronimo-spec-jms:jar:1.1-rc4:compile
[INFO]    |  |  |  +- excalibur-instrument:excalibur-instrument-api:jar:2.1:compile
[INFO]    |  |  |  +- concurrent:concurrent:jar:1.3.4:compile
[INFO]    |  |  |  +- excalibur-component:excalibur-testcase:jar:2.1:compile
[INFO]    |  |  |  +- excalibur-component:excalibur-component:jar:2.1:compile
[INFO]    |  |  |  |  +- excalibur-instrument:excalibur-instrument-mgr-api:jar:2.1:compile
[INFO]    |  |  |  |  \- excalibur-instrument:excalibur-instrument-mgr-impl:jar:2.1:compile
[INFO]    |  |  |  \- qdox:qdox:jar:1.5:compile
[INFO]    |  |  +- excalibur-instrument:excalibur-instrument:jar:1.0:compile
[INFO]    |  |  +- excalibur-logger:excalibur-logger:jar:1.1:compile
[INFO]    |  |  +- excalibur-pool:excalibur-pool-api:jar:2.1:compile
[INFO]    |  |  +- excalibur-pool:excalibur-pool-impl:jar:2.1:compile
[INFO]    |  |  |  \- junitperf:junitperf:jar:1.8:compile
[INFO]    |  |  +- excalibur-pool:excalibur-pool-instrumented:jar:2.1:compile
[INFO]    |  |  +- org.htmlparser:htmllexer:jar:2.1:compile
[INFO]    |  |  +- org.htmlparser:htmlparser:jar:2.1:compile
[INFO]    |  |  +- org.apache.httpcomponents:httpclient:jar:4.2.6:compile
[INFO]    |  |  +- org.apache.httpcomponents:httpmime:jar:4.2.6:compile
[INFO]    |  |  +- org.apache.httpcomponents:httpcore:jar:4.2.5:compile
[INFO]    |  |  +- oro:oro:jar:2.0.8:compile
[INFO]    |  |  +- jcharts:jcharts:jar:0.7.5:compile
[INFO]    |  |  +- org.jdom:jdom:jar:1.1.3:compile
[INFO]    |  |  +- org.mozilla:rhino:jar:1.7R5:compile
[INFO]    |  |  +- junit:junit:jar:4.12:compile
[INFO]    |  |  |  \- org.hamcrest:hamcrest-core:jar:1.3:compile
[INFO]    |  |  +- soap:soap:jar:2.3.1:compile
[INFO]    |  |  +- net.sf.jtidy:jtidy:jar:r938:compile
[INFO]    |  |  +- org.apache.tika:tika-core:jar:1.7:compile
[INFO]    |  |  +- org.apache.tika:tika-parsers:jar:1.7:compile
[INFO]    |  |  |  +- org.gagravarr:vorbis-java-tika:jar:0.6:compile
[INFO]    |  |  |  +- edu.ucar:netcdf:jar:4.2.20:compile
[INFO]    |  |  |  |  \- edu.ucar:unidataCommon:jar:4.2.20:compile
[INFO]    |  |  |  |     \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO]    |  |  |  +- net.sourceforge.jmatio:jmatio:jar:1.0:compile
[INFO]    |  |  |  +- org.apache.james:apache-mime4j-core:jar:0.7.2:compile
[INFO]    |  |  |  +- org.apache.james:apache-mime4j-dom:jar:0.7.2:compile
[INFO]    |  |  |  +- org.apache.commons:commons-compress:jar:1.8.1:compile
[INFO]    |  |  |  +- org.tukaani:xz:jar:1.5:compile
[INFO]    |  |  |  +- org.apache.pdfbox:pdfbox:jar:1.8.8:compile
[INFO]    |  |  |  |  +- org.apache.pdfbox:fontbox:jar:1.8.8:compile
[INFO]    |  |  |  |  \- org.apache.pdfbox:jempbox:jar:1.8.8:compile
[INFO]    |  |  |  +- org.bouncycastle:bcmail-jdk15:jar:1.45:compile
[INFO]    |  |  |  +- org.bouncycastle:bcprov-jdk15:jar:1.45:compile
[INFO]    |  |  |  +- org.apache.poi:poi:jar:3.11:compile
[INFO]    |  |  |  +- org.apache.poi:poi-scratchpad:jar:3.11:compile
[INFO]    |  |  |  +- org.apache.poi:poi-ooxml:jar:3.11:compile
[INFO]    |  |  |  |  \- org.apache.poi:poi-ooxml-schemas:jar:3.11:compile
[INFO]    |  |  |  |     \- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
[INFO]    |  |  |  +- org.ccil.cowan.tagsoup:tagsoup:jar:1.2.1:compile
[INFO]    |  |  |  +- org.ow2.asm:asm-debug-all:jar:4.1:compile
[INFO]    |  |  |  +- com.googlecode.mp4parser:isoparser:jar:1.0.2:compile
[INFO]    |  |  |  |  \- org.aspectj:aspectjrt:jar:1.8.0:compile
[INFO]    |  |  |  +- com.drewnoakes:metadata-extractor:jar:2.6.2:compile
[INFO]    |  |  |  |  \- com.adobe.xmp:xmpcore:jar:5.1.2:compile
[INFO]    |  |  |  +- de.l3s.boilerpipe:boilerpipe:jar:1.1.0:compile
[INFO]    |  |  |  +- rome:rome:jar:1.0:compile
[INFO]    |  |  |  |  \- jdom:jdom:jar:1.0:compile
[INFO]    |  |  |  +- org.gagravarr:vorbis-java-core:jar:0.6:compile
[INFO]    |  |  |  +- com.googlecode.juniversalchardet:juniversalchardet:jar:1.0.3:compile
[INFO]    |  |  |  +- com.uwyn:jhighlight:jar:1.0:compile
[INFO]    |  |  |  \- com.pff:java-libpst:jar:0.8.1:compile
[INFO]    |  |  +- com.thoughtworks.xstream:xstream:jar:1.4.8:compile
[INFO]    |  |  +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO]    |  |  +- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO]    |  |  +- xalan:xalan:jar:2.7.2:compile
[INFO]    |  |  +- xalan:serializer:jar:2.7.2:compile
[INFO]    |  |  +- xerces:xercesImpl:jar:2.11.0:compile
[INFO]    |  |  +- xml-apis:xml-apis:jar:1.4.01:compile
[INFO]    |  |  +- org.apache.xmlgraphics:xmlgraphics-commons:jar:1.5:compile
[INFO]    |  |  +- javax.mail:mail:jar:1.5.0-b01:compile
[INFO]    |  |  |  \- javax.activation:activation:jar:1.1:compile
[INFO]    |  |  +- org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO]    |  |  +- org.jsoup:jsoup:jar:1.8.1:compile
[INFO]    |  |  +- org.jodd:jodd-core:jar:3.6.4:compile
[INFO]    |  |  +- org.jodd:jodd-lagarto:jar:3.6.4:compile
[INFO]    |  |  +- org.jodd:jodd-log:jar:3.6.4:compile
[INFO]    |  |  +- org.mongodb:mongo-java-driver:jar:2.11.3:compile
[INFO]    |  |  +- com.fifesoft:rsyntaxtextarea:jar:2.5.6:compile
[INFO]    |  |  +- org.slf4j:slf4j-api:jar:1.7.10:compile
[INFO]    |  |  \- org.slf4j:slf4j-nop:jar:1.7.10:compile
[INFO]    |  +- org.apache.jmeter:ApacheJMeter_core:jar:2.13:compile
[INFO]    |  \- kg.apc:jmeter-plugins-charts:jar:0.1:compile
[INFO]    \- kg.apc:perfmon:jar:2.2.2:compile
[INFO]       +- kg.apc:cmdrunner:jar:1.0.1:compile
[INFO]       +- org.fusesource:sigar:jar:1.6.4:compile
[INFO]       |  \- log4j:log4j:jar:1.2.15:compile
[INFO]       +- avalon-framework:avalon-framework:jar:4.1.5:compile
[INFO]       \- logkit:logkit:jar:2.0:compile

您可能只添加这些库的一个子集,前提是您不使用需要它们代码的代码路径。

这确实强调了为什么将仅在测试中依赖的依赖项标记为 <scope>test</scope> 很重要,这样它们就不会作为 [=35= 所需的核心依赖项而被拉下] 你的主要代码。

以上信息尚未进入 Wiki(添加此信息并将所有内容移动到网站的任务正在进行中),但在 CHANGELOG 中可用:

https://github.com/jmeter-maven-plugin/jmeter-maven-plugin/blob/master/CHANGELOG.md

我使用 maven-antrun-plugin 下载 jmeter-plugins-manager-0.15.jar 然后我使用命令行执行(还有 ant)来下载最新的插件:

        <plugin><artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution><id>init</id><phase>initialize</phase><goals><goal>run</goal></goals>
                    <configuration>
                        <target>
                            <get src="http://jmeter-plugins.org/get/" dest="target/jmeter/lib/ext/jmeter-plugins-manager.jar"/>
                            <get src="http://central.maven.org/maven2/kg/apc/cmdrunner/2.0/cmdrunner-2.0.jar" dest="target/jmeter/lib/cmdrunner-2.0.jar"/>
                            <java classname="org.jmeterplugins.repository.PluginManagerCMDInstaller">
                                <classpath>
                                    <pathelement location="target/jmeter/lib/ext/jmeter-plugins-manager.jar"/>
                                </classpath>
                            </java>
                            <ant antfile="plugins.xml" target="plugins" inheritAll="true" />
                        </target>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency><groupId>ant-contrib</groupId><artifactId>ant-contrib</artifactId><version>1.0b3</version>
                    <exclusions>
                        <exclusion><groupId>ant</groupId><artifactId>ant</artifactId></exclusion>
                    </exclusions>
                </dependency>
            </dependencies>
        </plugin>

其中 plugins.xml 是:

<project xmlns:ac="antlib:net.sf.antcontrib">
<target name="plugins">
    <loadfile property="file" srcfile="plugins"/>
    <ac:for param="line" list="${file}" delimiter="${line.separator}">
        <ac:sequential>
            <exec executable="target/jmeter/bin/PluginsManagerCMD.sh">
                <arg value="install"/>
                <arg value="@{line}"/>
            </exec>
        </ac:sequential>
    </ac:for>
</target>

插件文件包含插件 ID 列表:

jpgc-dummy
jpgc-fifo
jpgc-graphs-basic
jpgc-perfmon
jpgc-tst
jpgc-functions
jpgc-casutg
jpgc-ffw
jpgc-prmctl