Learning center

FAQ

All commonly asked questions are posted here. Questions are classified by gategories to help you quickly access answers - click on a category below. Feel free to contact us if you are not able to find the answer here.

How do I create new result metrics?

Load Impact collects a lot of different result metrics by default, but sometimes you might want to measure something specific that we don’t currently include in the standard suite of metrics. This is where our custom metrics functionality comes in handy.

Custom metrics are very easy to use. Basically, you just calculate a sample point for your metric, then you call the result.custom_metric() function to store and aggregate the sample. You can store as many samples as you like, but if more than one sample is stored in the same 3-second period, an average value will be computed and stored instead of the two (or more) individual values.

Example:

 -- Measure the time it takes to complete several HTTP requests, 
 -- and then store that time as the result metric "total_load_time"
 start_time = util.time()
 http.request_batch({
    { "GET", "http://loadimpact.com", nil, { ["X-Myheader"]="Something" } },
    { "GET", "http://loadimpact.com/image1.jpg" },
    { "POST", "http://loadimpact.com/login_ajax.php", nil, { ["X-Anotherheader"]="Something Else" }, "login=test&password=test" }
 })
 end_time = util.time()
 result.custom_metric("total_load_time", end_time - start_time)

All metrics that you collect yourself in this way will of course be available on the test report page, allowing you to plot graphs of your metrics etc. just as with the built-in metrics.


See also: - The Load Impact load script tutorial
 - The Load Impact load script API – result module


Permalink