forked from shaba/openuds
added auth stats to stats collector & stats manager
This commit is contained in:
parent
e1d66db7ea
commit
3e8757e908
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (c) 2013 Virtual Cable S.L.
|
||||
# Copyright (c) 2013-202 Virtual Cable S.L.U.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification,
|
||||
@ -43,8 +43,8 @@ logger = logging.getLogger(__name__)
|
||||
# Posible counters, note that not all are used by every posible type
|
||||
# FIRST_COUNTER_TYPE, LAST_COUNTER_TYPE are just a placeholder for sanity checks
|
||||
(
|
||||
CT_LOAD, CT_STORAGE, CT_ASSIGNED, CT_INUSE,
|
||||
) = range(4)
|
||||
CT_LOAD, CT_STORAGE, CT_ASSIGNED, CT_INUSE, CT_AUTH_USERS, CT_AUTH_USERS_WITH_SERVICES, CT_AUTH_SERVICES
|
||||
) = range(7)
|
||||
|
||||
__caRead: typing.Dict = {}
|
||||
__caWrite: typing.Dict = {}
|
||||
@ -70,7 +70,7 @@ def addCounter(obj: typing.Any, counterType: int, counterValue: int, stamp: typi
|
||||
return statsManager().addCounter(__transDict[type(obj)], obj.id, counterType, counterValue, stamp)
|
||||
|
||||
|
||||
def getCounters(obj: typing.Any, counterType: int, **kwargs):
|
||||
def getCounters(obj: typing.Any, counterType: int, **kwargs) -> typing.Generator[typing.Tuple[datetime.datetime, int], None, None]:
|
||||
"""
|
||||
Get counters
|
||||
|
||||
@ -116,24 +116,27 @@ def getCounters(obj: typing.Any, counterType: int, **kwargs):
|
||||
yield val
|
||||
|
||||
|
||||
def getCounterTitle(counterType):
|
||||
def getCounterTitle(counterType) -> str:
|
||||
return __typeTitles.get(counterType, '').title()
|
||||
|
||||
|
||||
# Data initialization
|
||||
def _initializeData():
|
||||
def _initializeData() -> None:
|
||||
"""
|
||||
Initializes dictionaries.
|
||||
|
||||
Hides data from global var space
|
||||
"""
|
||||
from uds.models import Provider, Service, ServicePool
|
||||
from uds.models import Provider, Service, ServicePool, Authenticator
|
||||
|
||||
__caWrite.update({
|
||||
CT_LOAD: (Provider,),
|
||||
CT_STORAGE: (Service,),
|
||||
CT_ASSIGNED: (ServicePool,),
|
||||
CT_INUSE: (ServicePool,),
|
||||
CT_AUTH_USERS: (Authenticator,),
|
||||
CT_AUTH_SERVICES: (Authenticator,),
|
||||
CT_AUTH_USERS_WITH_SERVICES: (Authenticator,),
|
||||
})
|
||||
|
||||
# OBtain ids from variups type of object to retrieve stats
|
||||
@ -167,6 +170,11 @@ def _initializeData():
|
||||
ServicePool: {
|
||||
CT_ASSIGNED: get_Id,
|
||||
CT_INUSE: get_Id
|
||||
},
|
||||
Authenticator: {
|
||||
CT_AUTH_USERS: get_Id,
|
||||
CT_AUTH_SERVICES: get_Id,
|
||||
CT_AUTH_USERS_WITH_SERVICES: get_Id,
|
||||
}
|
||||
})
|
||||
|
||||
@ -186,14 +194,15 @@ def _initializeData():
|
||||
return res
|
||||
return ()
|
||||
|
||||
OT_PROVIDER, OT_SERVICE, OT_DEPLOYED = range(3)
|
||||
OT_PROVIDER, OT_SERVICE, OT_DEPLOYED, OT_AUTHENTICATOR = range(4)
|
||||
|
||||
# Dict to convert objects to owner types
|
||||
# Dict for translations
|
||||
__transDict.update({
|
||||
ServicePool: OT_DEPLOYED,
|
||||
Service: OT_SERVICE,
|
||||
Provider: OT_PROVIDER
|
||||
Provider: OT_PROVIDER,
|
||||
Authenticator: OT_AUTHENTICATOR,
|
||||
})
|
||||
|
||||
# Titles of types
|
||||
@ -201,8 +210,10 @@ def _initializeData():
|
||||
CT_ASSIGNED: _('Assigned'),
|
||||
CT_INUSE: _('In use'),
|
||||
CT_LOAD: _('Load'),
|
||||
CT_STORAGE: _('Storage')
|
||||
CT_STORAGE: _('Storage'),
|
||||
CT_AUTH_USERS: _('Users'),
|
||||
CT_AUTH_USERS_WITH_SERVICES: _('Users with services'),
|
||||
CT_AUTH_SERVICES: _('User Services'),
|
||||
})
|
||||
|
||||
|
||||
_initializeData()
|
||||
|
@ -32,7 +32,7 @@
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from uds.models import ServicePool
|
||||
from uds.models import ServicePool, Authenticator
|
||||
from uds.core.util.state import State
|
||||
from uds.core.util.stats import counters
|
||||
from uds.core.managers import statsManager
|
||||
@ -63,6 +63,13 @@ class DeployedServiceStatsCollector(Job):
|
||||
except Exception:
|
||||
logger.exception('Getting counters for service pool %s', servicePool.name)
|
||||
|
||||
for auth in Authenticator.objects.all():
|
||||
fltr = auth.users.filter(userServices__isnull=False).exclude(userServices__state__in=State.INFO_STATES)
|
||||
users = auth.users.all().count()
|
||||
users_with_service = fltr.distinct().count()
|
||||
number_assigned_services = fltr.count()
|
||||
print(auth.id, users, users_with_service, number_assigned_services)
|
||||
|
||||
logger.debug('Done Deployed service stats collector')
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user