]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p_Khashmir/stats.py
Added the number of times each action was started to the DHT stats.
[quix0rs-apt-p2p.git] / apt_p2p_Khashmir / stats.py
index 7a40adb28894f98845ad27a5c586a964e976dcc1..e2752dd379223707730c3517f3224ec2ac77a018 100644 (file)
@@ -92,6 +92,18 @@ class StatsLogger:
                        'tip': 'The number of bytes sent by the DHT',
                        'value': None,
                        },
+                      {'name': 'downSpeed',
+                       'group': 'Transport',
+                       'desc': 'Downloaded bytes/second',
+                       'tip': 'The number of bytes received by the DHT per second',
+                       'value': None,
+                       },
+                      {'name': 'upSpeed',
+                       'group': 'Transport',
+                       'desc': 'Uploaded bytes/second',
+                       'tip': 'The number of bytes sent by the DHT per second',
+                       'value': None,
+                       },
                       {'name': 'actions',
                        'group': 'Actions',
                        'desc': 'Actions',
@@ -168,25 +180,39 @@ class StatsLogger:
         self.tableStats()
         self.dbStats()
         stats = self._StatsTemplate[:]
+        elapsed = datetime.now() - self.startTime
         for stat in stats:
             val = getattr(self, stat['name'], None)
             if stat['name'] == 'uptime':
-                stat['value'] = dattime.now() - self.startTime
+                stat['value'] = elapsed
             elif stat['name'] == 'actions':
-                stat['value'] = deepcopy(actions)
+                stat['value'] = deepcopy(self.actions)
+            elif stat['name'] == 'downSpeed':
+                stat['value'] = self.downBytes / (elapsed.days*86400.0 + elapsed.seconds + elapsed.microseconds/1000000.0)
+            elif stat['name'] == 'upSpeed':
+                stat['value'] = self.upBytes / (elapsed.days*86400.0 + elapsed.seconds + elapsed.microseconds/1000000.0)
             elif val is not None:
                 stat['value'] = val
                 
         return stats
     
+    #{ Called by the action
+    def startedAction(self, action):
+        """Record that an action was started.
+        
+        @param action: the name of the action
+        """
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[0] += 1
+    
     #{ Called by the transport
     def sentAction(self, action):
         """Record that an action was attempted.
         
         @param action: the name of the action
         """
-        act = self.actions.setdefault(action, [0, 0, 0, 0, 0])
-        act[0] += 1
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[1] += 1
         
     def responseAction(self, response, action):
         """Record that a response to an action was received.
@@ -195,8 +221,8 @@ class StatsLogger:
         @param action: the name of the action
         @return: the response (for use in deferreds)
         """
-        act = self.actions.setdefault(action, [0, 0, 0, 0, 0])
-        act[1] += 1
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[2] += 1
         return response
         
     def failedAction(self, response, action):
@@ -206,8 +232,8 @@ class StatsLogger:
         @param action: the name of the action
         @return: the response (for use in deferreds)
         """
-        act = self.actions.setdefault(action, [0, 0, 0, 0, 0])
-        act[2] += 1
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[3] += 1
         return response
         
     def receivedAction(self, action):
@@ -216,16 +242,16 @@ class StatsLogger:
         @param action: the name of the action
         """
         self.reachable = True
-        act = self.actions.setdefault(action, [0, 0, 0, 0, 0])
-        act[3] += 1
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[4] += 1
     
     def errorAction(self, action):
         """Record that a received action resulted in an error.
         
         @param action: the name of the action
         """
-        act = self.actions.setdefault(action, [0, 0, 0, 0, 0])
-        act[4] += 1
+        act = self.actions.setdefault(action, [0, 0, 0, 0, 0, 0])
+        act[5] += 1
     
     def sentBytes(self, bytes):
         """Record that a single packet of some bytes was sent.