这里使用LoadRunner监控tomcat是通过使用LR编写相应的代码进行监控,其原理是通过LoadRunner的关联技术获取tomcat自带的监控首页的性能数据,来获取相应的监控性能指标,然后通过lr_user_data_point()函数将监控到的数据添加数据到图表中,以下是部分代码:
//定义tomcat内存使用情况的监视器事务;
lr_start_transaction(“monitor tomcat”);
//保存3个参数;
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);
//通过LR去访问tomcat监控页
web_set_user(“admin”,”123456″,”192.168.31.91″);
web_url(“status”,
“URL=http://192.168.31.91/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()添加数据到图表中
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}”)));
上面的格式有点异常,试试下面的:
lr_user_data_point("JVM_FreeMemory",atof(lr_eval_string("JVM_FreeMemory")));
lr_user_data_point("JVM_TotalMemory",atof(lr_eval_string("JVM_TotalMemory")));
lr_user_data_point("JVM_MaxMemory",atof(lr_eval_string("JVM_MaxMemory")));
上面脚本不全,经过本人多次试验最终脚本:
Action()
{
double atof(const char * string);
lr_start_transaction("admin tomcat");
web_set_max_html_param_len("99999999");
web_reg_save_param("JVMFreeMemory",
"LB=Free memory: ",
"RB= MB",
"Ord=1",
LAST);
web_set_max_html_param_len("99999999");
web_reg_save_param("JVMTotalMemory",
"LB=Total memory: ",
"RB= MB",
"Ord=1",
LAST);
web_set_max_html_param_len("99999999");
web_reg_save_param("JVMMaxMemory",
"LB=Max memory: ",
"RB= MB",
"Ord=1",
LAST);
web_set_user("admin","1234","172.16.5.16:8080");
web_url("status",
"URL=http://172.16.5.16:8080/manager/status",
"Resource=0",
"Referer=http://172.16.5.16:8080/manager/status",
"Mode=HTML",
LAST);
lr_end_transaction("admin tomcat", LR_AUTO);
lr_user_data_point("JVMFreeMemory",atof(lr_eval_string("JVMFreeMemory")));
lr_user_data_point("JVMTotalMemory",atof(lr_eval_string("JVMTotalMemory")));
lr_user_data_point("JVMMaxMemory",atof(lr_eval_string("JVMMaxMemory")));
return 0;
}
这个脚本才会完整跑通