merge debug and info views stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 26 Feb 2010 09:54:03 +0100
branchstable
changeset 4714 fccda6dd91bf
parent 4713 785299dfc2c0
child 4715 d3f87ee74fe4
merge debug and info views plus enhancements: * nicer presentation * proper translations * kill dead (modpython!) code * fix repository stats (active thread count / add looping tasks information)
i18n/en.po
i18n/es.po
i18n/fr.po
server/repository.py
server/utils.py
web/views/debug.py
web/views/management.py
--- a/i18n/en.po	Fri Feb 26 08:46:27 2010 +0100
+++ b/i18n/en.po	Fri Feb 26 09:54:03 2010 +0100
@@ -191,9 +191,6 @@
 msgid "Any"
 msgstr ""
 
-msgid "Application"
-msgstr ""
-
 msgid "Attributes"
 msgstr ""
 
@@ -348,9 +345,6 @@
 msgid "Entities"
 msgstr ""
 
-msgid "Environment"
-msgstr ""
-
 msgid "ExternalUri"
 msgstr "External Uri"
 
@@ -375,6 +369,9 @@
 msgid "Help"
 msgstr ""
 
+msgid "Instance"
+msgstr ""
+
 msgid "Int"
 msgstr "Integer"
 
@@ -504,9 +501,6 @@
 msgid "Repository"
 msgstr ""
 
-msgid "Request"
-msgstr ""
-
 #, python-format
 msgid "Schema %s"
 msgstr ""
@@ -517,9 +511,6 @@
 msgid "Search for"
 msgstr ""
 
-msgid "Server"
-msgstr ""
-
 msgid "SizeConstraint"
 msgstr "size constraint"
 
@@ -660,6 +651,9 @@
 msgid "Used by:"
 msgstr ""
 
+msgid "Web server"
+msgstr ""
+
 msgid "What's new?"
 msgstr ""
 
@@ -1482,6 +1476,12 @@
 msgid "condition_object"
 msgstr "condition of"
 
+msgid "config mode"
+msgstr ""
+
+msgid "config type"
+msgstr ""
+
 msgid "confirm password"
 msgstr ""
 
@@ -2376,9 +2376,6 @@
 msgid "hide filter form"
 msgstr ""
 
-msgid "home"
-msgstr ""
-
 msgid ""
 "how to format date and time in the ui (\"man strftime\" for format "
 "description)"
@@ -2522,6 +2519,9 @@
 msgid "inlined"
 msgstr "inlined"
 
+msgid "instance home"
+msgstr ""
+
 msgid "instance schema"
 msgstr ""
 
@@ -2589,6 +2589,9 @@
 msgid "last connection date"
 msgstr ""
 
+msgid "last usage"
+msgstr ""
+
 msgid "last_login_time"
 msgstr "last login time"
 
@@ -2840,6 +2843,9 @@
 msgid "no related project"
 msgstr ""
 
+msgid "no repository sessions found"
+msgstr ""
+
 msgid "no selected entities"
 msgstr ""
 
@@ -2850,6 +2856,9 @@
 msgid "no version information"
 msgstr ""
 
+msgid "no web sessions found"
+msgstr ""
+
 msgid "normal"
 msgstr ""
 
@@ -2886,6 +2895,12 @@
 msgid "open all"
 msgstr ""
 
+msgid "opened sessions"
+msgstr ""
+
+msgid "opened web sessions"
+msgstr ""
+
 msgid "order"
 msgstr ""
 
@@ -3134,6 +3149,9 @@
 msgid "required field"
 msgstr ""
 
+msgid "resources usage"
+msgstr ""
+
 msgid ""
 "restriction part of a rql query. For entity rql expression, X and U are "
 "predefined respectivly to the current object and to the request user. For "
@@ -3240,9 +3258,6 @@
 msgid "september"
 msgstr ""
 
-msgid "server debug information"
-msgstr ""
-
 msgid "server information"
 msgstr ""
 
