當前位置: 首頁>>代碼示例>>Python>>正文


Python Collector.report方法代碼示例

本文整理匯總了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()
開發者ID:kdevakum,項目名稱:alto-on-unis,代碼行數:83,代碼來源:probe_runner.py


注:本文中的collector.Collector.report方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。