12from argparse
import ArgumentParser
13from zmq_daq.utils import get_monitor_table, normalize_addresses, write_monitoring, show_monitoring
17if __name__ ==
'__main__':
18 parser = ArgumentParser(description=
"Monitor running ZMQ HLT applications with the given addresses.")
22 help=
"Monitor the given addresses. " +
23 "Valid input formats are 'tcp://<host>:<port>', '<host>:<port>' or just '<port>' in which case localhost is assumed.")
27 help=
"Additional to monitoring, also send out a START signal to all monitored processes.")
31 help=
"Additional to monitoring, also send out a STOP signal to all monitored processes.")
35 help=
"Send out a TERMINATE signal to all monitored processes and do not monitor afterwards.")
40 help=
"By default, some information are omitted. With this flag, all details are shown (can be very long output).")
41 parser.add_argument(
"--watch", action=
"store_true", help=
"Enter watch mode, where the script is called every 1 second.")
42 parser.add_argument(
"--dat", help=
"Write out the results of the monitoring periodically into a dat file. " +
43 "If not combined with --watch, the output will not be shown.")
45 args = parser.parse_args()
47 addresses = normalize_addresses(args.addresses)
51 ctx.setsockopt(zmq.LINGER, 0)
52 sockets = {address: ctx.socket(zmq.DEALER)
for address
in addresses}
54 for address, socket
in sockets.items():
55 socket.connect(address)
58 for socket
in sockets.values():
60 socket.send_multipart([b
"n", b
"", b
""])
62 socket.send_multipart([b
"l", b
"", b
""])
64 socket.send_multipart([b
"x", b
"", b
""])
69 if not args.watch
and not args.dat:
70 df = get_monitor_table(sockets, show_detail=args.show_detail)
76 f = open(args.dat,
"wb")
79 df = get_monitor_table(sockets, show_detail=args.show_detail)
81 show_monitoring(df, clear=
True)
84 write_monitoring(df, f)
87 except KeyboardInterrupt: