51Testing软件测试论坛

标题: loadrunner监控tomcat解决方案 [打印本页]

作者: zhsh1203    时间: 2009-3-6 16:09
标题: loadrunner监控tomcat解决方案
利用空闲的时间写了个监控tomcat服务器的方法,一起沟通交流和学习!

loadrunner监控tomcat:

第一种:
LR本身是不支持的!有两种方式可以集成!
1、自己写一个批处理程序去取tomcat的数据
2、使用sitescope去执行这个批处理,然后采集数据
3、使用LR与sitescope集成,然后读取数据

第二种:
1、通过LR去访问tomcat监控页
2、然后通过关联取监控数据
3、使用lr_user_data_point()添加数据到图表中去

关于第二种具体解决方案如下:(监控tomcat服务器:http://192.168.1.173:1203)

1、打开Tomcat的status页面,方法为编辑Tomcat的conf目录下的tomcat-users.xml文件,在文件中添加
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="pass" roles="admin,manager"/>
</tomcat-users>

2、开发lr脚本

vuser_init()
{
//定义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","pass","192.168.1.173:1203");

  web_url("status",
        "URL=http://192.168.1.173:1203/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}")));
return 0;
}

运行脚本后,在脚本日志显示效果图如下:(附件)
运行场景后,在analysis显示的效果图如下:(附件)

[ 本帖最后由 zhsh1203 于 2009-3-8 20:01 编辑 ]
作者: 看雪时节    时间: 2009-3-12 13:40

作者: qiubingshun    时间: 2009-3-13 14:13
好帖子呀,谢谢!
作者: jiangduxi    时间: 2009-3-26 21:46
好东西! 真希望拜你为师
作者: aks5201314    时间: 2009-3-27 10:15
好帖子,学习了!
作者: archonwang    时间: 2009-3-27 15:27
好贴,严重支持。
作者: jacquiyan    时间: 2009-4-8 09:42
你的脚本有个缺陷,就是输出的数字和从tomcat页面读取的不一样。
vuser_init.c(43): Notify: Parameter Substitution: parameter "JVMFreeMemory" =  "75.89"
vuser_init.c(43): Notify: Data Point "Tomcat JVM Free memory" value = 1309672.0000.
vuser_init.c(44): Notify: Parameter Substitution: parameter "JVMTotalMemory" =  "87.12"
vuser_init.c(44): Notify: Data Point "Tomcat JVM Total memory" value = 1309672.0000.
vuser_init.c(45): Notify: Parameter Substitution: parameter "JVMMaxMemory" =  "1888.00"
vuser_init.c(45): Notify: Data Point "Tomcat JVM Max memory" value = 1309672.0000.

那是因为atof函数转换成double时数值都变了样,需要显示定义下,在"vuser_init(){"这句话的
代码前面加上
double atof (const char *string);就ok了。
下面是正确的日志
vuser_init.c(43): Notify: Parameter Substitution: parameter "JVMFreeMemory" =  "76.08"
vuser_init.c(43): Notify: Data Point "Tomcat JVM Free memory" value = 76.0800.
vuser_init.c(44): Notify: Parameter Substitution: parameter "JVMTotalMemory" =  "87.31"
vuser_init.c(44): Notify: Data Point "Tomcat JVM Total memory" value = 87.3100.
vuser_init.c(45): Notify: Parameter Substitution: parameter "JVMMaxMemory" =  "1888.00"
vuser_init.c(45): Notify: Data Point "Tomcat JVM Max memory" value = 1888.0000.
作者: qinxiaocang1202    时间: 2009-4-8 15:11
正要实用,谢谢了!!学习学习
作者: gup21cn    时间: 2009-4-9 18:08
ding
作者: jacquiyan    时间: 2009-4-11 22:49
我发现这个脚本不知道怎么搞的,长时间运行后,察看结果图,只有三个点,没有形成曲线.运行几分钟反而有曲线.
请问怎么解决阿?
作者: 断寒    时间: 2009-4-14 14:48
标题: 回复 11# 的帖子
你把代码放到ACTION()里面去试下看看
作者: aaa01    时间: 2009-4-21 15:30
我就是按楼主说的第二种方法做的, 但是在脚本回放的时候出错了:

vuser_init.c(31): Error -26630: HTTP Status-Code=401 (Unauthorized) for "http://192.168.(*).(*):8000/manager/status"          [MsgId: MERR-26630]
vuser_init.c(31): Error -26377: No match found for the requested parameter "JVMFreeMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(31): Error -26377: No match found for the requested parameter "JVMTotalMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(31): Error -26377: No match found for the requested parameter "JVMMaxMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(31): web_url("status") highest severity level was "ERROR", 954 body bytes, 296 header bytes          [MsgId: MMSG-26388]
vuser_init.c(31): Notify: Transaction "monitor tomcat" ended with "Fail" status (Duration: 4.9891 Wasted Time: 0.0000).

