Added graphs to servicePool

This commit is contained in:
Adolfo Gómez García 2021-05-21 14:17:49 +02:00
parent c6d281580b
commit e8733e74d1

View File

@ -59,17 +59,17 @@ USE_MAX = True
def getServicesPoolsCounters( def getServicesPoolsCounters(
servicePool: typing.Optional[models.ServicePool], counter_type: int servicePool: typing.Optional[models.ServicePool], counter_type: int, since_days: int = SINCE
) -> typing.List[typing.Mapping[str, typing.Any]]: ) -> typing.List[typing.Mapping[str, typing.Any]]:
try: try:
cacheKey = ( cacheKey = (
(servicePool and str(servicePool.id) or 'all') (servicePool and str(servicePool.id) or 'all')
+ str(counter_type) + str(counter_type)
+ str(POINTS) + str(POINTS)
+ str(SINCE) + str(since_days)
) )
to = models.getSqlDatetime() to = models.getSqlDatetime()
since: datetime.datetime = to - datetime.timedelta(days=SINCE) since: datetime.datetime = to - datetime.timedelta(days=since_days)
cachedValue: typing.Optional[bytes] = cache.get(cacheKey) cachedValue: typing.Optional[bytes] = cache.get(cacheKey)
if not cachedValue: if not cachedValue:
@ -97,7 +97,8 @@ def getServicesPoolsCounters(
else: else:
val = pickle.loads(codecs.decode(cachedValue, 'zip')) val = pickle.loads(codecs.decode(cachedValue, 'zip'))
# return [{'stamp': since + datetime.timedelta(hours=i*10), 'value': i*i} for i in range(300)] # return [{'stamp': since + datetime.timedelta(hours=i*10), 'value': i*i*counter_type//4} for i in range(300)]
return val return val
except: except:
logger.exception('exception') logger.exception('exception')
@ -141,7 +142,7 @@ class System(Handler):
pool: typing.Optional[models.ServicePool] = None pool: typing.Optional[models.ServicePool] = None
if len(self._args) == 3: if len(self._args) == 3:
try: try:
pool = models.ServicePool.objects.get(uuid=processUuid(self._args[3])) pool = models.ServicePool.objects.get(uuid=processUuid(self._args[2]))
except Exception: except Exception:
pool = None pool = None
# If pool is None, needs admin also # If pool is None, needs admin also
@ -153,8 +154,16 @@ class System(Handler):
if self._args[0] == 'stats': if self._args[0] == 'stats':
if self._args[1] == 'assigned': if self._args[1] == 'assigned':
return getServicesPoolsCounters(pool, counters.CT_ASSIGNED) return getServicesPoolsCounters(pool, counters.CT_ASSIGNED)
if self._args[1] == 'inuse': elif self._args[1] == 'inuse':
return getServicesPoolsCounters(pool, counters.CT_INUSE) return getServicesPoolsCounters(pool, counters.CT_INUSE)
elif self._args[1] == 'cached':
return getServicesPoolsCounters(pool, counters.CT_CACHED)
elif self._args[1] == 'complete':
return {
'assigned': getServicesPoolsCounters(pool, counters.CT_ASSIGNED, since_days=7),
'inuse': getServicesPoolsCounters(pool, counters.CT_INUSE, since_days=7),
'cached': getServicesPoolsCounters(pool, counters.CT_CACHED, since_days=7),
}
raise RequestError('invalid request') raise RequestError('invalid request')