--- a/server/repository.py Fri Feb 26 07:04:52 2010 +0100
+++ b/server/repository.py Fri Feb 26 07:07:28 2010 +0100
@@ -328,8 +328,8 @@
return self._available_pools.get(True, timeout=5)
except Queue.Empty:
raise Exception('no pool available after 5 secs, probably either a '
- 'bug in code (to many uncommited/rollbacked '
- 'connections) or to much load on the server (in '
+ 'bug in code (too many uncommited/rollbacked '
+ 'connections) or too much load on the server (in '
'which case you can try to set a bigger '
'connections pools size)')
@@ -383,6 +383,22 @@
except ZeroDivisionError:
pass
+ def stats(self):
+ results = {}
+ for hits, misses, title in (
+ (self.querier.cache_hit, self.querier.cache_miss, 'rqlt_st'),
+ (self.system_source.cache_hit, self.system_source.cache_miss, 'sql'),
+ ):
+ 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['available_pools'] = self._available_pools.qsize()
+ return results
+
def _login_from_email(self, login):
session = self.internal_session()
try:
--- a/web/views/management.py Fri Feb 26 07:04:52 2010 +0100
+++ b/web/views/management.py Fri Feb 26 07:07:28 2010 +0100
@@ -12,7 +12,7 @@
from logilab.mtconverter import xml_escape
from cubicweb.selectors import yes, none_rset, match_user_groups, authenticated_user
-from cubicweb.view import AnyRsetView, StartupView, EntityView
+from cubicweb.view import AnyRsetView, StartupView, EntityView, View
from cubicweb.uilib import html_traceback, rest_traceback
from cubicweb.web import formwidgets as wdgs
from cubicweb.web.formfields import guess_field
@@ -301,6 +301,15 @@
_('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...
@@ -333,3 +342,19 @@
% (attr, xml_escape(val)))
self.w(u'</table>')
+
+class CwStats(View):
+ """A textual stats output for monitoring tools such as munin """
+
+ __regid__ = 'processinfo'
+ content_type = 'text/txt'
+ templatable = False
+ __select__ = none_rset() & match_user_groups('users', 'managers')
+
+ def call(self):
+ _ = self._cw._
+ stats = self._cw.vreg.config.repository(None).stats()
+ results = []
+ for element in stats:
+ results.append('%s %s' % (element, stats[element]))
+ self.w(u"%s" % _('\n'.join(results)))
--- a/web/views/urlrewrite.py Fri Feb 26 07:04:52 2010 +0100
+++ b/web/views/urlrewrite.py Fri Feb 26 07:07:28 2010 +0100
@@ -83,6 +83,7 @@
('/notfound', dict(vid='404')),
('/error', dict(vid='error')),
('/sparql', dict(vid='sparql')),
+ ('/processinfo', dict(vid='processinfo')),
# XXX should be case insensitive as 'create', but I would like to find another way than
# relying on the etype_selector
(rgx('/schema/([^/]+?)/?'), dict(vid='primary', rql=r'Any X WHERE X is CWEType, X name "\1"')),