Skip to content

Commit

Permalink
celerymon: New cmdline option: -A|--address: IP/address to bind the w…
Browse files Browse the repository at this point in the history
…ebserver to.
  • Loading branch information
Ask Solem committed Sep 10, 2010
1 parent 522ecc4 commit 3ddcc75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
18 changes: 15 additions & 3 deletions celerymonitor/bin/celerymond.py
Expand Up @@ -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.
Expand All @@ -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 = (
Expand All @@ -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__)
Expand All @@ -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(),
})

Expand All @@ -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()
Expand Down
7 changes: 5 additions & 2 deletions celerymonitor/service.py
Expand Up @@ -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()
5 changes: 3 additions & 2 deletions celerymonitor/web.py
Expand Up @@ -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):
Expand All @@ -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()

0 comments on commit 3ddcc75

Please sign in to comment.