5353parser .add_option ("" , "--fix_330" ,
5454 action = "store_true" , dest = "fix_330" , default = False ,
5555 help = "workaround for a bug in ZK 3.3.0" )
56+ parser .add_option ("-w" , "--wide" ,
57+ action = "store_true" , dest = "wide" , default = False ,
58+ help = "allow output to expand beyond 80 cols" )
5659parser .add_option ("-v" , "--verbosity" ,
5760 dest = "verbosity" , default = "DEBUG" ,
5861 help = "log level verbosity (DEBUG, INFO, WARN(ING), ERROR, CRITICAL/FATAL)" )
@@ -224,20 +227,32 @@ def update(self, s):
224227 (nc , zxid , sc ))
225228
226229class ServerUI (BaseUI ):
227- def __init__ (self , height , width , server_count ):
230+ def __init__ (self , height , width , server_count , wide = False ):
231+ self .wide = wide
228232 BaseUI .__init__ (self , curses .newwin (server_count + 2 , width , 1 , 0 ))
229233
230234 def resize (self , maxy , maxx ):
231235 BaseUI .resize (self , maxy , maxx )
232- self .addstr (1 , 0 , "ID SERVER PORT M OUTST RECVD SENT CONNS MINLAT AVGLAT MAXLAT" , curses .A_REVERSE )
236+ if self .wide :
237+ self .addstr (1 , 0 , "ID SERVER PORT M OUTST RECVD SENT CONNS MINLAT AVGLAT MAXLAT" , curses .A_REVERSE )
238+ else :
239+ self .addstr (1 , 0 , "ID SERVER PORT M OUTST RECVD SENT CONNS MINLAT AVGLAT MAXLAT" , curses .A_REVERSE )
233240
234241 def update (self , s ):
242+ if self .wide :
243+ host_width = 30
244+ unavailable_format = "%-2s %-30s %5s %s"
245+ available_format = "%-2s %-30s %5s %s %8s %8s %8s %5d %6s %6s %6s"
246+ else :
247+ host_width = 15
248+ unavailable_format = "%-2s %-15s %5s %s"
249+ available_format = "%-2s %-15s %5s %s %8s %8s %8s %5d %6s %6s %6s"
235250 if s .unavailable :
236- self .addstr (s .server_id + 2 , 0 , "%-2s %-15s %5s %s" %
237- (s .server_id , s .host [:15 ], s .port , s .mode [:1 ].upper ()))
251+ self .addstr (s .server_id + 2 , 0 , unavailable_format %
252+ (s .server_id , s .host [:host_width ], s .port , s .mode [:1 ].upper ()))
238253 else :
239- self .addstr (s .server_id + 2 , 0 , "%-2s %-15s %5s %s %8s %8s %8s %5d %6s %6s %6s" %
240- (s .server_id , s .host [:15 ], s .port , s .mode [:1 ].upper (),
254+ self .addstr (s .server_id + 2 , 0 , available_format %
255+ (s .server_id , s .host [:host_width ], s .port , s .mode [:1 ].upper (),
241256 s .outstanding , s .received , s .sent , len (s .sessions ),
242257 s .min_latency , s .avg_latency , s .max_latency ))
243258
@@ -255,7 +270,7 @@ def hostname(self, session):
255270
256271 def update (self , s ):
257272 self .win .erase ()
258- self .addstr (1 , 0 , "CLIENT PORT S I QUEUED RECVD SENT" , curses .A_REVERSE )
273+ self .addstr (1 , 0 , "CLIENT PORT S I QUEUED RECVD SENT" , curses .A_REVERSE )
259274 self .sessions [s .server_id ] = s .sessions
260275 items = []
261276 for l in self .sessions :
@@ -265,15 +280,16 @@ def update(self, s):
265280 try :
266281 #ugh, need to handle if slow - thread for async resolver?
267282 host = self .hostname (session ) if options .names else session .host
268- self .addstr (i + 2 , 0 , "%-15s %5s %1s %1s %8s %8s %8s" %
269- (host [:15 ], session .port , session .server_id , session .interest_ops ,
283+ self .addstr (i + 2 , 0 , "%-30s %5s %1s %1s %8s %8s %8s" %
284+ (host [:30 ], session .port , session .server_id , session .interest_ops ,
270285 session .queued , session .recved , session .sent ))
271286 except :
272287 break
273288
274289mainwin = None
275290class Main (object ):
276- def __init__ (self , servers ):
291+ def __init__ (self , servers , wide_ui = False ):
292+ self .wide_ui = wide_ui
277293 self .servers = servers .split ("," )
278294
279295 def show_ui (self , stdscr ):
@@ -291,7 +307,7 @@ def show_ui(self, stdscr):
291307 server_count = len (self .servers )
292308 maxy , maxx = stdscr .getmaxyx ()
293309 uis = (SummaryUI (maxy , maxx , server_count ),
294- ServerUI (maxy , maxx , server_count ),
310+ ServerUI (maxy , maxx , server_count , wide = self . wide_ui ),
295311 SessionUI (maxy , maxx , server_count ))
296312
297313 # start the polling threads
@@ -389,7 +405,7 @@ def get_zk_servers(filename):
389405
390406def main_func ():
391407 LOG .debug ("startup" )
392- ui = Main (get_zk_servers (options .configfile ))
408+ ui = Main (get_zk_servers (options .configfile ), wide_ui = options . wide )
393409 curses .wrapper (ui .show_ui )
394410
395411if __name__ == '__main__' :
0 commit comments