changeset 889:05a158902216

in progress
author Devel 1
date Mon, 26 Mar 2018 14:41:30 +0200
parents b9d643afb2fc
children 688a28cd5792
files stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java stress-tester/src/main/java/com/passus/st/job/TestJob.java
diffstat 2 files changed, 32 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Mon Mar 26 13:03:43 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/GlobalConfigMain.java	Mon Mar 26 14:41:30 2018 +0200
@@ -4,9 +4,14 @@
 import com.passus.config.YamlConfigurationReader;
 import com.passus.config.validation.Errors;
 import com.passus.st.job.TestJob;
+import com.passus.st.metric.MetricsCollector;
+import com.passus.st.metric.SummaryMetricsCollectionHandler;
 import org.apache.commons.cli.*;
 
 import java.io.File;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
 
 public class GlobalConfigMain {
 
@@ -52,6 +57,15 @@
                 cliHelper.printError(sb.toString());
             }
 
+            MetricsCollector metricsCollector = testJob.getMetricsCollector();
+            if (metricsCollector != null) {
+                SummaryMetricsCollectionHandler summMetricsHandler = new SummaryMetricsCollectionHandler();
+                metricsCollector.addHandler(summMetricsHandler);
+                ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+                final long startTime = System.currentTimeMillis();
+                executor.scheduleAtFixedRate(() -> Main.printMetrics(summMetricsHandler.getMetrics(), startTime), 5, 5, TimeUnit.SECONDS);
+            }
+
             testJob.start();
 
         } catch (ParseException e) {
@@ -64,7 +78,7 @@
         }
     }
 
-    public static void main(String[] args) {
+    public static void main(String... args) {
         new GlobalConfigMain().start(args);
     }
 
--- a/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Mon Mar 26 13:03:43 2018 +0200
+++ b/stress-tester/src/main/java/com/passus/st/job/TestJob.java	Mon Mar 26 14:41:30 2018 +0200
@@ -44,7 +44,7 @@
 
     private List<HttpClientListener> httpClientListener;
 
-    private MetricsCollector metricsCollector = new ScheduledMetricsCollector();
+    private MetricsCollector metricsCollector;
 
     public TestJob() {
     }
@@ -85,12 +85,6 @@
         this.metricsCollector = metricsCollector;
     }
 
-    private void registerMetricSource(MetricSource metricSource) {
-        if (metricsCollector != null) {
-            metricsCollector.register(metricSource);
-        }
-    }
-
     private void prepare() {
         LOGGER.debug("Preparing job...");
         if (defaultEmitter == null) {
@@ -103,11 +97,13 @@
             }
         }
 
-        emitters.forEach(emitter -> {
-            if (emitter.isCollectMetrics()) {
-                registerMetricSource(emitter);
-            }
-        });
+        if (metricsCollector != null) {
+            emitters.forEach(emitter -> {
+                if (emitter.isCollectMetrics()) {
+                    metricsCollector.register(emitter);
+                }
+            });
+        }
 
         clients.forEach(client -> {
             if (client.getEmitter() == null) {
@@ -121,7 +117,9 @@
             }
 
             if (client.isCollectMetrics()) {
-                registerMetricSource(client);
+                if (metricsCollector != null) {
+                    metricsCollector.register(client);
+                }
             }
         });
     }
@@ -129,7 +127,9 @@
     @Override
     public void start() {
         prepare();
-        metricsCollector.start();
+        if (metricsCollector != null) {
+            metricsCollector.start();
+        }
         emitters.forEach(Emitter::start);
         clients.forEach(Client::start);
     }
@@ -183,6 +183,9 @@
         List<Emitter> cfgEmitters = (List<Emitter>) context.get(EMITTER_EMITTERS);
         populateIfNotNull(cfgEmitters, testJob.emitters);
         testJob.defaultEmitter = (Emitter) context.get(EMITTER_DEFAULT_EMITTER);
+
+        testJob.metricsCollector = context.get(METRICS_COLLECTOR, MetricsCollector.class);
+
         return testJob;
     }
 }