我想将有关sampleResult的信息保存到MySQL中。所以我编写了自己的名为Performance Logger的监听器。它可以在我的Windows上运行良好。但是当我将相同的JMeter脚本移动到Linux中时,它失败了。以下是我的自定义侦听器的一些代码。
LoggerVisualizer.class
public class LoggerVisualizer extends AbstractVisualizer {
private PerformanceResultCollector collector;
public LoggerVisualizer() {
super();
initConfiguration();
}
private void initConfiguration() {
// some code
}
@Override
public void clearData() {
//some codes
}
public String getStaticLabel() {
return "Performance Logger";
}
public String getLabelResource(){
return "Performance Logger";
}
@Override
public void add(SampleResult sampleResult) {
}
public TestElement createTestElement() {
if (collector == null) {
collector = new PerformanceResultCollector();
}
modifyTestElement(collector);
return collector;
}
}
PerformanceResultCollector.class
public class PerformanceResultCollector extends ResultCollector implements Serializable {
CustomCollector collector;
public PerformanceResultCollector() {
log.info("construct performance collector")
collector = new CustomCollector();
}
@Override
public void sampleOccurred(SampleEvent e) {
collector.addSample(e.getResult());
}
public void cleanUp(){
CustomCollector.cleanUp();
}
}
在我的Windows服务器上,我添加了监听器,它运行良好。我可以在MySQL服务器中看到数据。但是当我将脚本移动到Linux并使用命令
运行它时 nohup ./jmeter -n -t /opt/tests/test.jmx -l /opt/log/perf_result.csv -Jjmeter.save.saveservice.output_format=csv -Jjmeter.save.saveservice.hostname=true -Jjmeter.save.saveservice.print_field_names=false -Jjmeter.save.saveservice.url=true -Jjmeter.save.saveservice.thread_counts=true -Jjmeter.save.saveservice.timestamp_format="yyyy-MM-dd HH:mm:ss" > /opt/log/jmeter_script_run.out 2> /opt/log/jmeter_script_run.err < /dev/null
我在jmeter.log中得到错误,如:
2015/08/08 04:36:28 INFO - com.test.jmeter.logger.PerformanceResultCollector: construct performance collector
2015/08/08 04:36:28 ERROR - jmeter.save.SaveService: Conversion error com.thoughtworks.xstream.converters.ConversionException: java.lang.NullPointerException : java.lang.NullPointerException
---- Debugging information ----
message : java.lang.NullPointerException
cause-exception : java.lang.RuntimeException
cause-message : java.lang.NullPointerException
class : com.test.jmeter.logger.PerformanceResultCollector
required-type : com.test.jmeter.logger.PerformanceResultCollector
converter-type : org.apache.jmeter.save.converters.TestElementConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree/com.test.jmeter.logger.PerformanceResultCollector
line number : 379
class[1] : org.apache.jorphan.collections.ListedHashTree
converter-type[1] : org.apache.jmeter.save.converters.HashTreeConverter
------------------------------- : java.lang.NullPointerException : java.lang.NullPointerException
---- Debugging information ----
message : java.lang.NullPointerException
cause-exception : java.lang.RuntimeException
cause-message : java.lang.NullPointerException
class : com.test.jmeter.logger.PerformanceResultCollector
required-type : com.test.jmeter.logger.PerformanceResultCollector
converter-type : org.apache.jmeter.save.converters.TestElementConverter
path : /jmeterTestPlan/hashTree/hashTree/hashTree/com.test.jmeter.logger.PerformanceResultCollector
line number : 379
class[1] : org.apache.jorphan.collections.ListedHashTree
converter-type[1] : org.apache.jmeter.save.converters.HashTreeConverter
在日志中,我发现它已经进入了PerformanceResultCollector的构造函数。但是为什么它会抛出NulPointerException。我确认Linux上的jmeter的lib与Windows上的相同。有人能告诉我听众有什么问题吗?非常感谢
在我多次修改我的代码后,我终于知道如何解决它,即使我不知道原因。在PerformanceResultCollector.class中,如果构造惰性CustomCollector,它可以工作。
public class PerformanceResultCollector extends ResultCollector implements Serializable {
CustomCollector collector;
public PerformanceResultCollector() {
log.info("construct performance collector")
}
@Override
public void sampleOccurred(SampleEvent e) {
if (null == collector) {
collector = new CustomCollector();
}
collector.addSample(e.getResult());
}
public void cleanUp(){
CustomCollector.cleanUp();
}
}
也许JMeter以不同的方式为非gui和gui模式解析jmx脚本。
答案 0 :(得分:0)
您是否也将MySql驱动程序放入jmeter / lib文件夹?
你确定你的jdbc网址吗?是主机:可以从你的linux机器加入端口吗?
CustomCollector构造函数做什么?
您是否尝试过非gui模式的Windows或者只能在gui模式下使用?