Example #1
0
def main():
	if len(sys.argv) > 2:
		from config import init_config
		init_config(sys.argv[1])
		from config import init_config
		from config import CONFIG
		from logger import CustomLogger
		cust_logger = CustomLogger(CONFIG.web_server.logger_name)
		cust_logger.add_file("log/"+CONFIG.web_server.logger_name, False)
		import app
		if bool(int(sys.argv[2])) == True:
			app.main()
Example #2
0
def main():
    if len(sys.argv) > 2:
        from config import init_config
        init_config(sys.argv[1])
        from config import init_config
        from config import CONFIG
        from logger import CustomLogger
        cust_logger = CustomLogger(CONFIG.web_server.logger_name)
        cust_logger.add_file("log/" + CONFIG.web_server.logger_name, False)
        import app
        if bool(int(sys.argv[2])) == True:
            app.main()
Example #3
0
        if (opt in ("-m", "--monitor")):
            monitor_port = int(val)
        if (opt in ("-l", "--loadBal")):
            (load_bal_ip, load_bal_port) = val.split(":")
            #send notification to load_balancer
            hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            hbSocket.sendto(
                "add_server#%s#%d#%d" %
                ("localhost", source_port, monitor_port),
                (load_bal_ip, int(load_bal_port)))
    ip = "localhost"

    db = mongoengine.connect("%s#%d" % (ip, source_port))
    #db.drop_database("%s#%d"%(ip,source_port))

    path_file_log = cust_logger.add_file("logWeb/%d" % source_port +
                                         "/logFweb")

    #we store our own condition in the database so the monitor can read it
    mib = WebServiceMIB(port=source_port,
                        status=StatusWebService.STATUS_UP,
                        log_file_path=path_file_log)
    mib.save()

    http_server = HTTPServer(WSGIContainer(app))
    http_server.listen(source_port)
    host_conf = {
        'ip': ip,
        'port': int(source_port),
        'monitor_port': int(monitor_port)
    }
    IOLoop.instance().start()
Example #4
0
    (options, args) = getopt.getopt(sys.argv[1:], "s:m:l:h",
        ["source=", "monitor=","loadBal=", "help"])
    source_port, load_bal_ip, load_bal_port, monitor_port = None, None, None, None
    for opt, val in options:
        if (opt in ("-s", "--source")):
            source_port = int(val)
        if (opt in ("-m", "--monitor")):
            monitor_port = int(val)
        if (opt in ("-l", "--loadBal")):
            (load_bal_ip, load_bal_port) = val.split(":")
            #send notification to load_balancer
            hbSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            hbSocket.sendto("add_server#%s#%d#%d"%("localhost", source_port, monitor_port), (load_bal_ip, int(load_bal_port)))
    ip = "localhost"

    db = mongoengine.connect("%s#%d"%(ip,source_port))
    #db.drop_database("%s#%d"%(ip,source_port))
    
    path_file_log = cust_logger.add_file("logWeb/%d"%source_port+"/logFweb")

    #we store our own condition in the database so the monitor can read it
    mib = WebServiceMIB(port = source_port, status = StatusWebService.STATUS_UP , log_file_path =  path_file_log )
    mib.save()


    http_server = HTTPServer(WSGIContainer(app))
    http_server.listen(source_port)
    host_conf = {'ip': ip, 'port':int(source_port), 'monitor_port':int(monitor_port)}
    IOLoop.instance().start()

    #app.run(host="0.0.0.0", port=source_port, debug=True, use_reloader=False)
Example #5
0
    (options, args) = getopt.getopt(sys.argv[1:], "s:m:l:h",
        ["source=", "monitor=","loadBal=", "help"])
    web_listen_port, load_bal_ip, load_bal_port, monitor_listen_port = None, None, None, None
    for opt, val in options:
        if (opt in ("-s", "--source")):
            web_listen_port = int(val)
        if (opt in ("-m", "--monitor")):
            cust_logger.info("monitor : %d"%int(val))
            monitor_listen_port = int(val)
        if (opt in ("-l", "--loadBal")):
            (load_bal_ip, load_bal_port) = val.split(":")
    ip = "localhost"

    #lock for logs reading
    lock = threading.Lock()

    path_file_log = cust_logger.add_file("logWeb/monitor%d"%web_listen_port+"/logFweb")
    db = mongoengine.connect("%s#%d"%(ip,web_listen_port))
    #db.drop_database("%s#%d"%(ip,web_listen_port))


    heartbeat_thread = threading.Thread(name='heartbeat', target=heartbeatDaemon, args=(web_listen_port,monitor_listen_port,monitors)) #Care about lists as arguments, if not in [] then list is split
    heartbeat_thread.setDaemon(True)
    heartbeat_thread.start()

    last_excpt_daemon = threading.Thread(name='last_exception', target=lastExceptionDaemon, args=(ip,web_listen_port,monitors)) #Care about lists as arguments, if not in [] then list is split
    last_excpt_daemon.setDaemon(True)
    last_excpt_daemon.start()

    reactor.listenUDP(monitor_listen_port, UdpProtocol(lock,ip,web_listen_port))
    reactor.run()
