Child: [2e9125] (diff)

Download this file

site_admin.py    55 lines (49 with data), 2.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import mimetypes
from collections import defaultdict
import pkg_resources
from tg import expose, redirect, flash, config, validate, request, response
from tg.decorators import with_trailing_slash, without_trailing_slash
from webob import exc
from pylons import c, g
from allura.lib import helpers as h
from allura.lib.security import require, has_project_access
from allura import model as M
class SiteAdminController(object):
@expose('jinja:site_admin_index.html')
@with_trailing_slash
def index(self):
with h.push_context('allura'):
require(has_project_access('security'))
neighborhoods = []
for n in M.Neighborhood.query.find():
project_count = M.Project.query.find(dict(neighborhood_id=n._id)).count()
configured_count = M.Project.query.find(dict(neighborhood_id=n._id, database_configured=True)).count()
neighborhoods.append((n.name, project_count, configured_count))
neighborhoods.sort(key=lambda t:(-t[2], -t[1]))
return dict(neighborhoods=neighborhoods)
@expose('jinja:site_admin_stats.html')
@without_trailing_slash
def stats(self, limit=25):
with h.push_context('allura'):
require(has_project_access('security'))
stats = defaultdict(lambda:defaultdict(list))
agg_timings = defaultdict(list)
for doc in M.Stats.m.find():
if doc.url.startswith('/_debug'): continue
doc_stats = stats[doc.url]
for t,val in doc.timers.iteritems():
doc_stats[t].append(val)
agg_timings[t].append(val)
for url, timings in stats.iteritems():
new_timings = dict(
(timer, sum(readings)/len(readings))
for timer, readings in timings.iteritems())
timings.update(new_timings)
agg_timings = dict(
(timer, sum(readings)/len(readings))
for timer, readings in agg_timings.iteritems())
stats = sorted(stats.iteritems(), key=lambda x:-x[1]['total'])
return dict(
agg_timings=agg_timings,
stats=stats[:int(limit)])