码迷,mamicode.com
首页 > 其他好文 > 详细

LR监控tomcat服务器

时间:2018-12-16 11:11:24      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:mit   art   场景   文件   value   步骤   根据   status   param   

采用编写VuGen脚本访问Tomcat的Status页面的方式获取性能数据(利用了关联和lr_user_data_point函数),本质上还是使用tomcat自带的监控页面,只是将监控结果加到LR的analysis中。具体步骤如下:

1)首先确保Tomcat中创建了必要权限的用户(编辑Tomcat的\conf目录下的tomcat-users.xml文件),然后在LoadRunner中编写脚本(根据不同版本的tomcat监控结果中的监控数据项会有些差别,根据情况更改脚本):

double atof (const char *string); 
extern char* strtok(char *token, const char *delimiter); 

CollectMetrics()
{
    int countP, countS, countF, countR, countK;
    int numValues;
    static int loggedVersionInfo = FALSE; 

    lr_save_string("127.0.0.1:8080", "ServerName");
    web_set_max_html_param_len("65536"); 

    web_set_user("admin", 
        "admin", 
        "{ServerName}");

    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("HTTPMinSpareThreads",
        "LB=Min spare threads: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPMaxSpareThreads",
        "LB=Max spare threads: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPCurrentSpareThreads",
        "LB=Current thread count: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPCurrentThreadBusy",
        "LB=Current thread busy: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPMaxProcessingTime",
        "LB=Max processing time: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPRequestCount",
        "LB=Request count: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPErrorCount",
        "LB=Error count: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPBytesReceived",
        "LB=Bytes received: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("HTTPBytesSent",
        "LB=Bytes sent: ",
        "RB= ",
        "Ord=1",
        LAST);

    web_reg_save_param("JKMaxThreads",
        "LB=Max threads: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKMinSpareThreads",
        "LB=Min spare threads: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKMaxSpareThreads",
        "LB=Max spare threads: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKCurrentSpareThreads",
        "LB=Current thread count: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKCurrentThreadBusy",
        "LB=Current thread busy: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKMaxProcessingTime",
        "LB=Max processing time: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKRequestCount",
        "LB=Request count: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKErrorCount",
        "LB=Error count: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKBytesReceived",
        "LB=Bytes received: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_save_param("JKBytesSent",
        "LB=Bytes sent: ",
        "RB= ",
        "Ord=2",
        LAST);

    web_reg_find("Text=/manager", 
        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 度量数据
    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}")));

    // 写入Tomcat web server 度量数据
    lr_user_data_point("Tomcat HTTP Max threads", atof(lr_eval_string("{HTTPMaxThreads}")));
    lr_user_data_point("Tomcat HTTP Min spare threads", atof(lr_eval_string("{HTTPMinSpareThreads}")));
    lr_user_data_point("Tomcat HTTP Max spare threads", atof(lr_eval_string("{HTTPMaxSpareThreads}")));
    lr_user_data_point("Tomcat HTTP Current spare threads", atof(lr_eval_string("{HTTPCurrentSpareThreads}")));
    lr_user_data_point("Tomcat HTTP Current thread busy", atof(lr_eval_string("{HTTPCurrentThreadBusy}")));
    lr_user_data_point("Tomcat HTTP Max processing time", atof(lr_eval_string("{HTTPMaxProcessingTime}")));
    lr_user_data_point("Tomcat HTTP Request count", atof(lr_eval_string("{HTTPRequestCount}")));
    lr_user_data_point("Tomcat HTTP Error count", atof(lr_eval_string("{HTTPErrorCount}")));
    lr_user_data_point("Tomcat HTTP Bytes received", atof(lr_eval_string("{HTTPBytesReceived}")));
    lr_user_data_point("Tomcat HTTP Bytes sent", atof(lr_eval_string("{HTTPBytesSent}")));

    // 写入Tomcat servlet container 度量数据
    lr_user_data_point("Tomcat JK Max threads", atof(lr_eval_string("{JKMaxThreads}")));
    lr_user_data_point("Tomcat JK Min spare threads", atof(lr_eval_string("{JKMinSpareThreads}")));
    lr_user_data_point("Tomcat JK Max spare threads", atof(lr_eval_string("{JKMaxSpareThreads}")));
    lr_user_data_point("Tomcat JK Current spare threads", atof(lr_eval_string("{JKCurrentSpareThreads}")));
    lr_user_data_point("Tomcat JK Current thread busy", atof(lr_eval_string("{JKCurrentThreadBusy}")));
    lr_user_data_point("Tomcat JK Max processing time", atof(lr_eval_string("{JKMaxProcessingTime}")));
    lr_user_data_point("Tomcat JK Request count", atof(lr_eval_string("{JKRequestCount}")));
    lr_user_data_point("Tomcat JK Error count", atof(lr_eval_string("{JKErrorCount}")));
    lr_user_data_point("Tomcat JK Bytes received", atof(lr_eval_string("{JKBytesReceived}")));
    lr_user_data_point("Tomcat JK Bytes sent", atof(lr_eval_string("{JKBytesSent}")));

    return 0;
}

2)然后在Run-time中设定数据收集的间隔:

      技术分享图片

3)最后在Controller中设置脚本运行,这样场景运行完毕后,即可在Analysis中添加“User Defined Data Points”查看收集到的Tomcat性能数据:

      技术分享图片

     这种收集数据的弊端是需要通过网络请求Tomcat的页面,会对Tomcat服务器的性能造成一定的影响如果Tomcat出现性能瓶颈,则收集数据时也可能碰到连接错误,因此,最好把收集数据点的间隔设大一点,例如5秒~10秒收集一个数据点。或尽量不采用LR监控。

 

LR监控tomcat服务器

标签:mit   art   场景   文件   value   步骤   根据   status   param   

原文地址:https://www.cnblogs.com/yezhaohui/p/10125572.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!