11# -*- coding: utf-8 -*-
22
3+ import time
34from json import dumps
45from os .path import dirname , abspath
56
2728 format = '%(asctime)s\t %(name)s\t %(message)s' ,
2829 datefmt = '%Y-%m-%d %H:%M:%S' )
2930bcast_log = logging .getLogger ('bcast_log' )
31+ mon_log = logging .getLogger ('mon_log' )
3032irc_log = logging .getLogger ('irc_log' )
3133api_log = logging .getLogger ('api_log' )
32-
34+ LAST_FORCED_LOG = 0
35+ FORCE_LOG_THRESH = 120
3336
3437DEFAULT_LANG = 'en'
3538DEFAULT_PROJECT = 'wikipedia'
@@ -84,7 +87,7 @@ class Monitor(irc.IRCClient):
8487 # which conflicts with a lot of other clients out there and
8588 # sometimes prevents joining rooms.
8689
87- nickname = 'wikimon '
90+ nickname = 'wikimon2 '
8891 GEO_IP_KEY = 'geo_ip'
8992
9093 def __init__ (self , geoip_db_monitor , bsf , ns_map , factory ):
@@ -162,6 +165,10 @@ def __init__(self, url, geoip_db, geoip_update_interval,
162165 WebSocketServerFactory .__init__ (self , url , * a , ** kw )
163166 self .clients = set ()
164167 self .tickcount = 0
168+ self .msgcount = 0
169+ self .lang = lang
170+ self .project = project
171+ self .start_time = time .time ()
165172
166173 start_monitor (self , geoip_db , geoip_update_interval ,
167174 lang , project ) # blargh
@@ -184,10 +191,17 @@ def unregister(self, client):
184191 pass
185192
186193 def broadcast (self , msg ):
194+ global LAST_FORCED_LOG
195+ self .msgcount += 1
187196 bcast_log .info ("broadcasting message %r" , msg )
188197 for c in self .clients :
189198 c .sendMessage (msg )
190199 bcast_log .debug ("message sent to %s" , c .peerstr )
200+
201+ if time .time () - LAST_FORCED_LOG > FORCE_LOG_THRESH :
202+ LAST_FORCED_LOG = time .time ()
203+ data = {'msgs' : self .msgcount , 'clients' : len (self .clients ), 'lang' : self .lang , 'project' : self .project , 'uptime_hours' : (time .time () - self .start_time )/ 60 / 60 }
204+ mon_log .critical (dumps (data ))
191205
192206
193207class BroadcastPreparedServerFactory (BroadcastServerFactory ):
0 commit comments