监控tomcat 首先要在tomcat的conf下的 tomcat-users.xml中增加user
代码:
Action_Tomcat() { double atof(const char * string); web_set_user("tomcat","tomcat","localhost:8080"); web_reg_save_param("JVM_FreeMemory", "LB=Free memory: ", "RB= MB", "Ord=1", LAST); web_reg_save_param("JVM_TotalMemory", "LB=Total memory: ", "RB= MB", "Ord=1", LAST); web_reg_save_param("JVM_MaxMemory", "LB=Max memory: ", "RB= MB", "Ord=1", LAST); web_reg_save_param("HTTP_MaxThreads", "LB=Max threads: ", "RB= ", "Ord=1", LAST); web_reg_save_param("HTTP_MaxProcessingTime", "LB=Max processing time: ", "RB= s", "Ord=1", LAST); web_reg_save_param("HTTP_RequestCount", "LB=Request count: ", "RB= ", "Ord=1", LAST); web_reg_save_param("HTTP_BytesReceived", "LB=Bytes received: ", "RB= MB", "Ord=1", LAST); lr_think_time(5); web_url("status", "URL=http://localhost:8080/manager/status", "TargetFrame=", "Resource=0", "Referer=", "Snapshot=t1.inf", "Mode=HTML", LAST); lr_user_data_point("Tomcat_JVM_FreeMemory",atof(lr_eval_string("{JVM_FreeMemory}"))); lr_user_data_point("Tomcat_JVM_TotalMemory",atof(lr_eval_string("{JVM_TotalMemory}"))); lr_user_data_point("Tomcat_JVM_MaxMemory",atof(lr_eval_string("{JVM_MaxMemory}"))); lr_user_data_point("Tomcat_HTTP_MaxThreads",atof(lr_eval_string("{HTTP_MaxThreads}"))); lr_user_data_point("Tomcat_HTTP_MaxProcessingTime",atof(lr_eval_string("{HTTP_MaxProcessingTime}"))); lr_user_data_point("Tomcat_HTTP_ProcessingTime",atof(lr_eval_string("{HTTP_ProcessingTime}"))); lr_user_data_point("Tomcat_HTTP_RequestCount",atof(lr_eval_string("{HTTP_RequestCount}"))); lr_user_data_point("Tomcat_HTTP_BytesReceived",atof(lr_eval_string("{HTTP_BytesReceived}"))); return 0; }
脚本完成,单击运行,然后···
检查了一下发现
这俩Action不一致,修改后运行脚本,ok了。
监控Tomcat的这段脚本代码放在新插入一个Action里面,并且放在之前录制来的业务脚本后面
然后就可以从Controller中观察到tomcat的运行状态了。
值得一提的是只有应用lr_user_data_point()函数,“User Defined Data Points”才处于可用状态。