@@ -3792,6 +3807,9 @@
 msgid "vcard"
 msgstr ""
 
+msgid "versions configuration"
+msgstr ""
+
 msgid "view"
 msgstr ""
 
--- a/i18n/es.po	Fri Feb 26 08:46:27 2010 +0100
+++ b/i18n/es.po	Fri Feb 26 09:54:03 2010 +0100
@@ -199,9 +199,6 @@
 msgid "Any"
 msgstr "Cualquiera"
 
-msgid "Application"
-msgstr "Aplicación"
-
 msgid "Attributes"
 msgstr "Atributos"
 
@@ -356,9 +353,6 @@
 msgid "Entities"
 msgstr "Entidades"
 
-msgid "Environment"
-msgstr "Ambiente"
-
 msgid "ExternalUri"
 msgstr ""
 
@@ -383,6 +377,9 @@
 msgid "Help"
 msgstr ""
 
+msgid "Instance"
+msgstr ""
+
 msgid "Int"
 msgstr "Número entero"
 
@@ -512,9 +509,6 @@
 msgid "Repository"
 msgstr ""
 
-msgid "Request"
-msgstr "Petición"
-
 #, python-format
 msgid "Schema %s"
 msgstr "Esquema %s"
@@ -525,9 +519,6 @@
 msgid "Search for"
 msgstr "Buscar"
 
-msgid "Server"
-msgstr "Servidor"
-
 msgid "SizeConstraint"
 msgstr ""
 
@@ -668,6 +659,9 @@
 msgid "Used by:"
 msgstr "Utilizado por :"
 
+msgid "Web server"
+msgstr ""
+
 msgid "What's new?"
 msgstr "Lo último en el sitio"
 
@@ -1513,6 +1507,12 @@
 msgid "condition_object"
 msgstr "condición de"
 
+msgid "config mode"
+msgstr ""
+
+msgid "config type"
+msgstr ""
+
 msgid "confirm password"
 msgstr "Confirmar contraseña"
 
@@ -2426,9 +2426,6 @@
 msgid "hide filter form"
 msgstr "Esconder el filtro"
 
-msgid "home"
-msgstr "Inicio"
-
 msgid ""
 "how to format date and time in the ui (\"man strftime\" for format "
 "description)"
@@ -2581,6 +2578,9 @@
 msgid "inlined"
 msgstr ""
 
+msgid "instance home"
+msgstr ""
+
 msgid "instance schema"
 msgstr ""
 
@@ -2652,6 +2652,9 @@
 msgid "last connection date"
 msgstr "Ultima fecha de conexión"
 
+msgid "last usage"
+msgstr ""
+
 msgid "last_login_time"
 msgstr "Ultima fecha de conexión"
 
@@ -2914,6 +2917,9 @@
 msgid "no related project"
 msgstr "no hay proyecto relacionado"
 
+msgid "no repository sessions found"
+msgstr ""
+
 msgid "no selected entities"
 msgstr "no hay entidades seleccionadas"
 
@@ -2924,6 +2930,9 @@
 msgid "no version information"
 msgstr "no información de version"
 
+msgid "no web sessions found"
+msgstr ""
+
 msgid "normal"
 msgstr ""
 
@@ -2960,6 +2969,12 @@
 msgid "open all"
 msgstr "abrir todos"
 
+msgid "opened sessions"
+msgstr ""
+
+msgid "opened web sessions"
+msgstr ""
+
 msgid "order"
 msgstr "orden"
 
@@ -3207,6 +3222,9 @@
 msgid "required field"
 msgstr "Campo requerido"
 
+msgid "resources usage"
+msgstr ""
+
 msgid ""
 "restriction part of a rql query. For entity rql expression, X and U are "
 "predefined respectivly to the current object and to the request user. For "
@@ -3317,9 +3335,6 @@
 msgid "september"
 msgstr "septiembre"
 
-msgid "server debug information"
-msgstr "server debug information"
-
 msgid "server information"
 msgstr "server information"
 
