一、配置被监控的Tomcat
需要在tomcat的conf目录下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;
}