mirror of
https://github.com/dkmstr/openuds.git
synced 2024-12-23 17:34:17 +03:00
Adding first stats to admin interface
This commit is contained in:
parent
0a477cae68
commit
3bc044518f
@ -49,18 +49,17 @@ cache = Cache('StatsDispatcher')
|
|||||||
|
|
||||||
# Enclosed methods under /syatem path
|
# Enclosed methods under /syatem path
|
||||||
POINTS = 300
|
POINTS = 300
|
||||||
SINCE = 30 # Days
|
SINCE = 1000 # Days
|
||||||
USE_MAX = True
|
USE_MAX = True
|
||||||
|
|
||||||
|
|
||||||
def getServicesPoolsCounters(servicePool, counter_type):
|
def getServicesPoolsCounters(servicePool, counter_type):
|
||||||
try:
|
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()
|
to = getSqlDatetime()
|
||||||
since = to - timedelta(days=SINCE)
|
since = to - timedelta(days=SINCE)
|
||||||
val = cache.get(cacheKey)
|
val = cache.get(cacheKey)
|
||||||
if val is None:
|
if val is None:
|
||||||
|
|
||||||
if servicePool is None:
|
if servicePool is None:
|
||||||
us = DeployedService()
|
us = DeployedService()
|
||||||
complete = True # Get all deployed services stats
|
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):
|
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]) })
|
val.append({ 'stamp': x[0], 'value': int(x[1]) })
|
||||||
if len(val) > 2:
|
if len(val) > 2:
|
||||||
cache.put(cacheKey, cPickle.dumps(val).encode('zip'), 3600)
|
cache.put(cacheKey, cPickle.dumps(val).encode('zip'), 600)
|
||||||
else:
|
else:
|
||||||
val = [{'stamp':since, 'value':0 }, {'stamp':to, 'value':0}]
|
val = [{'stamp':since, 'value':0 }, {'stamp':to, 'value':0}]
|
||||||
else:
|
else:
|
||||||
@ -89,18 +88,26 @@ class System(Handler):
|
|||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
logger.debug('args: {0}'.format(self._args))
|
logger.debug('args: {0}'.format(self._args))
|
||||||
if len(self._args) == 1 and self._args[0] == 'overview': # System overview
|
if len(self._args) == 1:
|
||||||
users = User.objects.count()
|
if self._args[0] == 'overview': # System overview
|
||||||
services = Service.objects.count()
|
users = User.objects.count()
|
||||||
user_services = UserService.objects.count()
|
services = Service.objects.count()
|
||||||
restrained_services_pools = len(DeployedService.getRestraineds())
|
user_services = UserService.objects.count()
|
||||||
return {
|
restrained_services_pools = len(DeployedService.getRestraineds())
|
||||||
'users': users,
|
return {
|
||||||
'services': services,
|
'users': users,
|
||||||
'user_services': user_services,
|
'services': services,
|
||||||
'restrained_services_pools': restrained_services_pools,
|
'user_services': user_services,
|
||||||
'user_services_assigned': getServicesPoolsCounters(None, counters.CT_ASSIGNED)
|
'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')
|
raise RequestError('invalid request')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user