Custom Script for current Hits and Total Hits

rvmsengrvmseng Posts: 55

Hi Dear Support Team,

I need two graphs to show "Current Hits" (Hit per second) and "Total Hits".

How can I write a custom monitoring script to get current and total hits?

Comments

  • SergeiSergei Posts: 20

    Load Test displays the Hit per Second rate as 'Test Start Rate' and 'Test Completion Rate' graphs. You can think of 'Test Start Rate' as a request injection rate in hits per second, and 'Test Completion Rate' as the Application Under Test (AUT) response rate in hits per second. You can choose either one or the other for your 'Current Hits' (hit per second) depending whether you want to monitor request injection or response rate.

    With regards to the 'Total Hits' - could you clarify what exactly you would like this graph to reflect:

    a. The number of hits (AUT responses) accumulated since the beginning of the load test.
    b. The number of hits (AUT responses) since the last load test result collection. The result collections occur with an approximate 3 second interval during a load test run.
    c. Something else. If so please clarify.

  • rvmsengrvmseng Posts: 55
    edited July 17

    Dears Sergei ,

    Thank you for your useful description,

    I need "Total Hits Graph" to get number of Hits that I have sent from beginning of test till current time.

    For example you suppose that my HPS (Hit Per Second) in time A is 5 and my total Hits from beginning to time A is 46.

    with regards your description I can find HPS with "Test Start Rate" or "Test Completion Rate", but How can I get "Total Hits Graph"?

  • rvmsengrvmseng Posts: 55
    edited July 17

    Also I want to know why following script not work in Custom monitoring?

    def getTotalHits(args):
    
        output = args.getOutput()
        hits = output.getHitCount([],[])
    
        return hits 
    

    whats is "args"? and how can I get it? and what is deference it with context?

  • SergeiSergei Posts: 20

    LoadTestOutput is available for scripted QoS metrics, it is not available for the scripted monitors.

    The reason is that in Load Test the monitor results collection happens asynchronously from the main result data collection that populates the LoadTestOutput. The reason for this is to prevent potentially slow monitor result collection from blocking the main load test result collection by decoupling them.

    It is possible however to get an approximation of you are trying to achieve with the following Groovy script:

    import java.util.*;
    import com.parasoft.simulator.*;
    import com.parasoft.simulator.output.*;
    import com.parasoft.api.loadtest.output.*;
    
    int getAccumulatedHits() {
        int runCount = 0;
        LoadTestOutput output = new LoadTestOutputImpl(Simulator.instance().getOutput());
        LoadTestResultSet mergedOutput = output.getMergedOutput(output.getMachineNames(), output.getProfileNames());
        mergedOutput.resetRowIterator();
        while(mergedOutput.hasNextRow()) {
            Map row = mergedOutput.nextRow();
            String testName = row.get(GenericOutputAttributes.TEST_NAME);
            System.out.println(testName);
            if (!(testName.contains("Test Suite") || testName.contains("Scenario"))) {
                runCount += row.get(GenericOutputAttributes.RUN_COUNT);
            }
        }
        return runCount;
    }
    

    The asynchronous nature of monitor results collection mentioned above will make this monitor results lag behind the built in graphs such as Test Completion Rate. In this sense this monitor will give you a hit count number that will in most cases be behind by one data collection point. Keep in mind, if you need to get the exact accumulated hit count at the end of a load test you can easily do that with a built in Count QoS metric that will give you the exact hit count that you can also filter.

    About the script: note the

    LoadTestOutput output = new LoadTestOutputImpl(Simulator.instance().getOutput());

    call is a non API call, but this allows you to get the LoadTestOutput API object that you can query. Also I recommend using the LoadTestOutput.getMergedOutput() call rather than LoadTestOutput.getHits() as you can filter out the Test hits out of all hits that contain Tests, Test Suites and Scenarios. In GUI you can apply custom filters to the standard graphs such as Test Completion Rate using the graph filter panel. The default filter for the built in graphs is the All Tests filter.

  • rvmsengrvmseng Posts: 55
    edited July 18

    Dear Sergei

    thank you so much, I have an issue still. my custom monitoring item does not exist in graphs list

    please refer to following images.



  • SergeiSergei Posts: 20

    When I was testing this I had a few channels in the custom monitor, so I could find the best solution for your case. I've been able to reproduce your case by having just one channel in the monitor. You could add a dummy helper channel like below to the Custom monitor to have both of them appear in the graph:

    int helper() {
        return 0;
    }
    

    Meanwhile I filed PR LT-1224 to address this inconsistency in Load Test behavior.

  • rvmsengrvmseng Posts: 55
    edited July 21

    Dear Sergei,

    I added helper, but "TotalHits" not appear yet.


    I found root cause of this issue, please refer to following command:
    LoadTestOutput output = new LoadTestOutputImpl(Simulator.instance().getOutput());

    when I remove "LoadTestOutput" from code, "TotalHits" appear.

  • SergeiSergei Posts: 20

    Try the updated script with a null check:

    import java.util.*;
    import com.parasoft.simulator.*;
    import com.parasoft.simulator.output.*;
    import com.parasoft.api.loadtest.output.*;
    
    int getAccumulatedHits() {
        int runCount = 0;
        SimulationOutput so = Simulator.instance().getOutput();
        if (so != null) {
            LoadTestOutput output = new LoadTestOutputImpl(so);
            LoadTestResultSet mergedOutput = output.getMergedOutput(output.getMachineNames(), output.getProfileNames());
            mergedOutput.resetRowIterator();
            while(mergedOutput.hasNextRow()) {
                Map row = mergedOutput.nextRow();
                String testName = row.get(GenericOutputAttributes.TEST_NAME);
                System.out.println(testName);
                if (!(testName.contains("Test Suite") || testName.contains("Scenario"))) {
                    runCount += row.get(GenericOutputAttributes.RUN_COUNT);
                }
            }
        }
        return runCount;
    }
    

    If this still does not work for you I recommend contacting Parasoft support as we'll need to collect additional details, such as your SOAtest/Load Test version etc. to find out why this script is not working on your side.

Sign In or Register to comment.