diff --git a/network-broker/network-broker b/network-broker/network-broker index 18c1ba1..8c9f146 100755 --- a/network-broker/network-broker +++ b/network-broker/network-broker @@ -641,14 +641,23 @@ class Broker(SocketServer.UDPServer): def enqueue_message(self, sending_peer, message): # Store last 10 messages self.messages = self.messages[-9:] + [message] + all_msgs = [] for addr, peer in self.peers.iteritems(): + all_msgs.append(message.message) if peer != sending_peer: peer.send_packet(message.marshal()) + stats.set_messages(all_msgs) + + try: + stats.generate_html(self.stat_html) + except Exception, e: + pass def dequeue_old_messages(self): now = time.mktime(time.localtime()) to_delete = 0 + all_msgs = [] for msg in self.messages: diff = now - msg.get_timestamp() @@ -658,6 +667,14 @@ class Broker(SocketServer.UDPServer): log_info("Deleting old message") self.messages = self.messages[ to_delete : ] + for msg in self.messages: + all_msgs.append(msg.message) + stats.set_messages(all_msgs) + try: + stats.generate_html(self.stat_html) + except Exception, e: + pass + def ping_all_peers(self): """Ping all peers (to see that they are alive)""" for k,v in self.peers.iteritems(): diff --git a/network-broker/stats.py b/network-broker/stats.py index 0b537af..c23c667 100644 --- a/network-broker/stats.py +++ b/network-broker/stats.py @@ -6,6 +6,7 @@ class Container: self.total_connections = 0 self.country_count = {} self.last_10 = [] + self.messages = [] self.nr_active = 0 self.nr_waiting = 0 @@ -17,11 +18,12 @@ class Container: def copy_from_other(self, other): try: + self.nr_active = 0 # Always reset + self.nr_waiting = 0 self.total_connections = other.total_connections self.country_count = other.country_count self.last_10 = other.last_10 - self.nr_active = 0 # Always reset - self.nr_waiting = 0 + self.messages = other.messages except: pass @@ -33,6 +35,9 @@ class Container: self.country_count[country] = cur + 1 + def set_messages(self, messages): + self.messages = messages + def add_connection(self, who, country): time_now = time.strftime("%Y-%m-%d %H:%M", time.gmtime()) s = "%s - %s (%s)" % (time_now, who, country) @@ -71,6 +76,11 @@ class HtmlGenerator: outf.write("