打不开tomcat的status页面, 但是可以手工输入admin , pass密码就可以进去, 不清楚这是为什么,希望帮忙能回答一下, 非常感谢了!
作者: aaa01    时间: 2009-4-22 13:47
谁知道这个问题怎么解决吗? 谢谢了!
作者: fwind1    时间: 2009-5-17 22:56
强人啊
作者: li_longcai    时间: 2009-5-29 16:08
标题: 学习了
学习了
作者: beiyu95    时间: 2009-5-31 10:53
思路挺好。如果要看jvm相关情况直接用jconsole好了,如果要看server status,直接用manager去看看即可。如果你非要tomcat的完整监控给大家推荐adventnet的 manageengine.
作者: xhgirl01    时间: 2009-6-26 12:23
学习中!
作者: rting    时间: 2009-7-2 17:46
不错 顶起来
作者: 青苹果Testing    时间: 2009-7-29 15:41

作者: baobao_2008    时间: 2009-7-31 09:33
好帖!!!!!!!!!!!1
作者: hrob    时间: 2009-8-21 15:41
我用这个方法设置tomcat登录的时候一直都报错:

Virtual User Script started
Starting action vuser_init.
Web Turbo Replay of LoadRunner 9.10.0 for Windows Vista; WebReplay85 build 5896          [MsgId: MMSG-27143]
Run Mode: Click-and-Script          [MsgId: MMSG-26000]
Run-Time Settings file: "C:\Users\ibm\workspace\lr\login\\default.cfg"          [MsgId: MMSG-27141]
Current locale is "Chinese Simplified (GB2312)", code page 936, preferred charset name "gb2312", Unicode converter name="gb2312", CRT locale string="Chinese (Simplified)_People's Republic of China.936"          [MsgId: MMSG-27045]
vuser_init.c(5): Notify: Transaction "monitor tomcat" started.
vuser_init.c(8): Registering web_reg_save_param was successful          [MsgId: MMSG-26390]
vuser_init.c(13): Registering web_reg_save_param was successful          [MsgId: MMSG-26390]
vuser_init.c(19): Registering web_reg_save_param was successful          [MsgId: MMSG-26390]
vuser_init.c(25): web_set_user was successful          [MsgId: MMSG-26392]
vuser_init.c(26): Warning -26630: HTTP Status-Code=401 (Unauthorized) for "http://122.122.1.15:888/manager/status"          [MsgId: MWAR-26630]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMFreeMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMTotalMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMMaxMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): web_url("status") highest severity level was "ERROR", 3666 body bytes, 466 header bytes          [MsgId: MMSG-26388]
vuser_init.c(26): Notify: Transaction "monitor tomcat" ended with "Fail" status (Duration: 0.2528 Wasted Time: 0.0001).
Abort was called from an action.

程序片段:
web_set_user("122.122.1.15\\admin","123","122.122.1.15:888");
          web_url("status",
                        "URL=http://122.122.1.15:888/manager/status",
                        "Resource=0",
                        "RecContentType=text/html",
                        "Referer=",
                        "Snapshot=t1.inf",
                        "Mode=HTTP",
                LAST);
在论坛里找了好多帖子,也检查了很多遍,都没有发现问题
直接开IE用admin和123是可以登进去的,IE是8.0的LR是9.1的
122.122.1.15这个IP就是我本机的,tomcat也是本机启的,
我还用localhost、127.0.0.1和本机的计算机名试过,都是报一样的错
高手来指点一下啊

[ 本帖最后由 hrob 于 2009-8-21 15:52 编辑 ]
作者: hrob    时间: 2009-8-21 17:43
明明就提示 web_set_user was successful 了
怎么还是没有权限呢
作者: alexanty    时间: 2009-9-3 22:25
好帖。
作者: yangxiaojing_6    时间: 2009-9-24 15:25
受益了,谢谢。
作者: yangxiaojing_6    时间: 2009-9-24 16:49
标题: Legend中,各个列的单位是什么
楼主,有一个疑问,JVMFreeMemory、JVMMaxMemory、JVMTotalMemory中,三个数值在Analysis的Legend中,各个数值(Minmus,MaxMum等)是以什么单位显示的?   谢谢。
作者: 24766504    时间: 2009-9-25 15:47
好贴,支持原创~~
前两天用了下 jprofile监测tomcat,那东东产生的图表 太多了 看不懂~~
还是简单点的好~~
作者: jacksboy    时间: 2009-11-11 16:52
非常感谢
作者: ljonathan    时间: 2009-11-11 23:03
向楼主学习

JProbe——有兴趣的可以试下
作者: webyabo    时间: 2009-11-24 15:52
标题: 回复 13# 的帖子
我也遇到此问题,重启tomcat,即可
作者: wo_cui    时间: 2009-12-4 17:03

作者: kuangquanshui    时间: 2009-12-4 18:08

作者: 小露宝    时间: 2010-2-2 09:48
正在查找有关方面的资料,谢谢了
作者: walksky2003    时间: 2010-3-23 10:56
点评一下:
  LZ属于优秀人才
