You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2015/07/11 11:48:47 UTC

svn commit: r1690363 - in /jmeter/trunk: src/components/org/apache/jmeter/visualizers/backend/ src/components/org/apache/jmeter/visualizers/backend/graphite/ src/core/org/apache/jmeter/control/ xdocs/ xdocs/usermanual/

Author: pmouawad
Date: Sat Jul 11 09:48:47 2015
New Revision: 1690363

URL: http://svn.apache.org/r1690363
Log:
Bug 58122 - GraphiteBackendListener : Add Server Hits metric
This resolves #26
Bugzilla Id: 58122

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/SamplerMetric.java
    jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
    jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
    jmeter/trunk/src/core/org/apache/jmeter/control/TransactionSampler.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/realtime-results.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/SamplerMetric.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/SamplerMetric.java?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/SamplerMetric.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/SamplerMetric.java Sat Jul 11 09:48:47 2015
@@ -19,6 +19,7 @@
 package org.apache.jmeter.visualizers.backend;
 
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.jmeter.control.TransactionController;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.util.JMeterUtils;
 
@@ -40,6 +41,7 @@ public class SamplerMetric {
     private DescriptiveStatistics allResponsesStats = new DescriptiveStatistics(SLIDING_WINDOW_SIZE);
     private int successes;
     private int failures;
+    private int hits;
     /**
      * 
      */
@@ -65,6 +67,21 @@ public class SamplerMetric {
         }else {
             koResponsesStats.addValue(time);
         }
+        addHits(result);
+    }
+
+    /**
+     * Compute hits from res
+     * @param res {@link SampleResult}
+     */
+    private void addHits(SampleResult res) {     
+        SampleResult[] subResults = res.getSubResults();
+        if (!TransactionController.isFromTransactionController(res)) {
+            hits += 1;                 
+        }
+        for (int i = 0; i < subResults.length; i++) {            
+            addHits(subResults[i]);
+        }
     }
     
     /**
@@ -75,6 +92,7 @@ public class SamplerMetric {
         // http://commons.apache.org/proper/commons-math/userguide/stat.html
         successes = 0;
         failures = 0;
+        hits = 0;
     }
 
     /**
@@ -226,4 +244,12 @@ public class SamplerMetric {
     public double getAllPercentile(double percentile) {
         return allResponsesStats.getPercentile(percentile);
     }
+
+    /**
+     * Returns hits to server
+     * @return the hits
+     */
+    public int getHits() {
+        return hits;
+    }
 }

Modified: jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/visualizers/backend/graphite/GraphiteBackendListenerClient.java Sat Jul 11 09:48:47 2015
@@ -62,8 +62,8 @@ public class GraphiteBackendListenerClie
     private static final String METRIC_SEPARATOR = "."; //$NON-NLS-1$
     private static final String METRIC_OK_PREFIX = "ok"; //$NON-NLS-1$
     private static final String METRIC_KO_PREFIX = "ko"; //$NON-NLS-1$
-    private static final String METRIC_ALL_PREFIX = "a";
-
+    private static final String METRIC_ALL_PREFIX = "a"; //$NON-NLS-1$
+    private static final String METRIC_HITS_PREFIX = "h"; //$NON-NLS-1$
     
     private static final String METRIC_COUNT = "count"; //$NON-NLS-1$
     private static final String METRIC_MIN_RESPONSE_TIME = "min"; //$NON-NLS-1$
@@ -85,6 +85,8 @@ public class GraphiteBackendListenerClie
     private static final String METRIC_ALL_MAX_RESPONSE_TIME = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_MAX_RESPONSE_TIME;
     private static final String METRIC_ALL_PERCENTILE_PREFIX = METRIC_ALL_PREFIX+METRIC_SEPARATOR+METRIC_PERCENTILE;
 
+    private static final String METRIC_ALL_HITS_COUNT        = METRIC_HITS_PREFIX+METRIC_SEPARATOR+METRIC_COUNT;
+
     private static final long ONE_SECOND = 1L;
     private static final int MAX_POOL_SIZE = 1;
     private static final String DEFAULT_PERCENTILES = "90;95;99";
@@ -155,6 +157,8 @@ public class GraphiteBackendListenerClie
         graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_OK_COUNT, Integer.toString(metric.getSuccesses()));
         graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_KO_COUNT, Integer.toString(metric.getFailures()));
         graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_COUNT, Integer.toString(metric.getTotal()));
+        graphiteMetricsManager.addMetric(timestampInSeconds, contextName, METRIC_ALL_HITS_COUNT, Integer.toString(metric.getHits()));
+
         // See https://bz.apache.org/bugzilla/show_bug.cgi?id=57350
         if(metric.getTotal() > 0) { 
             if(metric.getSuccesses()>0) {

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/TransactionController.java Sat Jul 11 09:48:47 2015
@@ -43,6 +43,11 @@ import org.apache.log.Logger;
  *
  */
 public class TransactionController extends GenericController implements SampleListener, Controller, Serializable {
+    /**
+     * Used to identify Transaction Controller Parent Sampler
+     */
+    static final String NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX = "Number of samples in transaction : ";
+
     private static final long serialVersionUID = 233L;
     
     private static final String TRUE = Boolean.toString(true); // i.e. "true"
@@ -203,7 +208,7 @@ public class TransactionController exten
                 }
                 res.setIdleTime(pauseTime+res.getIdleTime());
                 res.sampleEnd();
-                res.setResponseMessage("Number of samples in transaction : " + calls + ", number of failing samples : " + noFailingSamples);
+                res.setResponseMessage(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX + calls + ", number of failing samples : " + noFailingSamples);
                 if(res.isSuccessful()) {
                     res.setResponseCodeOK();
                 }
@@ -217,6 +222,15 @@ public class TransactionController exten
 
         return returnValue;
     }
+    
+    /**
+     * @param res {@link SampleResult}
+     * @return true if res is the ParentSampler transactions
+     */
+    public static final boolean isFromTransactionController(SampleResult res) {
+        return res.getResponseMessage() != null && 
+                res.getResponseMessage().startsWith(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX);
+    }
 
     /**
      * @see org.apache.jmeter.control.GenericController#triggerEndOfLoop()
@@ -228,7 +242,7 @@ public class TransactionController exten
                 res.setIdleTime(pauseTime+res.getIdleTime());
                 res.sampleEnd();
                 res.setSuccessful(TRUE.equals(JMeterContextService.getContext().getVariables().get(JMeterThread.LAST_SAMPLE_OK)));
-                res.setResponseMessage("Number of samples in transaction : " + calls + ", number of failing samples : " + noFailingSamples);
+                res.setResponseMessage(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX + calls + ", number of failing samples : " + noFailingSamples);
                 notifyListeners();
             }
         } else {

Modified: jmeter/trunk/src/core/org/apache/jmeter/control/TransactionSampler.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/control/TransactionSampler.java?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/control/TransactionSampler.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/control/TransactionSampler.java Sat Jul 11 09:48:47 2015
@@ -126,7 +126,7 @@ public class TransactionSampler extends
         this.transactionDone = true;
         // Set the overall status for the transaction sample
         // TODO: improve, e.g. by adding counts to the SampleResult class
-        transactionSampleResult.setResponseMessage("Number of samples in transaction : "
+        transactionSampleResult.setResponseMessage(TransactionController.NUMBER_OF_SAMPLES_IN_TRANSACTION_PREFIX
                         + calls + ", number of failing samples : "
                         + noFailingSamples);
         if (transactionSampleResult.isSuccessful()) {

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Jul 11 09:48:47 2015
@@ -94,6 +94,7 @@ Summary
 <h3>Listeners</h3>
 <ul>
 <li><bug>58041</bug>Tree View Listener should show sample data type</li>
+<li><bug>58122</bug>GraphiteBackendListener : Add Server Hits metric. Partly based on a patch from Amol Moye (amol.moye at thomsonreuters.com)</li>
 </ul>
 
 <h3>Timers, Assertions, Config, Pre- &amp; Post-Processors</h3>
@@ -179,6 +180,7 @@ Summary
 <li>Benoit Vatan (benoit.vatan at gmail.com)</li>
 <li>Jérémie Lesage (jeremie.lesage at jeci.fr)</li>
 <li>Kirill Yankov (myworkpostbox at gmail.com)</li>
+<li>Amol Moye (amol.moye at thomsonreuters.com)</li>
 </ul>
 
 <br/>

Modified: jmeter/trunk/xdocs/usermanual/realtime-results.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/realtime-results.xml?rev=1690363&r1=1690362&r2=1690363&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/realtime-results.xml (original)
+++ jmeter/trunk/xdocs/usermanual/realtime-results.xml Sat Jul 11 09:48:47 2015
@@ -61,10 +61,12 @@ In this document we will present the con
     </dl>
     </subsection>
     <subsection name="&sect-num;.1.2 Response times metrics" anchor="metrics-response-times">
-    <p>Response times metrics are the following:</p>
+    <p>Response related metrics are the following:</p>
     <dl>
       <dh><code>&lt;rootMetricsPrefix&gt;.&lt;samplerName&gt;.ok.count</code></dh>
       <dd>Number of successful responses for sampler name</dd>
+      <dh><code>&lt;rootMetricsPrefix&gt;.&lt;samplerName&gt;.h.count</code></dh>
+      <dd>Server hits per seconds, this metric cumulates Sample Result and Sub results (if using Transaction Controller, "Generate parent sampler" should be unchecked)</dd>
       <dh><code>&lt;rootMetricsPrefix&gt;.&lt;samplerName&gt;.ok.min</code></dh>
       <dd>Min response time for successful responses of sampler name</dd>
       <dh><code>&lt;rootMetricsPrefix&gt;.&lt;samplerName&gt;.ok.max</code></dh>