Mercurial > stress-tester
changeset 1132:04da438495fb
DnsScannerPayloadAnalyzer, PgSqlScannerPayloadAnalyzer
author | Devel 2 |
---|---|
date | Mon, 08 Jun 2020 13:49:38 +0200 |
parents | 0759f67a8f79 |
children | 6f2c58a18100 |
files | stress-tester/src/main/java/com/passus/st/client/GenericMetric.java stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java stress-tester/src/main/java/com/passus/st/scanner/DnsScannerPayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/PgSqlScannerPayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java |
diffstat | 5 files changed, 163 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/GenericMetric.java Mon Jun 08 13:10:13 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/GenericMetric.java Mon Jun 08 13:49:38 2020 +0200 @@ -17,7 +17,7 @@ protected final Map<String, Serializable> attrs = new LinkedHashMap<>(); - private boolean active; + protected boolean active; public GenericMetric(String name) { Assert.notNull(name, "name");
--- a/stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java Mon Jun 08 13:10:13 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/dns/DnsMetric.java Mon Jun 08 13:49:38 2020 +0200 @@ -12,11 +12,11 @@ public static final String DEFAULT_NAME = "DNS"; - private HashMap<DnsRecordType, MutableInt> sentRecordsCount; + private HashMap<DnsRecordType, MutableInt> sentRecordsCount = new HashMap<>(); - private HashMap<DnsRecordType, MutableInt> receivedRecordsCount; + private HashMap<DnsRecordType, MutableInt> receivedRecordsCount = new HashMap<>(); - private HashMap<DnsReplyCode, MutableInt> replayCodes; + private HashMap<DnsReplyCode, MutableInt> replayCodes = new HashMap<>(); public DnsMetric() { this(DEFAULT_NAME); @@ -28,23 +28,7 @@ attrs.put("receivedRecordsCount", receivedRecordsCount); attrs.put("replayCodes", replayCodes); } - - @Override - protected void doActivate() { - super.doActivate(); - sentRecordsCount = new HashMap<>(); - receivedRecordsCount = new HashMap<>(); - replayCodes = new HashMap<>(); - } - - @Override - protected void doDeactivate() { - super.doDeactivate(); - reset(); - sentRecordsCount = null; - receivedRecordsCount = null; - replayCodes = null; - } + public void addSentRecordType(DnsRecordType recordType) { Metric.incrementCountMap(recordType, sentRecordsCount);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/scanner/DnsScannerPayloadAnalyzer.java Mon Jun 08 13:49:38 2020 +0200 @@ -0,0 +1,77 @@ +package com.passus.st.scanner; + +import com.passus.net.dns.Dns; +import com.passus.net.dns.DnsQuery; +import com.passus.st.client.SessionPayloadEvent; +import com.passus.st.client.dns.DnsMetric; +import com.passus.st.metric.MetricSource; +import com.passus.st.metric.MetricsContainer; + +import static com.passus.st.Protocols.DNS; + +public class DnsScannerPayloadAnalyzer extends ScannerPayloadAnalyzer implements MetricSource { + + public static final String TYPE = "dns"; + + private DnsMetric metric; + + @Override + public String getType() { + return TYPE; + } + + @Override + public void activate() { + metric = new DnsMetric(); + 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() != DNS) { + return; + } + + Dns req = (Dns) event.getRequest(); + Dns resp = (Dns) event.getResponse(); + synchronized (metric) { + if (req != null && req.getQueriesCount() > 0) { + DnsQuery query = req.getQueries().get(0); + metric.addSentRecordType(query.getType()); + } + + if (resp != null) { + metric.addReplyCode(resp.getReplyCode()); + if (resp.getQueriesCount() > 0) { + resp.getAnswers().forEach((r) -> { + metric.addReceivedRecordType(r.getType()); + }); + } + } + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/scanner/PgSqlScannerPayloadAnalyzer.java Mon Jun 08 13:49:38 2020 +0200 @@ -0,0 +1,79 @@ +package com.passus.st.scanner; + +import com.passus.net.pgsql.PgSqlErrorResponseMessage; +import com.passus.net.pgsql.PgSqlMessage; +import com.passus.net.pgsql.PgSqlMessageType; +import com.passus.net.pgsql.PgSqlSimpleQueryMessage; +import com.passus.st.client.SessionPayloadEvent; +import com.passus.st.client.pgsql.PgSqlMetric; +import com.passus.st.metric.MetricSource; +import com.passus.st.metric.MetricsContainer; + +import static com.passus.st.Protocols.PGSQL; + +public class PgSqlScannerPayloadAnalyzer extends ScannerPayloadAnalyzer implements MetricSource { + + public static final String TYPE = "pgsql"; + + private PgSqlMetric metric; + + @Override + public String getType() { + return TYPE; + } + + @Override + public void activate() { + metric = new PgSqlMetric(); + 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() != PGSQL) { + return; + } + + PgSqlMessage req = (PgSqlMessage) event.getRequest(); + PgSqlMessage resp = (PgSqlMessage) event.getResponse(); + synchronized (metric) { + if(req != null) { + if (req.getType() == PgSqlMessageType.SIMPLE_QUERY) { + PgSqlSimpleQueryMessage simpleQueryMsg = (PgSqlSimpleQueryMessage) req; + metric.addQuery(simpleQueryMsg.getQuery()); + } + } + + if(resp != null) { + if (resp.getType() == PgSqlMessageType.ERROR_RESPONSE) { + PgSqlErrorResponseMessage errorMsg = (PgSqlErrorResponseMessage) resp; + metric.addErrorCode(errorMsg.getCode()); + } + } + } + } + +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 13:10:13 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 13:49:38 2020 +0200 @@ -32,6 +32,8 @@ public ScannerJob() { analyzers.add(new HttpScannerPayloadAnalyzer()); + analyzers.add(new DnsScannerPayloadAnalyzer()); + analyzers.add(new PgSqlScannerPayloadAnalyzer()); } public List<EventSource> getEventSources() {