@@ -3879,6 +3894,9 @@
 msgid "vcard"
 msgstr "vcard"
 
+msgid "versions configuration"
+msgstr ""
+
 msgid "view"
 msgstr "ver"
 
@@ -3998,12 +4016,24 @@
 #~ msgid "%s results matching query"
 #~ msgstr "%s resultados de la demanda"
 
+#~ msgid "Application"
+#~ msgstr "Aplicación"
+
 #~ msgid "Debug level set to %s"
 #~ msgstr "Nivel de debug puesto a %s"
 
+#~ msgid "Environment"
+#~ msgstr "Ambiente"
+
 #~ msgid "No query has been executed"
 #~ msgstr "Ninguna búsqueda ha sido ejecutada"
 
+#~ msgid "Request"
+#~ msgstr "Petición"
+
+#~ msgid "Server"
+#~ msgstr "Servidor"
+
 #~ msgid "There is no workflow defined for this entity."
 #~ msgstr "No hay workflow para este entidad"
 
@@ -4206,6 +4236,9 @@
 #~ msgid "groups allowed to update entities of this type"
 #~ msgstr "Grupos autorizados a actualizar entidades de este tipo"
 
+#~ msgid "home"
+#~ msgstr "Inicio"
+
 #~ msgid "initial state for entities of this type"
 #~ msgstr "Estado inicial para las entidades de este tipo"
 
@@ -4288,6 +4321,9 @@
 #~ msgid "rql expression allowing to update entities of this type"
 #~ msgstr "expresion RQL permitiendo actualizar entidades de este tipo"
 
+#~ msgid "server debug information"
+#~ msgstr "server debug information"
+
 #~ msgid ""
 #~ "use to define a transition from one or multiple states to a destination "
 #~ "states in workflow's definitions."
--- a/i18n/fr.po	Fri Feb 26 08:46:27 2010 +0100
+++ b/i18n/fr.po	Fri Feb 26 09:54:03 2010 +0100
@@ -198,9 +198,6 @@
 msgid "Any"
 msgstr "N'importe"
 
-msgid "Application"
-msgstr "Application"
-
 msgid "Attributes"
 msgstr "Attributs"
 
@@ -355,9 +352,6 @@
 msgid "Entities"
 msgstr "entités"
 
-msgid "Environment"
-msgstr "Environement"
-
 msgid "ExternalUri"
 msgstr "Uri externe"
 
@@ -382,6 +376,9 @@
 msgid "Help"
 msgstr "Aide"
 
+msgid "Instance"
+msgstr "Instance"
+
 msgid "Int"
 msgstr "Nombre entier"
 
@@ -511,9 +508,6 @@
 msgid "Repository"
 msgstr "Entrepôt de données"
 
-msgid "Request"
-msgstr "Requête"
-
 #, python-format
 msgid "Schema %s"
 msgstr "Schéma %s"
@@ -524,9 +518,6 @@
 msgid "Search for"
 msgstr "Rechercher"
 
-msgid "Server"
-msgstr "Serveur"
-
 msgid "SizeConstraint"
 msgstr "contrainte de taille"
 
@@ -667,6 +658,9 @@
 msgid "Used by:"
 msgstr "Utilisé par :"
 
+msgid "Web server"
+msgstr "Serveur web"
+
 msgid "What's new?"
 msgstr "Nouveautés"
 
@@ -1521,6 +1515,12 @@
 msgid "condition_object"
 msgstr "condition de"
 
+msgid "config mode"
+msgstr "mode de configuration"
+
+msgid "config type"
+msgstr "type de configuration"
+
 msgid "confirm password"
 msgstr "confirmer le mot de passe"
 
@@ -1690,7 +1690,8 @@
 msgid ""
 "creating RQLExpression (CWAttribute %(linkto)s update_permission "
 "RQLExpression)"
-msgstr "création d'une expression rql pour le droit de mise à jour de %(linkto)s"
+msgstr ""
+"création d'une expression rql pour le droit de mise à jour de %(linkto)s"
 
 msgid ""
 "creating RQLExpression (CWEType %(linkto)s add_permission RQLExpression)"
