51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 6979|回复: 5
打印 上一主题 下一主题

jmeter资源监控器开发——增加监控数据

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2008-7-31 22:14:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
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);
       }

增加相应setget方法


       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);
              }

附件:
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2011-4-29 17:23:03 | 只看该作者
感谢jacky的分享。
回复 支持 反对

使用道具 举报

  • TA的每日心情
    开心
    2014-10-16 12:32
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    3#
    发表于 2012-8-17 14:27:36 | 只看该作者
    感谢jacky的分享。
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    4#
    发表于 2012-9-6 15:01:24 | 只看该作者
    附件?
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    5#
    发表于 2012-12-26 10:37:27 | 只看该作者
    为什么我看不到附件??
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    6#
    发表于 2013-4-23 14:55:00 | 只看该作者
    附件看不见呀
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-24 18:35 , Processed in 0.078127 second(s), 27 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表