JMeter插件-----JMXMon插件监控JVM

准备

1、以windows为例,本地准备jmeter,这里用的是3.1
2、要监控的jvm配置jmx:

-Dcom.sun.management.jmxremote.port=8999 
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=false 
-Djava.rmi.server.hostname=10.255.255.150(使用的时候改成自己的ip)

安装

两种方式:

第一种方式有时候会比较慢,我们采用第二种方式

启动jmeter,按下面向导操作
jmeter
注意:我这里之前装好了,所以在installed中,正常未安装应该在availiable plugins中,勾选,安装,会自动重启

使用

1、建立测试计划
2、添加监视器
添加监视器

JMX Sampler介绍

  1. Label:填写监控图表里的曲线名称。
  2. URI:填写被测JVM的JMX连接地址
    service:jmx:rmi:///jndi/rmi://YOURHOST:JMXPORT/jmxrmi 或者
    service:jmx:rmi://YOURHOST:JMXPORT/jndi/rmi://YOURHOST:JMXPORT/jmxrmi
    这个字段可以包含jmeter变量,如果retry被勾选就可以灵活进行jxm配置。比如一个服务器产生外部进程,它可以返回jmx连接的ip和端口,可将这些值提取到变量(s)中并在URI字段中使用。
  3. Object Name:填写监控的具体对象名称。
  4. Attribute:填写监控的具体属性。
  5. Key:如果是复杂类型的属性,还需要填写Key。
  6. Delta:表示差异,在此理解为增量(见最后代码)。
  7. retry:勾选时,在测试期间尝试新的连接,丢失的连接可以恢复。

获取属性和objectName

通过jconsole或者jvisualVM获取
以jvisualVM为例
attr

demo运行示意
resutl

比如再添加一个
newattr
result

delta属性示例

表示增量
delta

扒了扒源码

JMXMonCollector.java

……
boolean isDelta = ((JMeterProperty)row.get(7)).getBooleanValue();
……
initiateConnector(attributes, jmxUrl, label, isDelta, objectName, attribute, key, canRetry);
……

protected void initiateConnector(Hashtable attributes, String jmxUrl, String name, boolean delta, String objectName, String attribute, String key, boolean canRetry)
    throws IOException
  {
    if ((!canRetry) && (pool.getConnection(jmxUrl, attributes, true) == null)) {
      return;
    }
    this.jmxMonSamplers.add(new JMXMonSampler(pool, attributes, jmxUrl, name, objectName, attribute, key, delta, canRetry));
  }

JMXMonSampler.java

 public JMXMonSampler(JMXMonConnectionPool pool, Hashtable attributes, String url, String name, String objectName, String attribute, String key, boolean sampleDeltaValue, boolean canRetry)
  {
    this.pool = pool;
    this.connectionAttributes = attributes;
    this.metricName = name;
    this.url = url;
    this.objectName = objectName;
    this.attribute = attribute;
    this.sampleDeltaValue = sampleDeltaValue;
    this.key = key;
    this.canRetry = canRetry;
  }
public void generateSamples(JMXMonSampleGenerator collector){
……
    if (this.sampleDeltaValue)
    {
      if (!Double.isNaN(this.oldValue)) {
        collector.generateSample(val - this.oldValue, this.metricName);
      }
      this.oldValue = val;
    }
    else
    {
      collector.generateSample(val, this.metricName);
    }
    ……
}

猜你喜欢

转载自blog.csdn.net/yue530tomtom/article/details/80355724