Monitoring Tomcat with LoadRunner

LoadRunner does not come with a monitor for Tomcat. Fortunately, you can easily create one in about 5 minutes…

Tomcat exposes metrics related to JVM memory and Servlet container threads (and some other useful information) on a Status page at <Server Name>/manager (ask your Tomcat admin to enable it).

Tomcat Status page

Create a standard web vuser script which loads the Tomcat Status page, and capture all the metrics you want using web_reg_save_param. Then log these values using lr_user_data_point. The metrics will be visible in the LoadRunner Controller and also in LoadRunner Analysis on the User-Defined Data Points Graph.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
lr_start_transaction("monitor tomcat");
 
/*
<h1>JVM</h1><p> Free memory: 130.99 MB Total memory: 254.18 MB Max memory: 1016.12 MB</p>
*/
 
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_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 metrics
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}")));

An example script is available for download here [7 KB].

4 comments

Have you tried using multiple data point objects?
Something like this:
lr_user_data_point(“JVM Free Memory”, atoi(lr_eval_string(“{JVMFreeMemory}”)));
lr_user_data_point(“HTTPS Active Threads”, atoi(lr_eval_string(“{HTTPSActiveThreads}”)));
lr_user_data_point(“HTTPS Current Threads”, atoi(lr_eval_string(“{HTTPSCurrentThreads}”)));

I am able to capture the metrics but while running the script in controller displays only one graph with only one measurement.

Any Suggestions?

Hello,

I write a jmx client tool in java, and i use it to monitor tomcat, jboss, jonas … and i create also user_data_point.

Unfortunately, you must have the Templates Bundle license to use it (java template).

[Stuart’s Reply:
Thanks for your comment. I agree that JMX is a much nicer way to monitor a Java app server. Unfortunately, as you noted, it requires an additional license.

It would be great if HP would include 1 Java Template vuser (and maybe 1 Microsoft .Net vuser) with each LoadRunner license so that they could be used for monitoring.

I have already requested that they enhance the lr_user_data_point function so that people can more easily create monitors for unsupported applications, but perhaps this would be another good feature request.]

For information, you could receive informations from Tomcat in XML format with :
/manager/status?XML=true

response extract :

….

Very interesting article. I plan on using this to test a tomcat application now. I am assuming you just configure this script to run with a pacing of 15-30 seconds (or how ever often you want to collect metrics) and then have it run for the length of the scenario?

Thanks for the excellent tip :)

[Stuart’s Reply:
Yes, that’s the idea. I like to use a pacing interval of 5 seconds, so that I get a fairly high level of granularity.

Note that you will probably have to modify the script a little depending on the number of JVMs, web servers and servlet containers you have configured.

Good luck with your testing!]

Leave a Reply