Example #6
0
                config.load_bal_monitor.ip, config.load_bal_monitor.port_udp):
            cust_logger.info("received list servers")
            _, list_json = data.split('#')
            heartbeats = [{
                (server['ip'], server['port'], server['monitor_port']):
                time.time()
            } for server in json.loads(list_json)]


################# MAIN ######################

if __name__ == "__main__":
    #if len(sys.argv) > 1:
    #    config = GlobalConfig.from_json(sys.argv[1])

    path_file_log = cust_logger.add_file("logMonitor/logFmonitor")

    db = mongoengine.connect(config.health_monitor.mongo_db)
    db.drop_database(config.health_monitor.mongo_db)

    heartbeats = Heartbeats()
    heartbeat_thread = threading.Thread(name='hb_daemon',
                                        target=heartBeatDaemon,
                                        args=([heartbeats]))
    heartbeat_thread.setDaemon(True)
    heartbeat_thread.start()

    check_daemon = threading.Thread(name='checks_daemon',
                                    target=checksDaemon,
                                    args=([heartbeats]))
    check_daemon.setDaemon(True)
Example #7
0
            ws.save()
        #load_balancer sends the list of servers
        elif data.startswith("list_servers") and (host, port) == (config.load_bal_monitor.ip, config.load_bal_monitor.port_udp):
            cust_logger.info("received list servers")
            _,list_json = data.split('#')
            heartbeats = [ {(server['ip'], server['port'], server['monitor_port']) : time.time()} for server in json.loads(list_json)]


################# MAIN ######################

if __name__ == "__main__":
    #if len(sys.argv) > 1: 
    #    config = GlobalConfig.from_json(sys.argv[1])


    path_file_log = cust_logger.add_file("logMonitor/logFmonitor")

    db = mongoengine.connect(config.health_monitor.mongo_db)
    db.drop_database(config.health_monitor.mongo_db)

    heartbeats = Heartbeats()
    heartbeat_thread = threading.Thread(name='hb_daemon', target=heartBeatDaemon, args=([heartbeats]))
    heartbeat_thread.setDaemon(True)
    heartbeat_thread.start()

    check_daemon = threading.Thread(name='checks_daemon', target=checksDaemon, args=([heartbeats]))
    check_daemon.setDaemon(True)
    check_daemon.start()


    #log_daemon = threading.Thread(name='checks_daemon', target=checksDaemon, args=([heartbeats]))
Example #8
0
                           ["source=", "monitor=", "loadBal=", "help"])
    web_listen_port, load_bal_ip, load_bal_port, monitor_listen_port = None, None, None, None
    for opt, val in options:
        if (opt in ("-s", "--source")):
            web_listen_port = int(val)
        if (opt in ("-m", "--monitor")):
            cust_logger.info("monitor : %d" % int(val))
            monitor_listen_port = int(val)
        if (opt in ("-l", "--loadBal")):
            (load_bal_ip, load_bal_port) = val.split(":")
    ip = "localhost"

    #lock for logs reading
    lock = threading.Lock()

    path_file_log = cust_logger.add_file("logWeb/monitor%d" % web_listen_port +
                                         "/logFweb")
    db = mongoengine.connect("%s#%d" % (ip, web_listen_port))
    #db.drop_database("%s#%d"%(ip,web_listen_port))

    heartbeat_thread = threading.Thread(
        name='heartbeat',
        target=heartbeatDaemon,
        args=(web_listen_port, monitor_listen_port, monitors)
    )  #Care about lists as arguments, if not in [] then list is split
    heartbeat_thread.setDaemon(True)
    heartbeat_thread.start()

    last_excpt_daemon = threading.Thread(
        name='last_exception',
        target=lastExceptionDaemon,
        args=(ip, web_listen_port, monitors)