def __init__(self, server_socket, to_eventprocessor, from_eventprocessor, pdbhelper, rootcc): """@type server_socket: ServerSocket @type to_eventprocessor: L{Queue.Queue} @type from_eventprocessor: L{Queue.Queue} @param rootcc: root counter collection @type rootcc: L{satella.instrumentation.CounterCollection}""" SelectHandlingLayer.__init__(self) # Set up the server socket and attach it to SL self.server_socket = server_socket self.register_channel(server_socket) # dictionary (user pids => respective PlayerSocket) self.authenticated_channels = {} # Queue section self.to_ep = to_eventprocessor self.from_ep = from_eventprocessor # PDB section self.pdbhelper = pdbhelper # Instrumentation section cc = CounterCollection('selectlayer') self.connections_counter = DeltaCounter('connections', units='connections', description='SSL connections to server') self.outbound_events = PulseCounter('events_to_ep', resolution=60, units='events per minute', description='events sent to EventProcessor') cc.add(self.connections_counter) cc.add(self.outbound_events) rootcc.add(cc)
def __init__(self, host, username, password, dbname, rootcc, dbtype='mysql'): """@type rootcc: L{satella.instrumentation.CounterCollection}""" assert dbtype == 'mysql', 'I cannot support other databases!' dd = DatabaseDefinition( MySQLdb.connect, (MySQLdb.OperationalError, MySQLdb.InterfaceError), (host, username, password, dbname)) self.cp = ConnectionPool(dd) # Set up instrumentation insmgr = CounterCollection('database') self.cursors_counter = PulseCounter('cursors', resolution=60, units=u'cursors per minute', description='SQL cursors created') insmgr.add(self.cursors_counter) rootcc.add(insmgr)
def __init__(self, pdb, rootcc): """ @param pdb: PlayerDatabase @param rootcc: Root CounterCollection """ BaseThread.__init__(self) self.pdb = pdb cc = CounterCollection( 'alpha_counter', description=u'Module that creates games from hero picking rooms') self.matches_dt = PulseCounter('matches_made', resolution=60, units=u'matches per minute', description=u'successful allocations') self.matches_dt_so = PulseCounter( 'matches_failed_so', resolution=60, units=u'matches per minute', description=u'fails to allocate due to shard overload') self.matches_dt_fl = PulseCounter( 'matches_failed_fl', resolution=60, units=u'matches per minute', description=u'fails to allocate due to other reasons') cc.add(self.matches_dt) cc.add(self.matches_dt_so) cc.add(self.matches_dt_fl) rootcc.add(cc)
def test_add_different_objects_same_names(self): insmgr = CounterCollection('test_namespace', description=u'test') ctr = NumericValueCounter('a_counter') atr = NumericValueCounter('a_counter') insmgr.add(ctr) self.assertRaises(ObjectExists, insmgr.add, atr)
def test_add_remove_collection(self): """Tests adding and removing a collection from a collection""" insmgr = CounterCollection('test_namespace') ctr = CounterCollection('nested_child') insmgr.add(ctr) self.assertRaises(ObjectExists, insmgr.add, ctr) insmgr.remove(ctr) self.assertRaises(ObjectNotExists, insmgr.remove, ctr)
def __init__(self, pdb, rootcc): """ @param pdb: PlayerDatabase @param rootcc: Root CounterCollection """ BaseThread.__init__(self) self.pdb = pdb cc = CounterCollection('match_maker', description=u'Module that organizes matches from enqueued players') self.total_matches_made = DeltaCounter('matches_made', units=u'matches', description=u'total matches made') self.matches_dt = PulseCounter('matches_made_p', resolution=60, units=u'matches per minute', description=u'organized matches per minute') cc.add(self.total_matches_made) cc.add(self.matches_dt) rootcc.add(cc)
def __init__(self, host, username, password, dbname, rootcc, dbtype='mysql'): """@type rootcc: L{satella.instrumentation.CounterCollection}""" assert dbtype == 'mysql', 'I cannot support other databases!' dd = DatabaseDefinition(MySQLdb.connect, (MySQLdb.OperationalError, MySQLdb.InterfaceError), (host, username, password, dbname)) self.cp = ConnectionPool(dd) # Set up instrumentation insmgr = CounterCollection('database') self.cursors_counter = PulseCounter('cursors', resolution=60, units=u'cursors per minute', description='SQL cursors created') insmgr.add(self.cursors_counter) rootcc.add(insmgr)
def test_mass_disable_enable(self): """Tests enabling and disabling children from a namespace""" insmgr = CounterCollection('test_namespace') ctr = NumericValueCounter('a_counter', units=u'dogs') atr = NumericValueCounter('b_counter', description=u'hello') self.assertEquals(ctr.units, u'dogs') self.assertEquals(atr.description, u'hello') insmgr.add(ctr) insmgr.add(atr) insmgr.disable() self.assertEquals(ctr.enabled, False) self.assertEquals(atr.enabled, False) insmgr.enable() self.assertEquals(ctr.enabled, True) self.assertEquals(atr.enabled, True)
def __init__(self, pdb, rootcc): """ @param pdb: PlayerDatabase @param rootcc: Root CounterCollection """ BaseThread.__init__(self) self.pdb = pdb cc = CounterCollection('alpha_counter', description=u'Module that creates games from hero picking rooms') self.matches_dt = PulseCounter('matches_made', resolution=60, units=u'matches per minute', description=u'successful allocations') self.matches_dt_so = PulseCounter('matches_failed_so', resolution=60, units=u'matches per minute', description=u'fails to allocate due to shard overload') self.matches_dt_fl = PulseCounter('matches_failed_fl', resolution=60, units=u'matches per minute', description=u'fails to allocate due to other reasons') cc.add(self.matches_dt) cc.add(self.matches_dt_so) cc.add(self.matches_dt_fl) rootcc.add(cc)
def test_add_remove_counter(self): """Tests adding and removing a counter from a collection""" insmgr = CounterCollection('test_namespace', description=u'test') ctr = NumericValueCounter('a_counter') atr = NumericValueCounter('b_counter') insmgr.add(ctr) insmgr.add(atr) self.assertRaises(ObjectExists, insmgr.add, ctr) self.assertEquals(insmgr.description, u'test') insmgr.remove(ctr) self.assertRaises(ObjectNotExists, insmgr.remove, ctr) c_atr = insmgr.get('b_counter') self.assertEquals(c_atr, atr) self.assertRaises(ObjectNotExists, insmgr.get, 'c_counter') self.assertEquals(insmgr.get()[0], atr) self.assertEquals(len(insmgr.get()), 1)
def __init__(self, pdbhelper, rootcc, qmangr, to_eventprocessor, cshardmgr_interface): """@type pdbhelper: L{lobbyapp.playerdb.api.PDBHelperInterface} implementation. @type qmangr: L{lobbyapp.queuemangr.QueueManager} @param to_eventprocessor: Queue that can be used to send orders to EventProcessor @type to_eventprocessor: L{Queue.Queue} @param cshardmgr_interface: interface to CShardMgr @type cshardmgr_interface: tuple(str, int)""" Monitor.__init__(self) self.pirs = {} #: pid => PlayerInformationRecord self.cshardmgr_interface = cshardmgr_interface self.pdbhelper = pdbhelper self.qmangr = qmangr self.alphas = [] # all existing AlphaMatches self.betagammas = [] # all existing BetaGammas self.to_eventprocessor = to_eventprocessor cc = CounterCollection('player_database') self.transactions_counter = PulseCounter('transactions', resolution=60, units=u'transactions per minute', description=u'player database transactions performed') alphas_waiting = CallbackCounter('alphas_waiting', self.alphas.__len__, description=u'matches being prepared') betagammas = CallbackCounter('betagammas', self.betagammas.__len__, description=u'matches being played') cc.add(self.transactions_counter) cc.add(alphas_waiting) cc.add(betagammas) rootcc.add(cc)
def __init__(self, qname, ppm, rootcc): """ Constructs the queue @param qname: queue name identifier @type qname: str @param ppm: Players required per match of this type @type ppm: int @param rootcc: Collection counter for queues """ self.qname = qname #: name of the queue self.players_per_match = ppm self.players = [] #: pids of players in queue # ---------------- instrumentation section cc = CounterCollection(self.qname) players_counter = CallbackCounter('players', lambda: len(self.players), description=u'players waiting in this queue') cc.add(players_counter) rootcc.add(cc)
def __init__(self, pdbhelper, rootcc, qmangr, to_eventprocessor, cshardmgr_interface): """@type pdbhelper: L{lobbyapp.playerdb.api.PDBHelperInterface} implementation. @type qmangr: L{lobbyapp.queuemangr.QueueManager} @param to_eventprocessor: Queue that can be used to send orders to EventProcessor @type to_eventprocessor: L{Queue.Queue} @param cshardmgr_interface: interface to CShardMgr @type cshardmgr_interface: tuple(str, int)""" Monitor.__init__(self) self.pirs = {} #: pid => PlayerInformationRecord self.cshardmgr_interface = cshardmgr_interface self.pdbhelper = pdbhelper self.qmangr = qmangr self.alphas = [] # all existing AlphaMatches self.betagammas = [] # all existing BetaGammas self.to_eventprocessor = to_eventprocessor cc = CounterCollection('player_database') self.transactions_counter = PulseCounter( 'transactions', resolution=60, units=u'transactions per minute', description=u'player database transactions performed') alphas_waiting = CallbackCounter('alphas_waiting', self.alphas.__len__, description=u'matches being prepared') betagammas = CallbackCounter('betagammas', self.betagammas.__len__, description=u'matches being played') cc.add(self.transactions_counter) cc.add(alphas_waiting) cc.add(betagammas) rootcc.add(cc)