@@ -2450,9 +2451,6 @@
 msgid "hide filter form"
 msgstr "cacher le filtre"
 
-msgid "home"
-msgstr "maison"
-
 msgid ""
 "how to format date and time in the ui (\"man strftime\" for format "
 "description)"
@@ -2605,6 +2603,9 @@
 msgid "inlined"
 msgstr "mise en ligne"
 
+msgid "instance home"
+msgstr "répertoire de l'instance"
+
 msgid "instance schema"
 msgstr "schéma de l'instance"
 
@@ -2677,6 +2678,9 @@
 msgid "last connection date"
 msgstr "dernière date de connexion"
 
+msgid "last usage"
+msgstr "dernier usage"
+
 msgid "last_login_time"
 msgstr "dernière date de connexion"
 
@@ -2935,6 +2939,9 @@
 msgid "no related project"
 msgstr "pas de projet rattaché"
 
+msgid "no repository sessions found"
+msgstr "aucune session trouvée"
+
 msgid "no selected entities"
 msgstr "pas d'entité sélectionnée"
 
@@ -2945,6 +2952,9 @@
 msgid "no version information"
 msgstr "pas d'information de version"
 
+msgid "no web sessions found"
+msgstr "aucune session trouvée"
+
 msgid "normal"
 msgstr "normal"
 
@@ -2981,6 +2991,12 @@
 msgid "open all"
 msgstr "tout ouvrir"
 
+msgid "opened sessions"
+msgstr "sessions ouvertes"
+
+msgid "opened web sessions"
+msgstr "sessions web ouvertes"
+
 msgid "order"
 msgstr "ordre"
 
@@ -3230,6 +3246,9 @@
 msgid "required field"
 msgstr "champ requis"
 
+msgid "resources usage"
+msgstr "resources utilisées"
+
 msgid ""
 "restriction part of a rql query. For entity rql expression, X and U are "
 "predefined respectivly to the current object and to the request user. For "
@@ -3341,9 +3360,6 @@
 msgid "september"
 msgstr "septembre"
 
-msgid "server debug information"
-msgstr "informations de déboguage serveur"
-
 msgid "server information"
 msgstr "informations serveur"
 
@@ -3830,9 +3846,9 @@
 "states in workflow's definitions. Transition without destination state will "
 "go back to the state from which we arrived to the current state."
 msgstr ""
-"utilisé dans une définition de processus pour ajouter une transition "
-"depuis un ou plusieurs états vers un état de destination. Une transition sans "
-"état de destination retournera à l'état précédent l'état courant."
+"utilisé dans une définition de processus pour ajouter une transition depuis "
+"un ou plusieurs états vers un état de destination. Une transition sans état "
+"de destination retournera à l'état précédent l'état courant."
 
 msgid "use_email"
 msgstr "adresse électronique"
@@ -3908,6 +3924,9 @@
 msgid "vcard"
 msgstr "vcard"
 
+msgid "versions configuration"
+msgstr "configuration de version"
+
 msgid "view"
 msgstr "voir"
 
--- a/server/repository.py	Fri Feb 26 08:46:27 2010 +0100
+++ b/server/repository.py	Fri Feb 26 09:54:03 2010 +0100
@@ -383,7 +383,8 @@
         except ZeroDivisionError:
             pass
 
-    def stats(self):
+    def stats(self): # XXX restrict to managers session?
+        import threading
         results = {}
         for hits, misses, title in (
             (self.querier.cache_hit, self.querier.cache_miss, 'rqlt_st'),
@@ -392,10 +393,10 @@
             results['%s_cache_hit' % title] =  hits
             results['%s_cache_miss' % title] = misses
             results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses)
-
         results['sql_no_cache'] = self.system_source.no_cache
         results['nb_open_sessions'] = len(self._sessions)
