LoadRunenr没有监控Tomcat的专用监控器,为了用lr达到监控tomcat的目的可以通过打开Tomcat自带的Status页面之后,利用lr的关联技术得到相关的数据,把数据输出到lr自定义的监控器中。
  1、打开Tomcat的status页面,方法为编辑Tomcat的conf目录下的tomcat-users.xml文件,在文件中添加
  1 <tomcat-users>
  2   <role rolename="manager"/>
  3   <user username="admin" password="admin" roles="manager"/>
  4 </tomcat-users>
  2、LR脚本开发
  1 lr_start_transaction("monitor tomcat");
  2   web_reg_save_param("JVMFreeMemory",
  3      "LB=Free memory: ",
  4      "RB= MB",
  5      "Ord=1",
  6    LAST);
  7    web_reg_save_param("JVMTotalMemory",
  8    "LB=Total memory: ",
  9    "RB= MB",
  10    "Ord=1",
  11    LAST);
  12 
  13     web_reg_save_param("JVMMaxMemory",
  14      "LB=Max memory: ",
  15      "RB= MB",
  16      "Ord=1",
  17     LAST);
  18 
  19     web_url("status",
  20         "URL=http://{ServerName}/manager/status",
  21         "Resource=0",
  22         "RecContentType=text/html",
  23         "Referer=",
  24         "Snapshot=t1.inf",
  25         "Mode=HTTP",
  26     LAST);
  27 
  28    lr_end_transaction("monitor tomcat", LR_AUTO);
  29 
  30 // Tomcat JVM metrics
  31   lr_user_data_point("Tomcat JVM Free memory", atof(lr_eval_string("{JVMFreeMemory}")));
  32   lr_user_data_point("Tomcat JVM Total memory", atof(lr_eval_string("{JVMTotalMemory}")));
  33    lr_user_data_point("Tomcat JVM Max memory", atof(lr_eval_string("{JVMMaxMemory}")));
  搞定!