Example #1
0
    def open(self):

        if self not in client_list:
            client_list.append(self)
        cursor = logs.find().sort('$natural', ASCENDING).limit(20)
        while(yield cursor.fetch_next):
            r = cursor.next_object()
            r[u'msgtype'] = 'log'
            self.write_message(json.dumps(
                r, default=date_encoder.default))

        cursor = stats.find()
        while (yield cursor.fetch_next):
            r = cursor.next_object()
            r[u'msgtype'] = 'stats'
            self.write_message(json.dumps(
                r, default=date_encoder.default))
Example #2
0
async def push_stats():
    # unlike the log function we will have to poll
    # the db for updates, aggregating results
    while True:
        yield gen.sleep(20)
        cursor = stats.find()

        async for r in cursor:
            # here check the stats and report any error
            try:
                check_stat(r)
            except Exception as e:
                log.warning(e.message)

            r[u'msgtype'] = 'stats'
            msg = json.dumps(r, default=date_encoder.default)

            for client in client_list:
                client.write_message(msg)
Example #3
0
    async def open(self):

        if self not in client_list:
            client_list.append(self)
        cursor = logs.find().sort('$natural', DESCENDING).limit(30)
        start_logs = []
        async for r in cursor:
            r[u'msgtype'] = 'log'
            start_logs.append(json.dumps(r, default=date_encoder.default))

        while len(start_logs):
            msg = start_logs.pop()
            self.write_message(msg)

        cursor = stats.find()

        async for r in cursor:
            r[u'msgtype'] = 'stats'
            self.write_message(json.dumps(r, default=date_encoder.default))
Example #4
0
    def open(self):

        if self not in client_list:
            client_list.append(self)
        cursor = logs.find().sort('$natural', DESCENDING).limit(30)
        start_logs = []
        while (yield cursor.fetch_next):
            r = cursor.next_object()
            r[u'msgtype'] = 'log'
            start_logs.append(json.dumps(r, default=date_encoder.default))

        while len(start_logs):
            msg = start_logs.pop()
            self.write_message(msg)

        cursor = stats.find()
        while (yield cursor.fetch_next):
            r = cursor.next_object()
            r[u'msgtype'] = 'stats'
            self.write_message(json.dumps(r, default=date_encoder.default))
Example #5
0
def push_stats():
    # unlike the log function we will have to poll
    # the db for updates, aggregating results
    while True:
        yield gen.sleep(20)
        cursor = stats.find()
        while (yield cursor.fetch_next):
            r = cursor.next_object()

            # here check the stats and report any error
            try:
                check_stat(r)
            except Exception as e:
                log.warning(e.message)

            r[u'msgtype'] = 'stats'
            msg = json.dumps(
                r, default=date_encoder.default)

            for client in client_list:
                    client.write_message(msg)