Exemplo n.º 1
0
    def test_listsize(self):
        a_list = [1,2,3,4]
        ivc = CallbackCounter('test_counter', lambda: len(a_list))
                # in this case the callback can also be a_list.__len__

        self.assertEqual(ivc.get_current(), 4)
        a_list.extend([5,6,7])
        self.assertEqual(ivc.get_current(), 7)
        a_list.remove(1)
        self.assertEqual(ivc.get_current(), 6)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def __init__(self, server_sockets, rootcc):
        SelectHandlingLayer.__init__(self)

        # process server sockets
        self.server_sockets = server_sockets    # there may be many
        for server_socket in server_sockets:
            self.register_channel(server_socket)


        self.reqtasks = []


        # ---------- instrumentation stuff
        self.c_lshardmgrs_connected = DeltaCounter('lshardmgrs_connected', 
                                                   description='Amount of lshardmgrs connected')
        self.c_requests_dispatched = PulseCounter('requests_dispatched', 
                                                  resolution=60, units=u'requests per minute',
                                                  description='Requests to allocate a server sent')
        self.c_alloc_orders = PulseCounter('allocation_orders', resolution=60,
                                           units=u'allocation requests per minute',
                                           description=u'Allocation requests received')
        self.c_requests_success = PulseCounter('requests_successful', resolution=60,
                                               units=u'successful requests per minute',
                                               description=u'Requests successfully executed')
        self.c_requests_failed = PulseCounter('requests_failed', resolution=60,
                                              units=u'failed requests per minute',
                                              description=u'Failed requests')

        def calculate_shards_available():
            a = [x for x in self.channels if x not in self.server_sockets]
            a = [x for x in a if x.who == 'l']
            return sum([x.shards for x in a])

        self.c_shards_available = CallbackCounter('shards_available', calculate_shards_available,
                                                  units=u'shards', description=u'Available shards')
        rootcc.add(self.c_lshardmgrs_connected)
        rootcc.add(self.c_requests_dispatched)
        rootcc.add(self.c_alloc_orders)
        rootcc.add(self.c_requests_success)
        rootcc.add(self.c_requests_failed)
        rootcc.add(self.c_shards_available)
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
 def test_disabling(self):
     ivc = CallbackCounter('test_counter', lambda: 0)
     ivc.disable()
     self.assertRaises(NoData, ivc.get_current)
     ivc.enable()
     self.assertEqual(ivc.get_current(), 0)