Mercurial > stress-tester
changeset 632:860c69eeaa6e
metrics
author | Devel 1 |
---|---|
date | Fri, 27 Oct 2017 16:28:16 +0200 |
parents | db2594ce845a |
children | 91af5c07101b |
files | stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorkerMetric.java stress-tester/src/main/java/com/passus/st/metric/ScheduledMetricsCollector.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java |
diffstat | 4 files changed, 39 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorkerMetric.java Fri Oct 27 16:25:19 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorkerMetric.java Fri Oct 27 16:28:16 2017 +0200 @@ -113,23 +113,8 @@ return respStatuses; } - /*public void addRequestUrl(URL url) { - MutableInt count = reqUrls.get(url); - if (count == null) { - count = new MutableInt(1); - reqUrls.put(url.toByteString(), count); - } else { - count.increment(); - } - }*/ public void addResponseStatusCode(Integer statusCode) { - MutableInt count = respStatuses.get(statusCode); - if (count == null) { - count = new MutableInt(1); - respStatuses.put(statusCode, count); - } else { - count.increment(); - } + Metric.incrementCountMap(statusCode, respStatuses); } public void addResponseTime(long time) { @@ -153,16 +138,6 @@ } @Override - public Class getAttributeClass(String name) { - Serializable value = getAttributeValue(name); - if (value == null) { - return null; - } - - return value.getClass(); - } - - @Override public boolean hasAttribute(String name) { return attrs.containsKey(name); } @@ -186,7 +161,6 @@ public void reset() { requestsNum.setValue(0); responsesNum.setValue(0); - //reqUrls.clear(); respStatuses.clear(); responseTimeHistogram.reset(); requestSendingTimeHistogram.reset(); @@ -195,33 +169,16 @@ responseSizeHistogram.reset(); } - private void update(Map<Integer, MutableInt> map1, Map<Integer, MutableInt> map2) { - for (Integer key : map1.keySet()) { - MutableInt value1 = map1.get(key); - MutableInt value2 = map2.get(key); - if (value2 != null) { - value1.add(value2); - } - } - - for (Integer key : map2.keySet()) { - if (!map1.containsKey(key)) { - map1.put(key, map2.get(key)); - } - } - } - @Override public void update(Metric metric) { if (!(metric instanceof HttpClientWorkerMetric)) { - throw new IllegalArgumentException(LongHistogramMetric.class + " required."); + throw new IllegalArgumentException(HttpClientWorkerMetric.class + " required."); } HttpClientWorkerMetric clientMetric = (HttpClientWorkerMetric) metric; requestsNum.add(clientMetric.requestsNum); responsesNum.add(clientMetric.responsesNum); - //update(reqUrls, clientMetric.reqUrls); - update(respStatuses, clientMetric.respStatuses); + Metric.updateCountMap(respStatuses, clientMetric.respStatuses); responseTimeHistogram.update(clientMetric.responseTimeHistogram); requestSendingTimeHistogram.update(clientMetric.requestSendingTimeHistogram); responseReceivingTimeHistogram.update(clientMetric.responseReceivingTimeHistogram);
--- a/stress-tester/src/main/java/com/passus/st/metric/ScheduledMetricsCollector.java Fri Oct 27 16:25:19 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/metric/ScheduledMetricsCollector.java Fri Oct 27 16:28:16 2017 +0200 @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -21,6 +22,8 @@ private static final Logger LOGGER = LogManager.getLogger(ScheduledMetricsCollector.class); + private static final AtomicInteger ID = new AtomicInteger(); + private ScheduledTimerService scheduledTimerService; private List<MetricSource> sources = new ArrayList<>(); @@ -89,7 +92,8 @@ } synchronized (this) { - scheduledTimerService = new DefaultScheduledTimerService(getClass().getSimpleName() + "-scheduler", + scheduledTimerService = new DefaultScheduledTimerService( + getClass().getSimpleName() + "-" + ID.getAndIncrement(), periodTime, () -> { if (started) {
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Oct 27 16:25:19 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSource.java Fri Oct 27 16:28:16 2017 +0200 @@ -290,6 +290,9 @@ } } } while (working && !res); + if (collectMetric) { + metric.incEnqueued(); + } } @Override @@ -373,6 +376,9 @@ } } } while (working && !res); + if (collectMetric) { + metric.incEnqueued(); + } } private void nextLoop() { @@ -462,6 +468,10 @@ Event event = queue.poll(100, TimeUnit.MILLISECONDS); if (event != null) { + if (collectMetric) { + metric.incDequeued(); + } + LOGGER.trace("queue poll {}", event); if (event.getType() == IpEvent.TYPE) { IpEvent ipEvent = (IpEvent) event;
--- a/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java Fri Oct 27 16:25:19 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/source/PcapSessionEventSourceMetric.java Fri Oct 27 16:28:16 2017 +0200 @@ -1,13 +1,13 @@ package com.passus.st.source; import com.passus.commons.Assert; -import com.passus.commons.metric.LongHistogramMetric; import com.passus.commons.metric.Metric; import java.io.Serializable; import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.lang3.mutable.MutableInt; /** @@ -23,6 +23,9 @@ private final MutableInt frames = new MutableInt(0); private final MutableInt tcpPackets = new MutableInt(0); private final MutableInt payloads = new MutableInt(0); + private final AtomicInteger events = new AtomicInteger(); + private final MutableInt eventsEnqueued = new MutableInt(); + private final MutableInt eventsDequeued = new MutableInt(); private final Map<String, Serializable> attrs = new LinkedHashMap<>(); @@ -38,6 +41,9 @@ attrs.put("frames", frames); attrs.put("tcpPackets", tcpPackets); attrs.put("payloads", payloads); + attrs.put("events", events); + attrs.put("eventsEnqueued", eventsEnqueued); + attrs.put("eventsDequeued", eventsDequeued); } @Override @@ -77,14 +83,14 @@ payloads.increment(); } - @Override - public Class getAttributeClass(String name) { - Serializable value = getAttributeValue(name); - if (value == null) { - return null; - } + public void incEnqueued() { + eventsEnqueued.increment(); + events.incrementAndGet(); + } - return value.getClass(); + public void incDequeued() { + eventsDequeued.increment(); + events.decrementAndGet(); } @Override @@ -112,17 +118,23 @@ frames.setValue(0); tcpPackets.setValue(0); payloads.setValue(0); + events.set(0); + eventsEnqueued.setValue(0); + eventsDequeued.setValue(0); } @Override public void update(Metric metric) { if (!(metric instanceof PcapSessionEventSourceMetric)) { - throw new IllegalArgumentException(LongHistogramMetric.class + " required."); + throw new IllegalArgumentException(PcapSessionEventSourceMetric.class + " required."); } PcapSessionEventSourceMetric pcapMetric = (PcapSessionEventSourceMetric) metric; frames.add(pcapMetric.frames); tcpPackets.add(pcapMetric.tcpPackets); payloads.add(pcapMetric.payloads); + events.addAndGet(pcapMetric.events.get()); + eventsEnqueued.add(pcapMetric.eventsEnqueued); + eventsDequeued.add(pcapMetric.eventsDequeued); } }