diff --git a/celerymonitor/bin/celerymond.py b/celerymonitor/bin/celerymond.py index 9e0e088..fea9bc8 100644 --- a/celerymonitor/bin/celerymond.py +++ b/celerymonitor/bin/celerymond.py @@ -7,6 +7,10 @@ Port the webserver should listen to. Default: ``8989``. +.. cmdoption:: -A, --address + + Address the webserver should listen to. Default (any). + .. cmdoption:: -f, --logfile Path to log file. If no logfile is specified, ``stderr`` is used. @@ -33,7 +37,7 @@ STARTUP_INFO_FMT = """ Configuration -> . broker -> %(conninfo)s - . webserver -> http://localhost:%(http_port)s + . webserver -> http://%(http_address)s:%(http_port)s """.strip() OPTION_LIST = ( @@ -47,11 +51,16 @@ optparse.make_option('-P', '--port', action="store", type="int", dest="http_port", default=8989, help="Port the webserver should listen to."), + optparse.make_option('-A', '--address', + action="store", type="string", dest="http_address", + default="", + help="Address the webserver should listen to. Default (any)."), ) def run_monitor(loglevel=conf.CELERYMON_LOG_LEVEL, - logfile=conf.CELERYMON_LOG_FILE, http_port=8989, **kwargs): + logfile=conf.CELERYMON_LOG_FILE, http_port=8989, + http_address='', **kwargs): """Starts the celery monitor.""" print("celerymon %s is starting." % celery.__version__) @@ -64,6 +73,7 @@ def run_monitor(loglevel=conf.CELERYMON_LOG_LEVEL, # when users sends e-mails. print(STARTUP_INFO_FMT % { "http_port": http_port, + "http_address": http_address or "localhost", "conninfo": info.format_broker_info(), }) @@ -75,7 +85,9 @@ def run_monitor(loglevel=conf.CELERYMON_LOG_LEVEL, def _run_monitor(): logger = setup_logger(loglevel, logfile) - monitor = MonitorService(logger=logger, http_port=http_port) + monitor = MonitorService(logger=logger, + http_port=http_port, + http_address=http_address) try: monitor.start() diff --git a/celerymonitor/service.py b/celerymonitor/service.py index 0c0ae13..5bd454f 100644 --- a/celerymonitor/service.py +++ b/celerymonitor/service.py @@ -5,10 +5,13 @@ class MonitorService(object): """celerymon""" - def __init__(self, logger, http_port=8989): + def __init__(self, logger, http_port=8989, + http_address=''): self.logger = logger self.http_port = http_port + self.http_address = http_address def start(self): - WebServerThread(port=self.http_port).start() + WebServerThread(port=self.http_port, + address=self.http_address).start() EventListener().start() diff --git a/celerymonitor/web.py b/celerymonitor/web.py index 8a96690..d3c333b 100644 --- a/celerymonitor/web.py +++ b/celerymonitor/web.py @@ -21,9 +21,10 @@ def __init__(self, applications, *args, **kwargs): class WebServerThread(threading.Thread): - def __init__(self, port=8989): + def __init__(self, port=8989, address=''): super(WebServerThread, self).__init__() self.port = port + self.address = address self.setDaemon(True) def run(self): @@ -32,5 +33,5 @@ def run(self): (r"", main.MAIN), ]) http_server = httpserver.HTTPServer(site) - http_server.listen(self.port) + http_server.listen(self.port, address=self.address) ioloop.IOLoop.instance().start()