def wrapper(self, *args, **kwargs): if not hasattr(self.__class__, '_stats_latency'): self.__class__._stats_latency = scales.NamedPmfDictStat('latency') if isinstance(self, RequestHandler): original_on_finish = self.on_finish def latency_on_finish(*args, **kwargs): latency = time.time() - start self._stats_latency[fn.__name__].addValue(latency) original_on_finish(*args, **kwargs) self.on_finish = latency_on_finish scales.init(self, self.request.path) start = time.time() return fn(self, *args, **kwargs) else: def done_callback(*args, **kwargs): latency = time.time() - start self._stats_latency[fn.__name__].addValue(latency) scales.init(self, '/'.join(['_internal', self.__module__, self.__class__.__name__])) start = time.time() result = fn(self, *args, **kwargs) if isinstance(result, Future): result.add_done_callback(done_callback) else: done_callback() return result
def __init__(self, uri, config, masterGraph, mqtt, influx): self.uri = uri self.config = config self.masterGraph = masterGraph self.mqtt = mqtt self.influx = influx self.mqttTopic = self.topicFromConfig(self.config) statPath = '/subscribed_topic/' + self.mqttTopic.decode( 'ascii').replace('/', '|') scales.init(self, statPath) self._mqttStats = scales.collection(statPath + '/incoming', scales.IntStat('count'), scales.RecentFpsStat('fps')) rawBytes = self.subscribeMqtt() rawBytes = rx.operators.do_action(self.countIncomingMessage)(rawBytes) parsed = self.getParser()(rawBytes) g = self.config for conv in g.items(g.value(self.uri, ROOM['conversions'])): parsed = self.conversionStep(conv)(parsed) outputQuadsSets = rx.combine_latest(*[ self.makeQuads(parsed, plan) for plan in g.objects(self.uri, ROOM['graphStatements']) ]) outputQuadsSets.subscribe_(self.updateQuads)
def __init__(self, graph, uri, pi, pinNumber): self.graph, self.uri, self.pi = graph, uri, pi self.pinNumber = pinNumber scales.init(self, self.__class__.__name__) self.stats = scales.collection(self.__class__.__name__, scales.PmfStat('poll'), scales.PmfStat('output'), ) self.hostStateInit()
def __init__(self, session, request_spec): self.log = logging.getLogger() self.log.setLevel(logging.DEBUG) self.log.addHandler(self.console) self.uuid = uuid4() # unit identifier scales.init(self, '/request-machine/%s' % self.uuid) # self.register_child_stat('/request-machine/%s' % self.uuid) self.session = session # request http session self.request_spec = request_spec # request spec with spec of call self.timings = RequestTimings(request_spec) self.state = RequestMachineStates.Idle # current state self._seed_session()
def __init__(self, name, parent_logger=None): scales.init(self, '/service-manager') BaseService.__init__(self, name, parent_logger=parent_logger) self.service_directory = {} # the directory service_directory = DirectoryService(self.service_directory, parent_logger=self.log) # wrapper # BaseService declares an interface to the directory proxy # we continue to do this (just like any other service uses # the directory proxy. It is a bit recursive, but done for # completeness sake. This is just another reference # designated by the BaseService parent class. self.set_directory_service_proxy(service_directory)
def wrapper(self, *args, **kwargs): attr_name = '_stats_metered_%s' % fn.__name__ if not hasattr(self.__class__, '_stats_metered'): setattr(self.__class__, attr_name, MeterStat(fn.__name__)) if isinstance(self, RequestHandler): scales.init(self, self.request.path) else: scales.init(self, '/'.join(['_internal', self.__module__, self.__class__.__name__])) getattr(self, attr_name).mark() return fn(self, *args, **kwargs)
def __init__(self, app): """ :param app: :type app: flask.Flask.app :return: """ scales.init(self, '/') self.app = app self._config = load_configuration() # plugging routes self.app.add_url_rule( '/v1.0/hello/<name>', 'hello_name', self.hello_name, methods=['GET'] )
def __init__(self, name="base-service", directory_proxy=None, parent_logger=None, enable_service_recovery=False): """ uuid - a uuid4 value for the service alias - a colloquial alias unique_name - a name which includes an easier to remember alias with the uuid :param name: :param directory_proxy: :param parent_logger: :return: """ ErrorHandlerMixin.__init__(self) # time indexes self.time_starting_index = None # time index when service was 'starting' self.time_started_index = None # time index when service was started self.uuid = uuid4() # unique uuid self.alias = name # name, may collide self.unique_name = '%s/%s' % ( self.alias, self.uuid ) # a unique name for this service, will always be unique scales.init(self, self.unique_name) if parent_logger is None: # no parent, use fq name self.lineage = "%s" % self.unique_name else: parent_name = parent_logger._context["name"] self.lineage = "%s/%s" % (parent_name, self.unique_name) self.log = Logger.get_logger(self.lineage) self.greenlet = None self._service_state = None self.set_state(BaseStates.Idle) # directory service proxy self.directory_proxy = directory_proxy # service recovery option self.enable_service_recovery = enable_service_recovery self.log.debug("Initialized.")
def __init__(self, name="base-service", directory_proxy=None): self.uuid = uuid4() self.unique_name = "/%s/%s" % (name, self.uuid) scales.init(self, self.unique_name) # self.log = logging.getLogger(self.unique_name) # self.log.setLevel(logging.DEBUG) # self.log.addHandler(self.console) self.log = Logger.get_logger(self.unique_name) print "%s - Init" % name self.name = name self.greenlet = None self._service_state = BaseStates.Idle # directory service proxy self._directory_proxy = directory_proxy
def __init__(self, name="base-service", directory_proxy=None): self.uuid = uuid4() self.unique_name = '/%s/%s' % (name, self.uuid) scales.init(self, self.unique_name) # self.log = logging.getLogger(self.unique_name) # self.log.setLevel(logging.DEBUG) # self.log.addHandler(self.console) self.log = Logger.get_logger(self.unique_name) print "%s - Init" % name self.name = name self.greenlet = None self._service_state = BaseStates.Idle # directory service proxy self._directory_proxy = directory_proxy
def __init__(self, name="base-service", directory_proxy=None, parent_logger=None, enable_service_recovery=False): """ uuid - a uuid4 value for the service alias - a colloquial alias unique_name - a name which includes an easier to remember alias with the uuid :param name: :param directory_proxy: :param parent_logger: :return: """ ErrorHandlerMixin.__init__(self) # time indexes self.time_starting_index = None # time index when service was 'starting' self.time_started_index = None # time index when service was started self.uuid = uuid4() # unique uuid self.alias = name # name, may collide self.unique_name = '%s/%s' % (self.alias, self.uuid) # a unique name for this service, will always be unique scales.init(self, self.unique_name) if parent_logger is None: # no parent, use fq name self.lineage = "%s" % self.unique_name else: parent_name = parent_logger._context["name"] self.lineage = "%s/%s" % (parent_name, self.unique_name) self.log = Logger.get_logger(self.lineage) self.greenlet = None self._service_state = None self.set_state(BaseStates.Idle) # directory service proxy self.directory_proxy = directory_proxy # service recovery option self.enable_service_recovery = enable_service_recovery self.log.debug("Initialized.")
def __init__(self, config): """ :param config: :type config: application.common.tools.Map :return: """ scales.init(self, '/backend/users') self._connection = None self._db_name = config.mongo.db_name replica_set = config.mongo.replicaset_name if 'replicaset_name' in config.mongo else None self._connection = pymongo.MongoClient( config.mongo.uri, replicaSet=replica_set, maxPoolSize=config.mongo.max_pool_size, waitQueueMultiple=config.mongo.wait_queue_multiple, waitQueueTimeoutMS=config.mongo.wait_queue_timeout_ms, tz_aware=True) self._db = self._connection[self._db_name] self._users = self._db[config.mongo.user_collection]
def __init__(self, config): """ :param config: :type config: application.common.tools.Map :return: """ scales.init(self, '/backend/users') self._connection = None self._db_name = config.mongo.db_name replica_set = config.mongo.replicaset_name if 'replicaset_name' in config.mongo else None self._connection = pymongo.MongoClient( config.mongo.uri, replicaSet=replica_set, maxPoolSize=config.mongo.max_pool_size, waitQueueMultiple=config.mongo.wait_queue_multiple, waitQueueTimeoutMS=config.mongo.wait_queue_timeout_ms, tz_aware=True ) self._db = self._connection[self._db_name] self._medias = self._db[config.mongo.media_collection]
def __init__(self, name): scales.init(self, '/service-manager') BaseService.__init__(self, name) self._directory = {} self.started_services = Queue() self._directory_service_proxy = DirectoryService(self._directory)
def __init__(self): super(ProfileView, self).__init__() scales.init(self, '/api/profile') self._users_backend = UsersBackend(config)
def __init__(self): scales.init(self, '/feed_updates')
def __init__(self): scales.init(self) self.dynamicStat = lambda: DynamicRoot.value
def __init__(self): scales.init(self, 'B')
def __init__(self, session): scales.init(self, '/cassandra') # each instance will be registered with a session, and receive a callback for each request generated session.add_request_init_listener(self.on_request)
def __init__(self, id): scales.init(self, '/goals/' + id)
def __init__(self, session, throw_on_success=False, throw_on_fail=False): scales.init(self, '/request') # each instance will be registered with a session, and receive a callback for each request generated session.add_request_init_listener(self.on_request) self.throw_on_fail = throw_on_fail self.throw_on_success = throw_on_success
def __init__(self): super(MediasView, self).__init__() scales.init(self, '/api/medias') self._media_backend = MediasBackend(config) self._image_processor = ImageProcessorService(config) self._video_processor = VideoProcessorService(config)
def __init__(self): super(UsersView, self).__init__() scales.init(self, '/api/home')
def __init__(self): super(ProfileView, self).__init__() scales.init(self, "/api/profile") self._users_backend = UsersBackend(config)
def __init__(self): super(RegisterView, self).__init__() scales.init(self, "/api/register")
def __init__(self): super(HomeView, self).__init__() scales.init(self, '/api/home')
def __init__(self): super(RegisterView, self).__init__() scales.init(self, '/api/register')
def __init__(self): scales.init(self)
def __init__(self): scales.init(self, 'path/to/A')
def __init__(self): scales.init(self, 'Root')
def __init__(self): super(UsersView, self).__init__() scales.init(self, "/api/home")