本文整理汇总了Python中emitter.Emitter.join方法的典型用法代码示例。如果您正苦于以下问题:Python Emitter.join方法的具体用法?Python Emitter.join怎么用?Python Emitter.join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类emitter.Emitter
的用法示例。
在下文中一共展示了Emitter.join方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: from emitter import Emitter [as 别名]
# 或者: from emitter.Emitter import join [as 别名]
class Controller(threading.Thread):
def __init__(self, config, stop_handler):
# Process initialization code
threading.Thread.__init__(self)
logger.debug('Initializing Controller thread.')
self.lock = threading.Lock()
self.config = config
self.metrics_config = config.getMetricGroupConfig()
self.events_cache = []
hostinfo = HostInfo(config)
self.application_metric_map = ApplicationMetricMap(hostinfo.get_hostname(),
hostinfo.get_ip_address())
self.event_queue = Queue(config.get_max_queue_size())
self.metric_collector = MetricsCollector(self.event_queue, self.application_metric_map, hostinfo)
self.server_url = config.get_server_address()
self.sleep_interval = config.get_collector_sleep_interval()
self._stop_handler = stop_handler
self.initialize_events_cache()
self.emitter = Emitter(self.config, self.application_metric_map, stop_handler)
self._t = None
def run(self):
logger.info('Running Controller thread: %s' % threading.currentThread().getName())
self.start_emitter()
# Wake every 5 seconds to push events to the queue
while True:
if (self.event_queue.full()):
logger.warn('Event Queue full!! Suspending further collections.')
else:
self.enqueque_events()
pass
#Wait for the service stop event instead of sleeping blindly
if 0 == self._stop_handler.wait(self.sleep_interval):
logger.info('Shutting down Controller thread')
break
if not self._t is None:
self._t.cancel()
self._t.join(5)
#The emitter thread should have stopped by now, just ensure it has shut down properly
self.emitter.join(5)
pass
# TODO: Optimize to not use Timer class and use the Queue instead
def enqueque_events(self):
# Queue events for up to a minute
for event in self.events_cache:
self._t = Timer(event.get_collect_interval(), self.metric_collector.process_event, args=(event,))
self._t.start()
pass
def initialize_events_cache(self):
self.events_cache = []
try:
host_metrics_groups = self.metrics_config['host_metric_groups']
process_metrics_groups = self.metrics_config['process_metric_groups']
except KeyError, ke:
logger.warn('Error loading metric groups.')
raise ke
pass
if host_metrics_groups:
for name, properties in host_metrics_groups.iteritems():
event = HostMetricCollectEvent(properties, name)
logger.info('Adding event to cache, {0} : {1}'.format(name, properties))
self.events_cache.append(event)
pass
pass
if process_metrics_groups:
for name, properties in process_metrics_groups.iteritems():
event = ProcessMetricCollectEvent(properties, name)
logger.info('Adding event to cache, {0} : {1}'.format(name, properties))
#self.events_cache.append(event)
pass
pass