Mercurial > stress-tester
changeset 460:f6b94e93bc1d
ST Main - summary metrix exposed
author | Devel 1 |
---|---|
date | Tue, 01 Aug 2017 13:25:54 +0200 |
parents | e7cf31ba49a2 |
children | ae444c6a1e70 |
files | stress-tester/src/main/java/com/passus/st/Main.java |
diffstat | 1 files changed, 34 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/Main.java Tue Aug 01 12:47:24 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/Main.java Tue Aug 01 13:25:54 2017 +0200 @@ -51,6 +51,9 @@ */ public class Main { + private final SummrizeMetricsCollectionHandler summMetricsHandler = new SummrizeMetricsCollectionHandler(); + private long startTime; + static void printHelp(Options options) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("[options] <pcap>", "description", options, ""); @@ -63,27 +66,38 @@ static void printMetrics(List<Metric> metrics, long startTime) { long endTime = System.currentTimeMillis(); - System.out.println(""); - try { - System.out.println("Elapsed time: " + PeriodFormatter.INSTANCE.reverseTransform(endTime - startTime) + "."); - } catch (ConversionException conversionException) { - } - System.out.println("Metrics:"); + synchronized (System.out) { + System.out.println(""); + try { + System.out.println("Elapsed time: " + PeriodFormatter.INSTANCE.reverseTransform(endTime - startTime) + "."); + } catch (ConversionException conversionException) { + } + System.out.println("Metrics:"); - String line = "%24s: %s\n"; - for (Metric metric : metrics) { - System.out.println(metric.getName() + ":"); - Map<String, Serializable> valuesMap = metric.getAttributesValue(); - for (Map.Entry<String, Serializable> entry : valuesMap.entrySet()) { - String key = entry.getKey(); - Serializable value = entry.getValue(); + String line = "%24s: %s\n"; + for (Metric metric : metrics) { + System.out.println(metric.getName() + ":"); + Map<String, Serializable> valuesMap = metric.getAttributesValue(); + for (Map.Entry<String, Serializable> entry : valuesMap.entrySet()) { + String key = entry.getKey(); + Serializable value = entry.getValue(); - System.out.printf(line, key, value); + System.out.printf(line, key, value); + } } } } - private void start(String[] args) { + void printMetrics() { + List<Metric> metrics = summMetricsHandler.getMetrics(); + printMetrics(metrics, startTime); + } + + List<Metric> getMetrics() { + return summMetricsHandler.getMetrics(); + } + + void start(String... args) { AppUtils.registerAll(); final Options options = new Options(); @@ -305,7 +319,6 @@ throw new Exception("Loop should be greater than zero."); } - SummrizeMetricsCollectionHandler summMetricsHandler = new SummrizeMetricsCollectionHandler(); if (cl.hasOption("wm")) { File metricsFile = new File(cl.getOptionValue("wm")); if (!metricsFile.exists() && !metricsFile.createNewFile()) { @@ -325,7 +338,7 @@ collector.register(client); collector.start(); - long startTime = System.currentTimeMillis(); + startTime = System.currentTimeMillis(); if (cl.hasOption("ca")) { MemoryEventsCache cache = new MemoryEventsCache(client); eventSrc.setHandler(cache); @@ -340,10 +353,7 @@ } ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); - Runnable printer = () -> { - printMetrics(summMetricsHandler.getMetrics(), startTime); - }; - executor.scheduleAtFixedRate(printer, 5, 5, TimeUnit.SECONDS); + executor.scheduleAtFixedRate(this::printMetrics, 5, 5, TimeUnit.SECONDS); client.join(); @@ -365,12 +375,14 @@ collector.flush(true); - printMetrics(summMetricsHandler.getMetrics(), startTime); + printMetrics(); } catch (ParseException e) { System.out.println(e.getMessage()); printHelp(options); } catch (Exception e) { e.printStackTrace(System.err); + } finally { + AppUtils.unregisterAll(); } }