def error_panel(db): host = zoom.system.request.host data = db( """ select log.id, username, path, timestamp from log left join users on log.user_id = users.id where log.status in ("E") and timestamp>=%s and server = %s order by log.id desc limit 10 """, today(), host) rows = [] for rec in data: row = [ link_to(str(rec[0]), '/admin/entry/' + str(rec[0])), link_to_user(rec[1]), rec[2], how_long_ago(rec[3]), ] rows.append(row) labels = 'id', 'user', 'path', 'when' return zoom.browse(rows, labels=labels, title=link_to_page('Errors'))
def get_index_metrics(db): def count(where, *args): """Return the result of a count query""" return '{:,}'.format((list(db('select count(*) from ' + where, *args))[0][0])) def avg(metric, where, *args): """Return the result of a query that calculates an average""" return '{:,.1f}'.format( (list(db('select avg({}) from {}'.format(metric, where), *args))[0][0])) the_day = today() host = zoom.system.request.host num_users = count('users where status="A"') num_groups = count('groups where type="U"') num_requests = count( 'log where status="C" and server=%s and timestamp>=%s', host, the_day) num_errors = count('log where status="E" and server=%s and timestamp>=%s', host, the_day) avg_speed = avg( 'elapsed', 'log where status="C" and server=%s and timestamp>=%s and path<>"/login"', host, the_day) num_authorizations = count('audit_log where timestamp>=%s', the_day) metrics = [('Users', '/admin/users', num_users), ('Groups', '/admin/groups', num_groups), ('Requests Today', '/admin/requests', num_requests), ('Errors Today', '/admin/errors', num_errors), ('Performance (ms)', '/admin/requests', avg_speed), ('Authorizations Today', '/admin/audit', num_authorizations)] return metrics
def users_panel(db): host = zoom.system.request.host data = db( """ select users.username, max(log.timestamp) as timestamp, count(*) as requests from log, users where log.user_id = users.id and timestamp >= %s and server = %s and path not like "%%\\/\\_%%" group by users.username order by timestamp desc limit 10 """, today() - datetime.timedelta(days=14), host) rows = [] for rec in data: row = [ link_to_user(rec[0]), how_long_ago(rec[1]), rec[2], ] rows.append(row) labels = 'user', 'last seen', 'requests' return zoom.browse(rows, labels=labels, title=link_to_page('Users'))
def get_index_metrics(db): def count(where, *args): return '{:,}'.format((list(db('select count(*) from ' + where, *args))[0][0])) def avg(metric, where, *args): return '{:,.1f}'.format((list(db('select avg({}) from {}'.format(metric, where), *args))[0][0])) num_users = count('users where status="A"') num_groups = count('groups where type="U"') num_requests = count('log where status="C" and timestamp>=%s', today()) num_errors = count('log where status="E" and timestamp>=%s', today()) avg_speed = avg('elapsed', 'log where status="C" and timestamp>=%s', today()) metrics = [ ('Users', '/admin/users', num_users), ('Groups', '/admin/groups', num_groups), ('Requests Today', '/admin/requests', num_requests), ('Errors Today', '/admin/errors', num_errors), ('Performance (ms)', '/admin/requests', avg_speed), ] return metrics