本文整理汇总了Python中collector.Collector.report方法的典型用法代码示例。如果您正苦于以下问题:Python Collector.report方法的具体用法?Python Collector.report怎么用?Python Collector.report使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类collector.Collector
的用法示例。
在下文中一共展示了Collector.report方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: subprocess
# 需要导入模块: from collector import Collector [as 别名]
# 或者: from collector.Collector import report [as 别名]
class ProbeRunner:
'''
Class to handle a single probe. Creates the scheduler, collector,
and probe module associated with this probe. The run method should
be called as a subprocess (by arbiter) and passed a
connection object so that it can receive a "stop" if necessary.
'''
def __init__(self, service, measurement):
self.measurement = measurement
self.config = measurement['configuration']
self.service = service.config
self.probe_defaults = service.probe_defaults
self.setup()
def run(self, conn, ip):
if conn.poll() and conn.recv() == "stop":
self._cleanup()
exit()
self.collect(ip)
# for nextt in self.scheduler:
# print "** NRSXTT **** " + str(nextt)
# logger.debug("run", msg="got time from scheduler", time=nextt)
# if conn.poll():
# if conn.recv() == "stop":
# self._cleanup()
# break
# time.sleep(max(nextt-time.time(), 0))
# self.collect()
def collect(self, ip):
logger.debug('collect', name=self.config['name'], module=self.config["probe_module"])
time.sleep(5)
data = self.probe.get_data(ip)
# print "====================data in collect: " + str(data)
# print "\n **************** " + str(rtt_list)
if len(data) == 0:
data = self.probe.get_data(ip)
ts = time.time()
if data:
if isinstance(data, list):
for d in data:
self.collector.insert(self._normalize(d), ts)
else:
self.collector.insert(self._normalize(data), ts)
return rtt_list
def _normalize(self, data):
if isinstance(data.itervalues().next(), dict):
return data
subject = self.service["runningOn"]["href"]
return dict({subject: data})
def setup(self):
config = self.config
logger.info('setup', name=config["name"], module=config["probe_module"], config=pprint.pformat(config))
# logger.warn('NODE: ' + HOSTNAME, name=config["name"], module=config["probe_module"], config=pprint.pformat(config))
probe_mod = blipp_import(config["probe_module"])
self.probe = probe_mod.Probe(self.service, self.measurement)
if "." in config["collection_schedule"]:
sched_file, sched_name = config["collection_schedule"].split('.')
else:
sched_file, sched_name = "builtins", config["collection_schedule"]
logger.info('setup', sched_file=sched_file, sched_name=sched_name)
logger.warn('NODE: ' + HOSTNAME, sched_file=sched_file, sched_name=sched_name)
self.scheduler = blipp_import("schedules." + sched_file, fromlist=[1]).__getattribute__(sched_name)
self.scheduler = self.scheduler(self.service, self.measurement)
self.collector = Collector(self.service, self.measurement)
def _cleanup(self):
'''
Used for graceful exit. Clear any outstanding unreported data.
'''
logger.debug('_cleanup', name=self.config['name'])
self.collector.report()