changeset 1077:2211bb11ab38

Metrics bugfixes
author Devel 2
date Wed, 29 Apr 2020 10:23:17 +0200
parents 992057a5cc68
children 844bc5ceadef
files stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java stress-tester/src/main/java/com/passus/st/emitter/socket/DatagramConnection.java stress-tester/src/main/java/com/passus/st/emitter/socket/SocketConnection.java stress-tester/src/main/java/com/passus/st/emitter/socket/SocketEmitter.java
diffstat 4 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java	Wed Apr 29 10:03:46 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/emitter/EmitterMetric.java	Wed Apr 29 10:23:17 2020 +0200
@@ -98,6 +98,10 @@
         return connectionsErrors.intValue();
     }
 
+    public int establishedConnections() {
+        return establishedConnections.intValue();
+    }
+
     public void incClosedConnections() {
         closedConnections.increment();
     }
@@ -120,10 +124,6 @@
         }
     }
 
-    public int establishedConnections() {
-        return establishedConnections.intValue();
-    }
-
     public void addBindSocket(SocketAddress address) {
         //bindedSockets.add(address);
     }
--- a/stress-tester/src/main/java/com/passus/st/emitter/socket/DatagramConnection.java	Wed Apr 29 10:03:46 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/emitter/socket/DatagramConnection.java	Wed Apr 29 10:23:17 2020 +0200
@@ -93,6 +93,11 @@
         } catch (Exception ex) {
             doCatchException(channelContext, ex);
         }
+
+        if (collectMetrics) {
+            metric.addRemoteSocketConnection(channelContext.getRemoteAddress());
+            metric.addBindSocket(channelContext.getLocalAddress());
+        }
     }
 
     public void close() {
@@ -115,7 +120,7 @@
 
     @Override
     protected void doMakeSSL() {
-        
+
     }
 
     @Override
--- a/stress-tester/src/main/java/com/passus/st/emitter/socket/SocketConnection.java	Wed Apr 29 10:03:46 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/emitter/socket/SocketConnection.java	Wed Apr 29 10:23:17 2020 +0200
@@ -111,6 +111,11 @@
             doCatchException(channelContext, ex);
         }
 
+        if (collectMetrics) {
+            metric.addRemoteSocketConnection(channelContext.getRemoteAddress());
+            metric.addBindSocket(channelContext.getLocalAddress());
+        }
+
         connectionPending = false;
     }
 
--- a/stress-tester/src/main/java/com/passus/st/emitter/socket/SocketEmitter.java	Wed Apr 29 10:03:46 2020 +0200
+++ b/stress-tester/src/main/java/com/passus/st/emitter/socket/SocketEmitter.java	Wed Apr 29 10:23:17 2020 +0200
@@ -6,6 +6,7 @@
 import com.passus.config.annotations.NodeDefinitionCreate;
 import com.passus.config.schema.MapNodeDefinition;
 import com.passus.net.session.Session;
+import com.passus.st.client.PerNameMetricsContainer;
 import com.passus.st.emitter.*;
 import com.passus.st.metric.MetricsContainer;
 import com.passus.st.plugin.PluginConstants;
@@ -38,6 +39,8 @@
 
     private long connectionTimeout = DEFAULT_CONNECTION_TIMEOUT;
 
+    private final PerNameMetricsContainer deferredMetrics = new PerNameMetricsContainer();
+
     private boolean started;
 
     @Override
@@ -68,6 +71,15 @@
                     container.update(connection.metric);
                 }
             });
+
+            if (!deferredMetrics.isEmpty()) {
+                deferredMetrics.getMetrics().forEach(m -> {
+                    container.update(m);
+                    m.reset();
+                });
+
+                deferredMetrics.clear();
+            }
         }
     }
 
@@ -144,6 +156,11 @@
 
                 @Override
                 public void onConnectionClosed(ChannelContext channelContext) {
+                    if (collectMetrics) {
+                        Connection connection = connections.get(channelContext.getSessionInfo());
+                        deferredMetrics.update(connection.metric);
+                    }
+
                     connections.remove(channelContext.getSessionInfo());
                 }