Skip to content

Commit

Permalink
Add address and port arguments for monitor.
Browse files Browse the repository at this point in the history
  • Loading branch information
syamajala committed Nov 12, 2021
1 parent f52846a commit 056dd81
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ami/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,14 @@ def close(self):
self.export.close()
self.ctx.destroy()

async def run(self, loop):
async def run(self, loop, address, http_port):
asyncio.create_task(self.process_msg())
asyncio.create_task(self.start_server(loop))
asyncio.create_task(self.start_server(loop, address, http_port))
asyncio.create_task(self.monitor_tasks())

async def start_server(self, loop):
self.server = pn.serve(self.template, loop=loop, title="AMI")
async def start_server(self, loop, address, http_port):
self.server = pn.serve(self.template, address=address, port=http_port,
loop=loop, title="AMI", show=False)

async def monitor_tasks(self):
while True:
Expand Down Expand Up @@ -462,14 +463,14 @@ async def process_msg(self):
self.enabled_plots.options = list(self.plot_metadata.keys())


def run_monitor(graph_name, export_addr, view_addr):
def run_monitor(graph_name, export_addr, view_addr, address, http_port):
logger.info('Starting monitor')

graphmgr_addr = GraphMgrAddress(graph_name, export_addr, view_addr, None)

loop = tornado.ioloop.IOLoop.current()
with Monitor(graphmgr_addr) as mon:
asyncio.ensure_future(mon.run(loop))
asyncio.ensure_future(mon.run(loop, address, http_port))
loop.start()


Expand All @@ -491,6 +492,22 @@ def main():
help='base port for AMI'
)

parser.add_argument(
'-l',
'--listen-port',
type=int,
default=0,
help='http port for panel'
)

parser.add_argument(
'-a',
'--address',
type=str,
default=None,
help='address name for panel'
)

parser.add_argument(
'-g',
'--graph-name',
Expand All @@ -513,6 +530,8 @@ def main():
graph = args.graph_name
export_addr = "tcp://%s:%d" % (args.host, args.port + Ports.Export)
view_addr = "tcp://%s:%d" % (args.host, args.port + Ports.View)
http_port = args.listen_port
address = args.address

log_handlers = [logging.StreamHandler()]
if args.log_file is not None:
Expand All @@ -521,7 +540,7 @@ def main():
logging.basicConfig(format=LogConfig.Format, level=log_level, handlers=log_handlers)

try:
return run_monitor(graph, export_addr, view_addr)
return run_monitor(graph, export_addr, view_addr, address, http_port)
except KeyboardInterrupt:
logger.info("Monitor killed by user...")
return 0
Expand Down

0 comments on commit 056dd81

Please sign in to comment.