用LoadRunner 函数监控Tomcat

转自【http://se.csai.cn/testtools/200812240908031253.htm

LoadRunenr没有监控Tomcat的专用监控器,为了用lr达到监控tomcat的目的可以通过打开Tomcat自带的Status页面之后,利用lr的关联技术得到相关的数据,把数据输出到lr自定义的监控器中。

 1、打开Tomcat的status页面,方法为编辑Tomcat的conf目录下的tomcat-users.xml文件,在文件中添加

<tomcat-users>
<role rolename="manager"/>
<user username="admin" password="pass" roles="manager"/>
</tomcat-users>

 2、开发lr脚本

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_url("status",
"URL=http://{ServerName}/manager/status",
"Resource=0",
"RecContentType=text/html",
"Referer=",
"Snapshot=t1.inf",
"Mode=HTTP",
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", atof(lr_eval_string("{JVMTotalMemory}")));
lr_user_data_point("Tomcat JVM Max memory", atof(lr_eval_string("{JVMMaxMemory}")));

<script></script>

<!-- 【<a href="http://www.csai.cn/incSearch/search_bbstitle.asp?t=LoadRunner+%CA%B5%CF%D6%BC%E0%BF%D8Tomcat&c=%C8%ED%BC%FE%B9%A4%B3%CC%7C%7C%B2%E2%CA%D4%B9%A4%BE%DF" target="_blank">发表评论</a>】 -->

你可能感兴趣的:(loadrunner)