are you nuts?

LoadRunner监控Tomcat

上一篇 / 下一篇  2011-09-27 17:24:33 / 个人分类:别人的好东西,拿来主义!

一、配置被监控的Tomcat

需要在tomcatconf目录下tomcat-users.xml文件中,配置管理员角色
<tomcat-users>
  <role rolename="manager"/>
  <user username="test" password="test" roles="manager"/>
</tomcat-users>

 二、LR单协议选择WEB(HTTP/TCP)-->Action部分替换为如下内容:

double atof (const char *string);//此函数在使用前必须先声明

Action()
{
  web_set_user("test", //tomcat
用户名
  "test", //tomcat
密码
  "192.168.16.107:9090");
 
       lr_start_transaction("monitor tomcat");

       web_reg_save_param("JVMFreeMemory",
              "LB=Free memory: ",
              "RB= MB",
              "Ord=1",
              LAST);
 
       web_reg_save_param("JVMTotalMemory",
              "LB=Total memory: ",
              "RB= MB",
              "Ord=1",
              LAST);
 
       web_reg_save_param("JVMMaxMemory",
              "LB=Max memory: ",
              "RB= MB",
              "Ord=1",
              LAST);
 
       web_reg_save_param("HTTPMaxThreads",
              "LB=Max threads: ",
              "RB= ",
              "Ord=1",
              LAST);
 
       web_reg_save_param("HTTPCurrentThreadCount",
              "LB=Current thread count: ",
              "RB= ",
              "Ord=1",
              LAST);
 
       web_reg_save_param("HTTPCurrentThreadBusy",
              "LB=Current thread busy: ",
              "RB=<br>",
              "Ord=1",
              LAST);
 
       web_reg_save_param("JKMaxThreads",
              "LB=Max threads: ",
              "RB= ",
              "Ord=2",
              LAST);
 
       web_reg_save_param("JKCurrentThreadCount",
              "LB=Current thread count: ",
              "RB= ",
              "Ord=2",
              LAST);
 
       web_reg_save_param("JKCurrentThreadBusy",
              "LB=Current thread busy: ",
              "RB=<br>",
              "Ord=2",
              LAST);


        web_url("status",
  "URL=http://192.168.16.107:9090/manager/status",
  "TargetFrame=",
  "Resource=0",
  "RecContentType=text/html",
  "Referer=http://192.168.16.107:9090",
  "Snapshot=t5.inf",
  "Mode=HTML",
  LAST);
 
       lr_end_transaction("monitor tomcat", LR_AUTO);
 
       // Tomcat JVM metrics
       lr_user_data_point("Tomcat JVM Free memory
(当前可用的内存)", atof(lr_eval_string("{JVMFreeMemory}")));
       lr_user_data_point("Tomcat JVM Total memory(
当前已经分配的Tomcat JVM内存
)", atof(lr_eval_string("{JVMTotalMemory}")));
       lr_user_data_point("Tomcat JVM Max memory(
当前允许分配的最大Tomcat JVM内存)", atof(lr_eval_string("{JVMMaxMemory}")));

    /*通过计算得到jvm内存使用率*/
    lr_user_data_point("Tomcat JVM memory %used
(内存使用率)
", (atof(lr_eval_string("{JVMTotalMemory}"))-atof(lr_eval_string("{JVMFreeMemory}")))/atof(lr_eval_string("{JVMTotalMemory}"))*100);
 
     
       // Tomcat web server metrics
       lr_user_data_point("Tomcat HTTP Max threads
(最大线程数)
", atof(lr_eval_string("{HTTPMaxThreads}")));
       lr_user_data_point("Tomcat HTTP Current thread count", atof(lr_eval_string("{HTTPCurrentThreadCount}")));
       lr_user_data_point("Tomcat HTTP Current thread busy", atof(lr_eval_string("{HTTPCurrentThreadBusy}")));

    
       // Tomcat servlet container metrics
       lr_user_data_point("Tomcat JK Max threads", atof(lr_eval_string("{JKMaxThreads}")));
       lr_user_data_point("Tomcat JK Current thread count ", atof(lr_eval_string("{JKCurrentThreadCount}")));
       lr_user_data_point("Tomcat JK Current thread busy", atof(lr_eval_string("{JKCurrentThreadBusy}")));

 return 0;
}


TAG:

许丫头的个人空间 引用 删除 许丫头   /   2011-09-28 10:05:26
不太懂,上面的代码写在一个Action中,是作为一个单独的场景运行吗
 

评分:0

我来说两句

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 5907
  • 日志数: 8
  • 建立时间: 2011-08-12
  • 更新时间: 2011-10-09

RSS订阅

Open Toolbar