1

In Grinder we'd like to add customized statistics

grinder.statistics.registerSummaryExpression("connTimeout", "userLong0")

grinder.statistics.forCurrentTest.addLong("userLong0", 1)

And it seems to be successful as we can get the customized field in Grinder out file The problem is that the value of that statistics is always 0

Here is the complete script implemented by Jython

# -*- coding: utf-8 -*-

from net.grinder.script.Grinder import grinder
from net.grinder.script import Test

from com.netease.cloud.ndir.performance import Query
from com.netease.cloud.ndir.performance import QueryReturnCode

def writeToFile(text):
    filename = "response.log"
    file = open(filename, "a")
    file.write(str(text) + "\n")
    file.close() 

ndir_client = grinder.getProperties().getProperty("ndirClient")
query_file = grinder.getProperties().getProperty("queryFile")

request = Query("grinder.properties", query_file)

grinder.statistics.registerSummaryExpression("connTimeout", "userLong0")
grinder.statistics.registerSummaryExpression("readTimeout", "userLong1")
grinder.statistics.registerSummaryExpression("code!=200", "userLong2")
grinder.statistics.registerSummaryExpression("docs=[]", "userLong3")
grinder.statistics.registerSummaryExpression("unknown", "userLong4")


class TestRunner:

    def __init__(self):
        grinder.statistics.delayReports=True

    def initialSleep(self):
        sleepTime = grinder.threadNumber * 20  # per thread
        grinder.sleep(sleepTime, 0)

    def query(self):
        if ndir_client == "true":
            query = request.randomQueryByNdirClient
        else:
            query = request.randomQueryByHttpGet
        try:
            result = query()
        except:
            writeToFile("exception")
            grinder.statistics.forCurrentTest.addLong("userLong4", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(False)
            return
        if result == 0:
            grinder.getStatistics().getForCurrentTest().setSuccess(True)
            return
        elif result == 1:
            grinder.statistics.forCurrentTest.addLong("userLong0", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(False)
            return
        elif result == 2:
            grinder.statistics.forCurrentTest.addLong("userLong1", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(False)
            return
        elif result == 3:
            grinder.statistics.forCurrentTest.addLong("userLong2", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(False)
            return          
        elif result == 4:
            grinder.statistics.forCurrentTest.addLong("userLong3", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(True)    
            return
        else:
            grinder.statistics.forCurrentTest.addLong("userLong4", 1)
            grinder.getStatistics().getForCurrentTest().setSuccess(False)
            return

    request = Test(120, 'query').wrap(query)

    def __call__(self):
        if grinder.runNumber == 0: 
            self.initialSleep()
        self.request(self)
frank
  • 13
  • 2

1 Answers1

4

I suspect the problem is that you are marking tests as failed, but expecting the statistics to appear in the summary. Only successful tests are accumulated into the summary statistics.

Try registering data log expressions as well

grinder.statistics.registerDataLogExpression("connTimeout", "userLong0")
grinder.statistics.registerDataLogExpression("readTimeout", "userLong1")
grinder.statistics.registerDataLogExpression("code!=200", "userLong2")
grinder.statistics.registerDataLogExpression("docs=[]", "userLong3")
grinder.statistics.registerDataLogExpression("unknown", "userLong4")

Then you'll at least see the values in the data log file of the worker process.

Philip Aston
  • 193
  • 1
  • 6
  • Thanks for the reply and you're right, once I set all the test to successful the statistics' value will be there. But the problem is that data log in not automatically aggregated, then do the aggregation by its own script? – frank May 06 '14 at 06:35
  • Correct. The Grinder deliberately doesn't aggregate stats for failed tests - the times might follow some other distribution, so it makes little sense. Alternatively, you could record the information against another Test that you don't mark as failed. – Philip Aston May 06 '14 at 12:00
  • Thanks for the tips, and it is working when making another Test for statistics recording. The problem is that this Test also has "TPS" which makes the value of "Totals" meaningless – frank May 07 '14 at 07:50