diff options
Diffstat (limited to 'src/console/trex_status.py')
-rwxr-xr-x | src/console/trex_status.py | 183 |
1 files changed, 51 insertions, 132 deletions
diff --git a/src/console/trex_status.py b/src/console/trex_status.py index 20d70534..8ee669b5 100755 --- a/src/console/trex_status.py +++ b/src/console/trex_status.py @@ -85,6 +85,7 @@ class TrexStatus(): return win, panel1 + # static info panel def update_info (self): if self.server_status == None: return @@ -99,106 +100,12 @@ class TrexStatus(): self.server_status["general"]["build_date"] + " @ " + self.server_status["general"]["build_time"] + " by " + self.server_status["general"]["version_user"])) self.info_panel.getwin().addstr(6, 2, "{:<30} {:30}".format("Server Uptime:", self.server_status["general"]["uptime"])) - #self.ft_panel.clear() - - #ft_section_y = 3 - #self.ft_panel.getwin().addstr(ft_section_y, 2,"General Info:", curses.A_UNDERLINE) - - #self.ft_panel.getwin().addstr(ft_section_y, 2, "{:<30} {:<30,}".format("Total Flows Opened:", ft_stats["total-opened-flows"])) - #ft_section_y = ft_section_y + 1 - #self.ft_panel.getwin().addstr(ft_section_y, 2, "{:<30} {:<30,}".format("Total Flows Closed:", ft_stats["total-closed-flows"])) - #ft_section_y = ft_section_y + 1 - #self.ft_panel.getwin().addstr(ft_section_y, 2, "{:<30} {:<30,}".format("Current Active Flows:", ft_stats["active-flows"])) - #ft_section_y = ft_section_y + 1 - #self.ft_panel.getwin().addstr(ft_section_y, 2, "{:<30} {:<30,}".format("Flow Allocation Errors:", ft_stats["allocation_err"])) + # general stats def update_general (self, gen_stats): + pass - if not gen_stats: - return - - transport_info_section_y = 3 - general_info_section_y = int(self.cls_panel.h * 0.5) - - self.general_panel.clear() - - # transport layer info - self.general_panel.getwin().addstr(transport_info_section_y, 2, "{:<30} {:^10} {:^5} {:^10}".format("Total Tx Rate:", - float_to_human_readable(gen_stats["total-rx-bps"]), - "/", - float_to_human_readable(gen_stats["total-rx-pps"], suffix = "pps"))) - transport_info_section_y += 2 - - - self.general_panel.getwin().addstr(transport_info_section_y, 2, "{:<30} {:^6.2f} %".format("DP Core Util.:", gen_stats["cpu-util"])); - - transport_info_section_y += 2 - - for i in range(1, 3): - self.general_panel.getwin().addstr(transport_info_section_y, 2, "{:<30} {:^10} {:^5} {:^10}".format("Port {0} Rx:".format(i), - float_to_human_readable(gen_stats["port " + str(i)]["total-rx-bps"]), - "/", - float_to_human_readable(gen_stats["port " + str(i)]["total-rx-pps"], suffix = "pps"))) - transport_info_section_y += 1 - - - self.general_panel.getwin().addstr(general_info_section_y, 2,"General Info:", curses.A_UNDERLINE) - general_info_section_y = general_info_section_y + 2 - - self.general_panel.getwin().addstr(general_info_section_y, 2, "{:<30} {:<30}".format("VNBAR Main Process PID:", os.getppid())) - general_info_section_y = general_info_section_y + 1 - self.general_panel.getwin().addstr(general_info_section_y, 2, "{:<30} {:<30}".format("ZMQ client online at:", vnbar_ipc.VnbarIpc.get_zmq_transport_name())) - - - # v2 - def update_cls (self, pd_stats): - if not pd_stats: - return - - self.cls_panel.clear() - - section_start = 3 - section_size = (self.cls_panel.h / 2) - 5 - - for port_name, pd in sorted(pd_stats.iteritems()): - if pd == None: - continue - - # sort by bandwidth - pd = collections.OrderedDict(sorted(pd.items(), key=operator.itemgetter(1), reverse = True)) - - # restart the line index - line_index = 0 - - # headline - self.cls_panel.getwin().addstr(section_start + line_index, 2, "{0}:".format(port_name), curses.A_BOLD | curses.A_UNDERLINE) - line_index += 1 - - cls_str = "{:^45} {:^20} {:^20} {:^20}".format("Protocol Name", "Byte Count", "Packet Count", "B/W Perc.") - self.cls_panel.getwin().addstr(section_start + line_index, 2, cls_str) - line_index += 2 - - # protocols - proto_index = 0 - proto_count = len(pd) - - total_bandwidth = sum([i['bytes'] for i in pd.values()]) - - for proto_name, cnts in pd.iteritems(): - proto_str = "{:<45} {:^20,} {:^20,} {:^20}".format(proto_name, cnts['bytes'], cnts['pkts'], percentage(cnts['bytes'], total_bandwidth) ) - proto_index = proto_index + 1 - - if line_index > section_size: - self.cls_panel.getwin().addstr(section_start + line_index, 2, "<...{0} More...>".format(proto_count - proto_index), (curses.A_DIM if ((line_index % 2) == 0) else curses.A_BOLD)) - break - - self.cls_panel.getwin().addstr(section_start + line_index, 2, proto_str, (curses.A_DIM if ((line_index % 2) == 0) else curses.A_BOLD)) - - line_index += 1 - - section_start = section_start + section_size + 3 - - + # control panel def update_control (self): self.control_panel.clear() @@ -214,17 +121,7 @@ class TrexStatus(): self.control_panel.getwin().addstr(index, 2, l) index += 1 - def run (self): - try: - curses.curs_set(0) - except: - pass - - curses.use_default_colors() - self.stdscr.nodelay(1) - curses.nonl() - curses.noecho() - + def generate_layout (self): self.max_y = self.stdscr.getmaxyx()[0] self.max_x = self.stdscr.getmaxyx()[1] @@ -239,32 +136,54 @@ class TrexStatus(): panel.update_panels(); self.stdscr.refresh() + def wait_for_key_input (self): + ch = self.stdscr.getch() + + if (ch != curses.ERR): + # stop/start status + if (ch == ord('f')): + self.update_active = not self.update_active + self.add_log_event("Update continued" if self.update_active else "Update stopped") + + elif (ch == ord('p')): + self.add_log_event("Pinging RPC server") + rc, msg = self.rpc_client.ping_rpc_server() + if rc: + self.add_log_event("Server replied: '{0}'".format(msg)) + else: + self.add_log_event("Failed to get reply") + + # c - clear stats + elif (ch == ord('c')): + self.add_log_event("Statistics cleared") + + elif (ch == ord('q')): + return False + else: + self.add_log_event("Unknown key pressed {0}".format("'" + chr(ch) + "'" if chr(ch).isalpha() else "")) + + return True + + # main run entry point + def run (self): + try: + curses.curs_set(0) + except: + pass + + curses.use_default_colors() + self.stdscr.nodelay(1) + curses.nonl() + curses.noecho() + + self.generate_layout() + self.update_active = True while (True): - ch = self.stdscr.getch() - - if (ch != curses.ERR): - # stop/start status - if (ch == ord('f')): - self.update_active = not self.update_active - self.add_log_event("Update continued" if self.update_active else "Update stopped") - - elif (ch == ord('p')): - self.add_log_event("Pinging RPC server") - rc, msg = self.rpc_client.ping_rpc_server() - if rc: - self.add_log_event("Server replied: '{0}'".format(msg)) - else: - self.add_log_event("Failed to get reply") - - # c - clear stats - elif (ch == ord('c')): - self.add_log_event("Statistics cleared") - - elif (ch == ord('q')): - break - else: - self.add_log_event("Unknown key pressed {0}".format("'" + chr(ch) + "'" if chr(ch).isalpha() else "")) + + rc = self.wait_for_key_input() + if not rc: + break self.update_control() self.update_info() |