作者: xiaorong523    时间: 2010-5-13 13:25
非常感谢,收藏了
作者: 丫崽儿    时间: 2010-5-13 15:09
不错 正要用,
作者: 王絮    时间: 2010-10-15 12:56
谢谢楼主分享!!!!
作者: cjp110212    时间: 2010-10-15 16:35
高手,必须顶,下来看看,多谢
作者: xiyufenfei    时间: 2010-10-15 16:51
不错的文章  谢谢分享
作者: beauty330804    时间: 2011-6-8 14:38
回复 13# aaa01
你检查一下,你tomcat 的conf目录下的tomcat-user.xml文件中有没有添加
<tomcat-users>
  <role rolename="manager"/>
  <role rolename="admin"/>
  <user username="admin" password="pass" roles="admin,manager"/>
</tomcat-users>
我有时候也会出现这个问题,回头检查tomcat-user.xml,原来添加的用户竟然没有啦,呵呵,也没有找出什么原因!反正加上就可以了,呵呵~~~
作者: radii    时间: 2011-6-8 15:15
你们都太牛气了!!
作者: beauty330804    时间: 2011-6-9 15:14
回复 26# yangxiaojing_6
应该是MB吧,因为编写的脚本里写的右边界的值是MB --"RB=MB”
作者: candyzc    时间: 2011-7-26 11:22
这个太赞了,谢谢
作者: 爱夏眠的蜗牛    时间: 2011-8-18 11:18
受教了。~!
作者: musk    时间: 2011-9-21 17:52
可以用,谢谢LZ了!
作者: wangyanzhao    时间: 2011-11-10 13:59
回复 13# aaa01


    把脚本贴出来 看看
作者: siemens800    时间: 2011-11-18 11:22
kankan
作者: 零测试    时间: 2011-11-18 12:54
学习了
作者: lycan_322    时间: 2011-11-18 16:37
没能理解  脚本放在init里,只运行一次 ,能跟着action事务么,这是实时监控、=?
作者: pl80601983    时间: 2012-3-23 17:29
很好,严重支持一下。
作者: pangda    时间: 2012-3-26 15:59
我先收藏
作者: xppxyy    时间: 2012-3-26 17:48

作者: 丁宁咔叽    时间: 2012-3-27 11:36

作者: gary116    时间: 2012-3-28 14:22
学习中
作者: QQ表情    时间: 2012-4-19 10:49
就应该多一些这样的贴子,顶
作者: 花与剑    时间: 2012-4-19 15:56
啊啊
作者: zzting    时间: 2012-5-2 16:42
学习啦!
作者: iter777    时间: 2012-5-2 18:11
支持研究探讨。说实话我现在再做一个web项目,也要求找一个监控工具,在最初调研的时候也考虑过用lr监控,但其功能有限;而想配合sitescope做全面的监控,却发现这个东东实在不好用,而且也有license的问题,最后选择了ManagerEngine的applicationManagement,非常好用的东东,关键是免费
作者: dhl0613    时间: 2012-8-1 17:47
本帖最后由 dhl0613 于 2012-8-1 17:57 编辑

回复 1# zhsh1203

除了IP和端口不一样外,脚本都是一样滴!为什么回放脚本时,报下面这些错?
vuser_init.c(26): Error -27796: Failed to connect to server "192.168.1.192:8005": [10061] Connection refused          [MsgId: MERR-27796]
vuser_init.c(26): Warning -26000: Empty or no response for URL="http://192.168.1.192:8005/manager/status"          [MsgId: MWAR-26000]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMFreeMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMFreeMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): Error -26377: No match found for the requested parameter "JVMFreeMemory". Check whether the requested boundaries exist in the response data. Also, if the data you want to save exceeds 256 bytes, use web_set_max_html_param_len to increase the parameter size          [MsgId: MERR-26377]
vuser_init.c(26): Error -26374: The above "not found" error(s) may be explained by header and body byte counts being 0 and 0, respectively.          [MsgId: MERR-26374]
vuser_init.c(26): web_url("status") highest severity level was "ERROR", 0 body bytes, 0 header bytes          [MsgId: MMSG-26388]
vuser_init.c(26): Notify: Transaction "monitor tomcat" ended with "Fail" status (Duration: 1.9176 Wasted Time: 0.5290).

部分脚本如下:
web_set_user("admin","admin","192.168.1.192:8005");

web_url("status",
   "URL=http://192.168.1.192:8005/manager/status",
   "Resource=0",
   "RecContentType=text/html",
   "Referer=",
   "Snapshot=t1.inf",
   "Mode=HTTP",
   LAST);
作者: 喝茶不喝酒    时间: 2012-8-1 20:41
好帖子当然要顶起来!
作者: dionysus    时间: 2012-8-12 19:31
学习了,谢谢楼主
作者: hf5208332    时间: 2012-8-20 10:24
学习了,有监测Mysql的吗?
作者: hf5208332    时间: 2012-8-20 10:25
学习了,有监测Mysql的吗?
作者: hf5208332    时间: 2012-8-20 10:29
学习了,有监测Mysql的吗?
作者: cross1900    时间: 2012-12-11 14:26
感谢啊~! 谢谢LZ
作者: kallen    时间: 2019-1-16 12:39
好帖子,学习了




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2