Loadrunner监控Tomcat
这里使用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}”)));