예제 #1
0
def check_monitor_status():
	context = zmq.Context()
	poller  = zmq.Poller()

	current_monitor_index = 0

	heartbeat = context.socket(zmq.REQ)
	heartbeat.connect(heartbeat_servers[current_monitor_index])
	poller.register(heartbeat, zmq.POLLIN)

	while True:
		# send heartbeat signal every x seconds
		heartbeat.send("")

		socks = dict(poller.poll(1 * 1000))

		if socks.get(heartbeat) == zmq.POLLIN:
			heartbeat.recv()
		else:
			print "switch monitor server"
			current_monitor_index = (current_monitor_index+1) % len(monitor_servers)
			
			poller.unregister(heartbeat)
			heartbeat.setsockopt(zmq.LINGER, 0)
			heartbeat.close()
			

			heartbeat = context.socket(zmq.REQ)
			heartbeat.connect(heartbeat_servers[current_monitor_index])
			poller.register(heartbeat, zmq.POLLIN)

			fetch_remot_monitor.change_server_addr( monitor_servers[current_monitor_index] )

		time.sleep(1)
예제 #2
0
def main():
	fetch_remot_monitor.change_server_addr(monitor_servers[0])

	thread = threading.Thread(target=check_monitor_status, args=())
	thread.start()

	tornado.options.parse_command_line()
	http_server = tornado.httpserver.HTTPServer(Application())
	http_server.listen(options.port)
	tornado.ioloop.IOLoop.instance().start()