Mercurial > stress-tester
changeset 1133:6f2c58a18100
NetflowScannerPayloadAnalyzer
author | Devel 2 |
---|---|
date | Mon, 08 Jun 2020 13:57:26 +0200 |
parents | 04da438495fb |
children | 599886ac3146 |
files | stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java stress-tester/src/main/java/com/passus/st/client/netflow/NetflowMetric.java stress-tester/src/main/java/com/passus/st/scanner/NetflowScannerPayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java |
diffstat | 4 files changed, 77 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java Mon Jun 08 13:49:38 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java Mon Jun 08 13:57:26 2020 +0200 @@ -28,7 +28,6 @@ attrs.put("receivedRecordsCount", receivedRecordsCount); attrs.put("replayCodes", replayCodes); } - public void addSentRecordType(DnsRecordType recordType) { Metric.incrementCountMap(recordType, sentRecordsCount);
--- a/stress-tester/src/main/java/com/passus/st/client/netflow/NetflowMetric.java Mon Jun 08 13:49:38 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/netflow/NetflowMetric.java Mon Jun 08 13:57:26 2020 +0200 @@ -3,16 +3,17 @@ import com.passus.commons.metric.Metric; import com.passus.net.netflow.*; import com.passus.st.client.GenericMetric; +import org.apache.commons.lang3.mutable.MutableInt; public class NetflowMetric extends GenericMetric { public static final String DEFAULT_NAME = "Netflow"; - private int v5flows; + private MutableInt v5flows = new MutableInt(); - private int v9flows; + private MutableInt v9flows = new MutableInt(); - private int v10flows; + private MutableInt v10flows = new MutableInt(); public NetflowMetric() { this(DEFAULT_NAME); @@ -30,15 +31,15 @@ switch (netflow.getVersion()) { case NetflowUtils.VERSION_5: Netflow5 netflow5 = (Netflow5) netflow; - v5flows += netflow5.getPdus().length; + v5flows.add(netflow5.getPdus().length); break; case NetflowUtils.VERSION_9: Netflow9 netflow9 = (Netflow9) netflow; - v9flows += netflow9.getFlowSets().size(); + v9flows.add(netflow9.getFlowSets().size()); break; case NetflowUtils.VERSION_10: Netflow10 netflow10 = (Netflow10) netflow; - v10flows += netflow10.getFlowSets().size(); + v10flows.add(netflow10.getFlowSets().size()); break; } } catch (Exception ignore) { @@ -49,15 +50,15 @@ @Override public void update(Metric metric) { NetflowMetric netflowMetric = (NetflowMetric) metric; - v5flows += netflowMetric.v5flows; - v9flows += netflowMetric.v9flows; - v10flows += netflowMetric.v10flows; + v5flows.add(netflowMetric.v5flows); + v9flows.add(netflowMetric.v9flows); + v10flows.add(netflowMetric.v10flows); } @Override public void reset() { - v5flows = 0; - v9flows = 0; - v10flows = 0; + v5flows.setValue(0); + v9flows.setValue(0); + v10flows.setValue(0); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/scanner/NetflowScannerPayloadAnalyzer.java Mon Jun 08 13:57:26 2020 +0200 @@ -0,0 +1,63 @@ +package com.passus.st.scanner; + +import com.passus.net.netflow.Netflow; +import com.passus.st.client.SessionPayloadEvent; +import com.passus.st.client.netflow.NetflowMetric; +import com.passus.st.metric.MetricSource; +import com.passus.st.metric.MetricsContainer; + +import static com.passus.st.Protocols.NETFLOW; + +public class NetflowScannerPayloadAnalyzer extends ScannerPayloadAnalyzer implements MetricSource { + + public static final String TYPE = "netflow"; + + private NetflowMetric metric; + + @Override + public String getType() { + return TYPE; + } + + @Override + public void activate() { + metric = new NetflowMetric(); + metric.activate(); + } + + @Override + public void deactivate() { + metric.deactivate(); + metric = null; + } + + @Override + public boolean isCollectMetrics() { + return false; + } + + @Override + public void setCollectMetrics(boolean collectMetrics) { + + } + + @Override + public void writeMetrics(MetricsContainer container) { + synchronized (metric) { + container.update(metric); + } + } + + @Override + protected void analyzePayload(SessionPayloadEvent event) { + if (event.getProtocolId() != NETFLOW) { + return; + } + + Netflow req = (Netflow) event.getRequest(); + if (req != null) { + metric.addNetflow(req); + } + } + +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 13:49:38 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 13:57:26 2020 +0200 @@ -33,6 +33,7 @@ public ScannerJob() { analyzers.add(new HttpScannerPayloadAnalyzer()); analyzers.add(new DnsScannerPayloadAnalyzer()); + analyzers.add(new NetflowScannerPayloadAnalyzer()); analyzers.add(new PgSqlScannerPayloadAnalyzer()); }