User defined statistic in nGrinder

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

User defined statistic in nGrinder

Mavlarn

Post in wiki:

http://www.cubrid.org/wiki_ngrinder/entry/user-defined-statistic-in-ngrinder 

 

Maybe you know that "The Grinder" supports user defined statistic. If you define and put some value in the script, then this filed can be saved in data log or summary data. You can check the example script for this from:

http://grinder.sourceforge.net/g3/script-gallery.html#jmsreceiver.py

But in ngrinder, in previous 3.1.2 version, you can not see that data in test report. But from version 3.1.2, you can see that data in report chart.

The sample script is below: 

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
43
44
45
46
47
48
49
50
# -*- coding:utf-8 -*-
 
# A simple example using the HTTP plugin that shows the retrieval of a
# single page via HTTP.
#
# This script is auto generated by ngrinder.
#
# @author admin
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPRequest
from net.grinder.plugin.http import HTTPPluginControl
from java.util import Random
 
control = HTTPPluginControl.getConnectionDefaults()
# if you don't want that HTTPRequest follows the redirection, please modify the following option 0.
# control.followRedirects = 1
# if you want to increase the timeout, please modify the following option.
control.timeout = 6000
 
test1 = Test(1"Test1")
request1 = HTTPRequest()
 
grinder.statistics.registerDataLogExpression("User_defined""userLong0")
 
# Make any method call on request1 increase TPS
test1.record(request1)
random = Random()
 
class TestRunner:
    # initlialize a thread
    def __init__(self):
        grinder.statistics.delayReports=True
        pass
 
    # test method       
    def __call__(self):
        result = request1.GET("http://www.baidu.com")       
        # do something
        deliveryTime = random.nextInt(1000)
        sleet(deliveryTime)
        grinder.statistics.forCurrentTest.setValue("userLong0", deliveryTime)
         
        if result.getStatusCode() == 200 :
            grinder.statistics.forLastTest.success = 1
        elif result.getStatusCode() in (301302) :
            grinder.logger.warn("Warning. The response may not be correct. The response code was %d." %  result.getStatusCode())
            grinder.statistics.forLastTest.success = 1
        else :
            grinder.statistics.forLastTest.success = 0

Currently, only one chart can be displayed for the user defined statistic, and the name of this statistic should be “User_defined”. For more detailed description of usage, you can refer the document of grinder:

registerSummaryExpression

After running a test with this script, you can see the chart for user defined statistics in the detailed report.

image