@@ -45,6 +45,7 @@ FS_TOP_SUPPORTED_VER = 2
4545ITEMS_PAD_LEN = 3
4646ITEMS_PAD = " " * ITEMS_PAD_LEN
4747DEFAULT_REFRESH_INTERVAL = 1
48+ DEFAULT_PAD_WIDTH = 300 # for medium size windows
4849
4950# metadata provided by mgr/stats
5051FS_TOP_MAIN_WINDOW_COL_CLIENT_ID = "client_id"
@@ -290,7 +291,7 @@ class FSTop(FSTopBase):
290291 self .conffile = args .conffile
291292 self .refresh_interval_secs = args .delay
292293 self .PAD_HEIGHT = 10000 # height of the fstop_pad
293- self .PAD_WIDTH = 300 # width of the fstop_pad
294+ self .PAD_WIDTH = DEFAULT_PAD_WIDTH # width of the fstop_pad
294295 self .exit_ev = threading .Event ()
295296
296297 def handle_signal (self , signum , _ ):
@@ -358,6 +359,12 @@ class FSTop(FSTopBase):
358359 # If the terminal do not support the visibility
359360 # requested it will raise an exception
360361 pass
362+
363+ # Check the window size before creating the pad. For large windows,
364+ # PAD_WIDTH = window width.
365+ h , w = self .stdscr .getmaxyx ()
366+ if (w > DEFAULT_PAD_WIDTH ):
367+ self .PAD_WIDTH = w
361368 self .fstop_pad = curses .newpad (self .PAD_HEIGHT , self .PAD_WIDTH )
362369 self .run_all_display ()
363370
@@ -934,6 +941,15 @@ class FSTop(FSTopBase):
934941 self .header .addstr (5 , 0 , help , curses .A_DIM )
935942 return True
936943
944+ def handle_header (self , stats_json , help , screen_title , color_id = 0 ):
945+ try :
946+ return self .create_header (stats_json , help , screen_title , color_id )
947+ except curses .error :
948+ curses .endwin ()
949+ sys .stderr .write ("Error creating header. Please increase the window width to use "
950+ "cephfs-top.\n " )
951+ exit ()
952+
937953 def run_display (self ):
938954 # clear the pads to have a smooth refresh
939955 self .header .erase ()
@@ -983,7 +999,7 @@ class FSTop(FSTopBase):
983999 current_states ["limit" ] = None
9841000 self .header .erase () # erase previous text
9851001 self .fsstats .erase ()
986- self .create_header (stats_json , help , screen_title , 3 )
1002+ self .handle_header (stats_json , help , screen_title , 3 )
9871003 else :
9881004 self .tablehead_y = 0
9891005 help = "COMMANDS: " + help_commands
@@ -996,7 +1012,7 @@ class FSTop(FSTopBase):
9961012 else :
9971013 num_client = len (client_metadata )
9981014 vscrollEnd += num_client
999- if self .create_header (stats_json , help , screen_title , 3 ):
1015+ if self .handle_header (stats_json , help , screen_title , 3 ):
10001016 self .create_table_header ()
10011017 self .create_clients (stats_json , fs )
10021018
@@ -1030,7 +1046,10 @@ class FSTop(FSTopBase):
10301046 elif cmd == curses .KEY_END :
10311047 hscrollOffset = self .PAD_WIDTH - self .viewportWidth - 1
10321048 elif cmd == curses .KEY_RESIZE :
1033- # terminal resize event. Update the viewport dimensions
1049+ # terminal resize event.
1050+ # Update the pad dimensions
1051+ self .PAD_WIDTH = DEFAULT_PAD_WIDTH
1052+ # Update the viewport dimensions
10341053 windowsize = self .stdscr .getmaxyx ()
10351054 self .viewportHeight , self .viewportWidth = windowsize [0 ] - 1 , windowsize [1 ] - 1
10361055
@@ -1112,7 +1131,7 @@ class FSTop(FSTopBase):
11121131 current_states ["limit" ] = None
11131132 self .header .erase () # erase previous text
11141133 self .fsstats .erase ()
1115- self .create_header (stats_json , help , screen_title , 2 )
1134+ self .handle_header (stats_json , help , screen_title , 2 )
11161135 else :
11171136 self .tablehead_y = 0
11181137 num_client = 0
@@ -1128,7 +1147,7 @@ class FSTop(FSTopBase):
11281147 else :
11291148 num_client = len (client_metadata )
11301149 vscrollEnd += num_client
1131- if self .create_header (stats_json , help , screen_title , 2 ):
1150+ if self .handle_header (stats_json , help , screen_title , 2 ):
11321151 if not index : # do it only for the first fs
11331152 self .create_table_header ()
11341153 self .create_clients (stats_json , fs )
@@ -1163,7 +1182,10 @@ class FSTop(FSTopBase):
11631182 elif cmd == curses .KEY_END :
11641183 hscrollOffset = self .PAD_WIDTH - self .viewportWidth - 1
11651184 elif cmd == curses .KEY_RESIZE :
1166- # terminal resize event. Update the viewport dimensions
1185+ # terminal resize event.
1186+ # Update the pad dimensions
1187+ self .PAD_WIDTH = DEFAULT_PAD_WIDTH
1188+ # Update the viewport dimensions
11671189 windowsize = self .stdscr .getmaxyx ()
11681190 self .viewportHeight , self .viewportWidth = windowsize [0 ] - 1 , windowsize [1 ] - 1
11691191 if cmd :
0 commit comments