-        results['nb_threads'] = len(self._running_threads)
+        results['nb_active_threads'] = threading.activeCount()
+        results['looping_tasks'] = ', '.join(str(t) for t in self._looping_tasks)
         results['available_pools'] = self._available_pools.qsize()
         return results
 
--- a/server/utils.py	Fri Feb 26 08:46:27 2010 +0100
+++ b/server/utils.py	Fri Feb 26 09:54:03 2010 +0100
@@ -107,6 +107,9 @@
         self.func = auto_restart_func
         self.name = func.__name__
 
+    def __str__(self):
+        return '%s (%s seconds)' % (self.name, self.interval)
+
     def start(self):
         self._t = Timer(self.interval, self.func)
         self._t.start()
--- a/web/views/debug.py	Fri Feb 26 08:46:27 2010 +0100
+++ b/web/views/debug.py	Fri Feb 26 09:54:03 2010 +0100
@@ -25,41 +25,89 @@
         w(u'</ul>')
 
 
-class DebugView(StartupView):
-    __regid__ = 'debug'
+
+class ProcessInformationView(StartupView):
+    __regid__ = 'info'
     __select__ = none_rset() & match_user_groups('managers')
-    title = _('server debug information')
+
+    title = _('server information')
 
     def call(self, **kwargs):
         """display server information"""
+        req = self._cw
+        dtformat = req.property_value('ui.datetime-format')
+        _ = req._
         w = self.w
-        w(u'<h1>server sessions</h1>')
-        sessions = self._cw.cnx._repo._sessions.items()
+        # generic instance information
+        w(u'<h1>%s</h1>' % _('Instance'))
+        w(u'<table>')
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            _('config type'), self._cw.vreg.config.name))
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            _('config mode'), self._cw.vreg.config.mode))
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            _('instance home'), self._cw.vreg.config.apphome))
+        w(u'</table>')
+        vcconf = req.vreg.config.vc_config()
+        w(u'<h3>%s</h3>' % _('versions configuration'))
+        w(u'<table>')
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            'CubicWeb', vcconf.get('cubicweb', _('no version information'))))
+        for cube in sorted(self._cw.vreg.config.cubes()):
+            cubeversion = vcconf.get(cube, _('no version information'))
+            w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+                cube, cubeversion))
+        w(u'</table>')
+        # repository information
+        repo = req.vreg.config.repository(None)
+        w(u'<h1>%s</h1>' % _('Repository'))
+        w(u'<h3>%s</h3>' % _('resources usage'))
+        w(u'<table>')
+        stats = repo.stats()
+        for element in sorted(stats):
+            w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
+                   % (element, stats[element],
+                      element.endswith('percent') and '%' or '' ))
+        w(u'</table>')
+        if req.cnx._cnxtype == 'inmemory':
+            w(u'<h3>%s</h3>' % _('opened sessions'))
+            sessions = repo._sessions.values()
+            if sessions:
+                w(u'<ul>')
+                for session in sessions:
+                    w(u'<li>%s (%s: %s)<br/>' % (
+                        xml_escape(unicode(session)),
+                        _('last usage'),
+                        strftime(dtformat, localtime(session.timestamp))))
+                    dict_to_html(w, session.data)
+                    w(u'</li>')
+                w(u'</ul>')
+            else:
+                w(u'<p>%s</p>' % _('no repository sessions found'))
+        # web server information
+        w(u'<h1>%s</h1>' % _('Web server'))
+        w(u'<table>')
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            _('base url'), req.base_url()))
+        w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
+            _('data directory url'), req.datadir_url))
+        w(u'</table>')
+        from cubicweb.web.application import SESSION_MANAGER
+        sessions = SESSION_MANAGER.current_sessions()
+        w(u'<h3>%s</h3>' % _('opened web sessions'))
         if sessions:
             w(u'<ul>')
