Commit 9db0ac09 authored by Antoine Millet's avatar Antoine Millet
Browse files

Implementation of database statistics.

parent 51436662
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -430,6 +430,13 @@ class CliHandler(OnlineCCHandler):
                
        return errs.get_dict()

    @listed
    def db_stats(self, conn):
        '''
        Return statistics about current database status.
        '''
        return self._server.objects.stats()

    def proxy_client(self, conn, login, command, *args, **kwargs):
        client = self._server.get_connection(login)
        return client.connection.call(command, *args, **kwargs)
+26 −0
Original line number Diff line number Diff line
@@ -50,6 +50,9 @@ class ObjectsDB(object):
        # The list of received message while update:
        self._msgs = []

        # Total amount of query updates:
        self._nb_queries = 0

    def update(self, ids=None, tags=None, tags_novalue=None):
        '''
        Update the database according to the TTL values.
@@ -61,6 +64,7 @@ class ObjectsDB(object):
        '''

        with self._lock:
            self._nb_queries += 1
            self._update(ids, tags, tags_novalue)
            self._process_responses()

@@ -306,3 +310,25 @@ class ObjectsDB(object):
        self.update(ids, tags=tags, tags_novalue=to_check)
        for obj_id in ids:
            yield self._objects[obj_id]

    def stats(self):
        '''
        Get stats about the current state of the object database.
        '''

        stats = {}

        stats['count'] = len(self._objects)
        cached = dead = 0
        now = datetime.now()
        for date in self._ttls.values():
            if date > now:
                dead += 1
            else:
                cached += 1
        stats['cached'] = cached
        stats['dead'] = dead
        stats['total'] = cached + dead
        stats['queries'] = self._nb_queries

        return stats