web/views/management.py
branchstable
changeset 4714 fccda6dd91bf
parent 4713 785299dfc2c0
child 5232 78c1a531f7b3
child 5421 8167de96c523
equal deleted inserted replaced
4713:785299dfc2c0 4714:fccda6dd91bf
   271         binfo += u":Package %s version: %s\n" % (pkg, pkgversion)
   271         binfo += u":Package %s version: %s\n" % (pkg, pkgversion)
   272     binfo += '\n'
   272     binfo += '\n'
   273     return binfo
   273     return binfo
   274 
   274 
   275 
   275 
   276 class ProcessInformationView(StartupView):
       
   277     __regid__ = 'info'
       
   278     __select__ = none_rset() & match_user_groups('users', 'managers')
       
   279 
       
   280     title = _('server information')
       
   281 
       
   282     def call(self, **kwargs):
       
   283         """display server information"""
       
   284         vcconf = self._cw.vreg.config.vc_config()
       
   285         req = self._cw
       
   286         _ = req._
       
   287         # display main information
       
   288         self.w(u'<h3>%s</h3>' % _('Application'))
       
   289         self.w(u'<table border="1">')
       
   290         self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   291             'CubicWeb', vcconf.get('cubicweb', _('no version information'))))
       
   292         for pkg in self._cw.vreg.config.cubes():
       
   293             pkgversion = vcconf.get(pkg, _('no version information'))
       
   294             self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   295                 pkg, pkgversion))
       
   296         self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   297             _('home'), self._cw.vreg.config.apphome))
       
   298         self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   299             _('base url'), req.base_url()))
       
   300         self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % (
       
   301             _('data directory url'), req.datadir_url))
       
   302         self.w(u'</table>')
       
   303         self.w(u'<br/>')
       
   304         self.w(u'<h3>%s</h3>' % _('Repository'))
       
   305         self.w(u'<table border="1">')
       
   306         stats = self._cw.vreg.config.repository(None).stats()
       
   307         for element in stats:
       
   308             self.w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>'
       
   309                    % (element, stats[element],
       
   310                       element.endswith('percent') and '%' or '' ))
       
   311         self.w(u'</table>')
       
   312 
       
   313         # environment and request and server information
       
   314         try:
       
   315             # need to remove our adapter and then modpython-apache wrapper...
       
   316             env = req._areq._req.subprocess_env
       
   317         except AttributeError:
       
   318             return
       
   319         self.w(u'<h3>%s</h3>' % _('Environment'))
       
   320         self.w(u'<table border="1">')
       
   321         for attr in env.keys():
       
   322             self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
       
   323                    % (attr, xml_escape(env[attr])))
       
   324         self.w(u'</table>')
       
   325         self.w(u'<h3>%s</h3>' % _('Request'))
       
   326         self.w(u'<table border="1">')
       
   327         for attr in ('filename', 'form', 'hostname', 'main', 'method',
       
   328                      'path_info', 'protocol',
       
   329                      'search_state', 'the_request', 'unparsed_uri', 'uri'):
       
   330             val = getattr(req, attr)
       
   331             self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
       
   332                    % (attr, xml_escape(val)))
       
   333         self.w(u'</table>')
       
   334         server = req.server
       
   335         self.w(u'<h3>%s</h3>' % _('Server'))
       
   336         self.w(u'<table border="1">')
       
   337         for attr in dir(server):
       
   338             val = getattr(server, attr)
       
   339             if attr.startswith('_') or callable(val):
       
   340                 continue
       
   341             self.w(u'<tr><th align="left">%s</th><td>%s</td></tr>'
       
   342                    % (attr, xml_escape(val)))
       
   343         self.w(u'</table>')
       
   344 
       
   345 
       
   346 class CwStats(View):
   276 class CwStats(View):
   347     """A textual stats output for monitoring tools such as munin """
   277     """A textual stats output for monitoring tools such as munin """
   348 
   278 
   349     __regid__ = 'processinfo'
   279     __regid__ = 'processinfo'
   350     content_type = 'text/txt'
   280     content_type = 'text/txt'