1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Adding first stats to admin interface

This commit is contained in:
Adolfo Gómez 2014-01-28 06:59:45 +00:00
parent 0a477cae68
commit 3bc044518f

View File

@ -49,18 +49,17 @@ cache = Cache('StatsDispatcher')
# Enclosed methods under /syatem path
POINTS = 300
SINCE = 30 # Days
SINCE = 1000 # Days
USE_MAX = True
def getServicesPoolsCounters(servicePool, counter_type):
try:
cacheKey = (servicePool and servicePool.id or 'all') + str(counter_type)
cacheKey = (servicePool and servicePool.id or 'all') + str(counter_type) + str(POINTS) + str(SINCE)
to = getSqlDatetime()
since = to - timedelta(days=SINCE)
val = cache.get(cacheKey)
if val is None:
if servicePool is None:
us = DeployedService()
complete = True # Get all deployed services stats
@ -71,7 +70,7 @@ def getServicesPoolsCounters(servicePool, counter_type):
for x in counters.getCounters(us, counter_type, since=since, to=to, limit=POINTS, use_max=USE_MAX, all=complete):
val.append({ 'stamp': x[0], 'value': int(x[1]) })
if len(val) > 2:
cache.put(cacheKey, cPickle.dumps(val).encode('zip'), 3600)
cache.put(cacheKey, cPickle.dumps(val).encode('zip'), 600)
else:
val = [{'stamp':since, 'value':0 }, {'stamp':to, 'value':0}]
else:
@ -89,18 +88,26 @@ class System(Handler):
def get(self):
logger.debug('args: {0}'.format(self._args))
if len(self._args) == 1 and self._args[0] == 'overview': # System overview
users = User.objects.count()
services = Service.objects.count()
user_services = UserService.objects.count()
restrained_services_pools = len(DeployedService.getRestraineds())
return {
'users': users,
'services': services,
'user_services': user_services,
'restrained_services_pools': restrained_services_pools,
'user_services_assigned': getServicesPoolsCounters(None, counters.CT_ASSIGNED)
}
if len(self._args) == 1:
if self._args[0] == 'overview': # System overview
users = User.objects.count()
services = Service.objects.count()
user_services = UserService.objects.count()
restrained_services_pools = len(DeployedService.getRestraineds())
return {
'users': users,
'services': services,
'user_services': user_services,
'restrained_services_pools': restrained_services_pools,
}
if len(self._args) == 2:
if self._args[0] == 'stats':
if self._args[1] == 'assigned':
return getServicesPoolsCounters(None, counters.CT_ASSIGNED)
if self._args[1] == 'inuse':
return getServicesPoolsCounters(None, counters.CT_INUSE)
raise RequestError('invalid request')