|
by jack
jmeter自带的监控器输出的只有四条曲线,其中health和load曲线还是根据mem和thread算出来的,所以真正意义上输出的数据只有两个而已。显然这远远满足不了我们对性能监控的需要么。
既然jmeter没有,那我就有用武之地了(要不然要我这QA架构师干啥,哈),于是我自己添了几个,用着还不错,现在把添加一个参数的过程完整叙述如下:
以增加swapout为例,取xml中的currentThreadsBusy作为swapout的值。
蓝色字注明关键点:
Stats.java
增加新的数据解析方法
public static int calculateSwapout(Status stat) {
double swapout = 0;
if (stat != null && stat.getConnector().size() > 0) {
Connector cntr = (Connector) stat.getConnector().get(0);
swapout = cntr.getRequestInfo().getCurrentThreadsBusy();
}
return (int) swapout;
}
MonitorStats.java
增加私有静态变量
private static final String SWAPOUT = "stats.swapout";
增加构造函数入参、赋值语句
public MonitorStats(int health, int load, int cpuload, int memload, int threadload, int swapin, int swapout, String host, String port,
String protocol, long time) {
this.setHealth(health);
this.setLoad(load);
this.setCpuLoad(cpuload);
this.setMemLoad(memload);
this.setThreadLoad(threadload);
this.setSwapin(swapin);
this.setSwapout(swapout);
this.setHost(host);
this.setPort(port);
this.setProtocol(protocol);
this.setTimeStamp(time);
}
增加相应set、get方法
public void setSwapout(int load) {
this.setProperty(SWAPOUT, String.valueOf(load));
}
public int getSwapout() {
return this.getPropertyAsInt(SWAPOUT);
}
MonitorModel.java
增加私有变量对象current初始化中MonitorStats实例化的入参
private MonitorStats current = new MonitorStats(0, 0, 0, 0, 0, 0, 0, "", "", "", System.currentTimeMillis());
增加clearData方法中MonitorStats实例化的入参
current = new MonitorStats(0, 0, 0, 0, 0, 0, 0, "", "", "", System.currentTimeMillis());
增加相应get方法
public int getSwapout() {
return this.current.getSwapout();
}
增加cloneMonitorStats方法的入参
public MonitorStats cloneMonitorStats() {
return new MonitorStats(current.getHealth(), current.getLoad(), current.getCpuLoad(), current.getMemLoad(),
current.getThreadLoad(), current.getSwapin(), current.getSwapout(), current.getHost(), current.getPort(), current.getProtocol(), current
.getTimeStamp());
}
MemoryBenchmark.java
增加main方法中MonitorStats实例化的入参
MonitorStats mstats = new MonitorStats(Stats.calculateHealth(st), Stats.calculateLoad(st), Stats.calculateCpuLoad(st), Stats
.calculateMemLoad(st), Stats.calculateThreadLoad(st), Stats.calculateSwapin(st), Stats.calculateSwapout(st), "localhost", "8080", "http", System
.currentTimeMillis());
MonitorAccumModel.java
增加addSample方法中MonitorStats实例化的入参
MonitorStats stat = new MonitorStats(Stats.calculateHealth(st), Stats.calculateLoad(st), Stats.calculateCpuLoad(st), Stats
.calculateMemLoad(st), Stats.calculateThreadLoad(st), Stats.calculateSwapin(st), Stats.calculateSwapout(st), surl.getHost(), String.valueOf(surl
.getPort()), surl.getProtocol(), System.currentTimeMillis());
增加createNewMonitorModel方法中MonitorStats实例化的入参
MonitorStats stat = new MonitorStats(Stats.DEAD, 0, 0, 0, 0, 0, 0, url.getHost(), String.valueOf(url.getPort()), url
.getProtocol(), System.currentTimeMillis());
MonitorPerformancePanel.java
增加公共静态变量(显示文案和图例,同时增加资源文件中对应项,及相应图片)
public static final String LEGEND_SWAPOUT = JMeterUtils.getResString("monitor_legend_swapout_per");
public static final ImageIcon LEGEND_SWAPOUT_ICON = JMeterUtils.getImage("monitor-yellow-legend.gif");
资源文件messages.properties:
monitor_legend_swapout_per=Swap Out
图片文件monitor-yellow-legend.gif
增加createLegend方法中的JLabel实例化语句
JLabel jswapout = new JLabel(LEGEND_SWAPOUT);
jswapout.setFont(plaintext);
jswapout.setPreferredSize(lsize);
jswapout.setIcon(LEGEND_SWAPOUT_ICON);
legend.add(jswapout);
MonitorGraph.java
增加私有变量
private boolean SWAPOUT = true;
增加相应set方法
public void setSwapout(boolean swapout) {
this.SWAPOUT = swapout;
}
增加drawSample方法中相应绘图语句
if (SWAPOUT) {
int swoy = (int) (height - (height * (model.getSwapout() / 10000.0)));
int lastswoy = (int) (height - (height * (last.getSwapout() / 10000.0)));
g.setColor(Color.yellow);
g.drawLine(lastx, lastswoy, xaxis, swoy);
}
附件:
|
|