23 w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
23 w(u'<li><span class="label">%s</span>: <span>%s</span></li>' % ( |
24 xml_escape(str(key)), xml_escape(repr(dict[key])))) |
24 xml_escape(str(key)), xml_escape(repr(dict[key])))) |
25 w(u'</ul>') |
25 w(u'</ul>') |
26 |
26 |
27 |
27 |
28 class DebugView(StartupView): |
28 |
29 __regid__ = 'debug' |
29 class ProcessInformationView(StartupView): |
|
30 __regid__ = 'info' |
30 __select__ = none_rset() & match_user_groups('managers') |
31 __select__ = none_rset() & match_user_groups('managers') |
31 title = _('server debug information') |
32 |
|
33 title = _('server information') |
32 |
34 |
33 def call(self, **kwargs): |
35 def call(self, **kwargs): |
34 """display server information""" |
36 """display server information""" |
|
37 req = self._cw |
|
38 dtformat = req.property_value('ui.datetime-format') |
|
39 _ = req._ |
35 w = self.w |
40 w = self.w |
36 w(u'<h1>server sessions</h1>') |
41 # generic instance information |
37 sessions = self._cw.cnx._repo._sessions.items() |
42 w(u'<h1>%s</h1>' % _('Instance')) |
|
43 w(u'<table>') |
|
44 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
45 _('config type'), self._cw.vreg.config.name)) |
|
46 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
47 _('config mode'), self._cw.vreg.config.mode)) |
|
48 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
49 _('instance home'), self._cw.vreg.config.apphome)) |
|
50 w(u'</table>') |
|
51 vcconf = req.vreg.config.vc_config() |
|
52 w(u'<h3>%s</h3>' % _('versions configuration')) |
|
53 w(u'<table>') |
|
54 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
55 'CubicWeb', vcconf.get('cubicweb', _('no version information')))) |
|
56 for cube in sorted(self._cw.vreg.config.cubes()): |
|
57 cubeversion = vcconf.get(cube, _('no version information')) |
|
58 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
59 cube, cubeversion)) |
|
60 w(u'</table>') |
|
61 # repository information |
|
62 repo = req.vreg.config.repository(None) |
|
63 w(u'<h1>%s</h1>' % _('Repository')) |
|
64 w(u'<h3>%s</h3>' % _('resources usage')) |
|
65 w(u'<table>') |
|
66 stats = repo.stats() |
|
67 for element in sorted(stats): |
|
68 w(u'<tr><th align="left">%s</th><td>%s %s</td></tr>' |
|
69 % (element, stats[element], |
|
70 element.endswith('percent') and '%' or '' )) |
|
71 w(u'</table>') |
|
72 if req.cnx._cnxtype == 'inmemory': |
|
73 w(u'<h3>%s</h3>' % _('opened sessions')) |
|
74 sessions = repo._sessions.values() |
|
75 if sessions: |
|
76 w(u'<ul>') |
|
77 for session in sessions: |
|
78 w(u'<li>%s (%s: %s)<br/>' % ( |
|
79 xml_escape(unicode(session)), |
|
80 _('last usage'), |
|
81 strftime(dtformat, localtime(session.timestamp)))) |
|
82 dict_to_html(w, session.data) |
|
83 w(u'</li>') |
|
84 w(u'</ul>') |
|
85 else: |
|
86 w(u'<p>%s</p>' % _('no repository sessions found')) |
|
87 # web server information |
|
88 w(u'<h1>%s</h1>' % _('Web server')) |
|
89 w(u'<table>') |
|
90 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
91 _('base url'), req.base_url())) |
|
92 w(u'<tr><th align="left">%s</th><td>%s</td></tr>' % ( |
|
93 _('data directory url'), req.datadir_url)) |
|
94 w(u'</table>') |
|
95 from cubicweb.web.application import SESSION_MANAGER |
|
96 sessions = SESSION_MANAGER.current_sessions() |
|
97 w(u'<h3>%s</h3>' % _('opened web sessions')) |
38 if sessions: |
98 if sessions: |
39 w(u'<ul>') |
99 w(u'<ul>') |
40 for sid, session in sessions: |
100 for session in sessions: |
41 w(u'<li>%s (last usage: %s)<br/>' % (xml_escape(str(session)), |
101 w(u'<li>%s (%s: %s)<br/>' % ( |
42 strftime('%Y-%m-%d %H:%M:%S', |
102 session.sessionid, |
43 localtime(session.timestamp)))) |
103 _('last usage'), |
|
104 strftime(dtformat, localtime(session.last_usage_time)))) |
44 dict_to_html(w, session.data) |
105 dict_to_html(w, session.data) |
45 w(u'</li>') |
106 w(u'</li>') |
46 w(u'</ul>') |
107 w(u'</ul>') |
47 else: |
108 else: |
48 w(u'<p>no server sessions found</p>') |
109 w(u'<p>%s</p>' % _('no web sessions found')) |
49 from cubicweb.web.application import SESSION_MANAGER |
110 |
50 w(u'<h1>web sessions</h1>') |
|
51 sessions = SESSION_MANAGER.current_sessions() |
|
52 if sessions: |
|
53 w(u'<ul>') |
|
54 for session in sessions: |
|
55 w(u'<li>%s (last usage: %s)<br/>' % (session.sessionid, |
|
56 strftime('%Y-%m-%d %H:%M:%S', |
|
57 localtime(session.last_usage_time)))) |
|
58 dict_to_html(w, session.data) |
|
59 w(u'</li>') |
|
60 w(u'</ul>') |
|
61 else: |
|
62 w(u'<p>no web sessions found</p>') |
|
63 |
111 |
64 |
112 |
65 class RegistryView(StartupView): |
113 class RegistryView(StartupView): |
66 __regid__ = 'registry' |
114 __regid__ = 'registry' |
67 __select__ = StartupView.__select__ & match_user_groups('managers') |
115 __select__ = StartupView.__select__ & match_user_groups('managers') |