LoadRunner 实现监控Tomcat
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}"))); |