Mercurial > stress-tester
changeset 1134:599886ac3146
MySqlScannerPayloadAnalyzer
author | Devel 2 |
---|---|
date | Mon, 08 Jun 2020 14:16:03 +0200 |
parents | 6f2c58a18100 |
children | 32ad0e5ff0fc |
files | stress-tester/src/main/java/com/passus/st/scanner/MySqlScannerPayloadAnalyzer.java stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java |
diffstat | 2 files changed, 80 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester/src/main/java/com/passus/st/scanner/MySqlScannerPayloadAnalyzer.java Mon Jun 08 14:16:03 2020 +0200 @@ -0,0 +1,79 @@ +package com.passus.st.scanner; + +import com.passus.net.mysql.*; +import com.passus.st.client.SessionPayloadEvent; +import com.passus.st.client.mysql.MySqlMetric; +import com.passus.st.metric.MetricSource; +import com.passus.st.metric.MetricsContainer; + +import static com.passus.st.Protocols.MYSQL; + +public class MySqlScannerPayloadAnalyzer extends ScannerPayloadAnalyzer implements MetricSource { + + public static final String TYPE = "mysql"; + + private MySqlMetric metric; + + @Override + public String getType() { + return TYPE; + } + + @Override + public void activate() { + metric = new MySqlMetric(); + 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() != MYSQL) { + return; + } + + MySqlRequest req = (MySqlRequest) event.getRequest(); + MySqlResponse resp = (MySqlResponse) event.getResponse(); + synchronized (metric) { + if (req != null) { + if (req.getPacketType() == MySqlPacketTypes.QUERY_COMMAND) { + MySqlQueryCommand queryCmd = (MySqlQueryCommand) req; + synchronized (metric) { + metric.addQuery(queryCmd.getQuery()); + } + } + } + + + if (resp != null) { + if (resp.getPacketType() == MySqlPacketTypes.ERROR_RESPONSE) { + MySqlErrorResponse errorRsp = (MySqlErrorResponse) resp; + metric.addErrorCode(errorRsp.getErrorCode()); + } + } + } + } + +} \ No newline at end of file
--- a/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 13:57:26 2020 +0200 +++ b/stress-tester/src/main/java/com/passus/st/scanner/ScannerJob.java Mon Jun 08 14:16:03 2020 +0200 @@ -35,6 +35,7 @@ analyzers.add(new DnsScannerPayloadAnalyzer()); analyzers.add(new NetflowScannerPayloadAnalyzer()); analyzers.add(new PgSqlScannerPayloadAnalyzer()); + analyzers.add(new MySqlScannerPayloadAnalyzer()); } public List<EventSource> getEventSources() {