-            for sid, session in sessions:
-                w(u'<li>%s  (last usage: %s)<br/>' % (xml_escape(str(session)),
-                                                      strftime('%Y-%m-%d %H:%M:%S',
-                                                               localtime(session.timestamp))))
+            for session in sessions:
+                w(u'<li>%s (%s: %s)<br/>' % (
+                    session.sessionid,
+                    _('last usage'),
+                    strftime(dtformat, localtime(session.last_usage_time))))
                 dict_to_html(w, session.data)
                 w(u'</li>')
             w(u'</ul>')
         else:
-            w(u'<p>no server sessions found</p>')
-        from cubicweb.web.application import SESSION_MANAGER
-        w(u'<h1>web sessions</h1>')
-        sessions = SESSION_MANAGER.current_sessions()
-        if sessions:
-            w(u'<ul>')
-            for session in sessions:
-                w(u'<li>%s (last usage: %s)<br/>' % (session.sessionid,
-                                                     strftime('%Y-%m-%d %H:%M:%S',
-                                                              localtime(session.last_usage_time))))
-                dict_to_html(w, session.data)
-                w(u'</li>')
-            w(u'</ul>')
-        else:
-            w(u'<p>no web sessions found</p>')
+            w(u'<p>%s</p>' % _('no web sessions found'))
+
 
 
 class RegistryView(StartupView):
--- a/web/views/management.py	Fri Feb 26 08:46:27 2010 +0100
+++ b/web/views/management.py	Fri Feb 26 09:54:03 2010 +0100
@@ -273,76 +273,6 @@
     return binfo
 
 
-class ProcessInformationView(StartupView):
-    __regid__ = 'info'
-    __select__ = none_rset() & match_user_groups('users', 'managers')
-
-    title = _('server information')
-
-    def call(self, **kwargs):
-        """display server information"""
-        vcconf = self._cw.vreg.config.vc_config()
-        req = self._cw
-        _ = req._
-        # display main information
-        self.w(u'<h3>%s</h3>' % _('Application'))
-        self.w(u'<table border="1">')
-        self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
-            'CubicWeb', vcconf.get('cubicweb', _('no version information'))))
-        for pkg in self._cw.vreg.config.cubes():
-            pkgversion = vcconf.get(pkg, _('no version information'))
-            self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
-                pkg, pkgversion))
-        self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
-            _('home'), self._cw.vreg.config.apphome))
-        self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
-            _('base url'), req.base_url()))
-        self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
-            _('data directory url'), req.datadir_url))
-        self.w(u'</table>')
-        self.w(u'<br/>')
-        self.w(u'<h3>%s</h3>' % _('Repository'))
-        self.w(u'<table border="1">')
-        stats = self._cw.vreg.config.repository(None).stats()
-        for element in stats:
-            self.w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
-                   % (element, stats[element],
-                      element.endswith('percent') and '%' or '' ))
-        self.w(u'</table>')
-
-        # environment and request and server information
-        try:
-            # need to remove our adapter and then modpython-apache wrapper...
-            env = req._areq._req.subprocess_env
-        except AttributeError:
-            return
-        self.w(u'<h3>%s</h3>' % _('Environment'))
-        self.w(u'<table border="1">')
-        for attr in env.keys():
-            self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
-                   % (attr, xml_escape(env[attr])))
-        self.w(u'</table>')
-        self.w(u'<h3>%s</h3>' % _('Request'))
-        self.w(u'<table border="1">')
-        for attr in ('filename', 'form', 'hostname', 'main', 'method',
-                     'path_info', 'protocol',
-                     'search_state', 'the_request', 'unparsed_uri', 'uri'):
-            val = getattr(req, attr)
-            self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
-                   % (attr, xml_escape(val)))
-        self.w(u'</table>')
-        server = req.server
-        self.w(u'<h3>%s</h3>' % _('Server'))
-        self.w(u'<table border="1">')
-        for attr in dir(server):
-            val = getattr(server, attr)
-            if attr.startswith('_') or callable(val):
-                continue
-            self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
-                   % (attr, xml_escape(val)))
-        self.w(u'</table>')
-
-
 class CwStats(View):
     """A textual stats output for monitoring tools such as munin """