|
1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 """Define server side service provided by cubicweb""" |
|
19 |
|
20 import threading |
|
21 |
|
22 from cubicweb.server import Service |
|
23 from cubicweb.predicates import match_user_groups |
|
24 |
|
25 class StatsService(Service): |
|
26 """Return a dictionary containing some statistics about the repository |
|
27 resources usage. |
|
28 """ |
|
29 |
|
30 __regid__ = 'repo_stats' |
|
31 __select__ = match_user_groups('managers') |
|
32 |
|
33 def call(self): |
|
34 repo = self._cw.repo # Service are repo side only. |
|
35 results = {} |
|
36 querier = repo.querier |
|
37 source = repo.system_source |
|
38 for size, maxsize, hits, misses, title in ( |
|
39 (len(querier._rql_cache), repo.config['rql-cache-size'], |
|
40 querier.cache_hit, querier.cache_miss, 'rqlt_st'), |
|
41 (len(source._cache), repo.config['rql-cache-size'], |
|
42 source.cache_hit, source.cache_miss, 'sql'), |
|
43 ): |
|
44 results['%s_cache_size' % title] = '%s / %s' % (size, maxsize) |
|
45 results['%s_cache_hit' % title] = hits |
|
46 results['%s_cache_miss' % title] = misses |
|
47 results['%s_cache_hit_percent' % title] = (hits * 100) / (hits + misses) |
|
48 results['type_source_cache_size'] = len(repo._type_source_cache) |
|
49 results['extid_cache_size'] = len(repo._extid_cache) |
|
50 results['sql_no_cache'] = repo.system_source.no_cache |
|
51 results['nb_open_sessions'] = len(repo._sessions) |
|
52 results['nb_active_threads'] = threading.activeCount() |
|
53 looping_tasks = repo._tasks_manager._looping_tasks |
|
54 results['looping_tasks'] = ', '.join(str(t) for t in looping_tasks) |
|
55 results['available_cnxsets'] = repo._cnxsets_pool.qsize() |
|
56 results['threads'] = ', '.join(sorted(str(t) for t in threading.enumerate())) |
|
57 return results |