@@ -74,7 +74,6 @@ class Elasticstat:
7474 STATUS_COLOR = {'red' : ESColors .RED , 'green' : ESColors .GREEN , 'yellow' : ESColors .YELLOW }
7575
7676 def __init__ (self , host , port , username , password , delay_interval , categories , threadpools , no_color ):
77-
7877 self .sleep_interval = delay_interval
7978 self .node_counters = {}
8079 self .node_counters ['gc' ] = {}
@@ -85,14 +84,9 @@ def __init__(self, host, port, username, password, delay_interval, categories, t
8584 self .node_names = {} # node names, organized by id
8685 self .new_nodes = [] # used to track new nodes that join the cluster
8786 self .active_master = ""
88- self .threadpools = threadpools
8987 self .no_color = no_color
90-
91- # categories for display
92- if categories == 'all' :
93- self .categories = CATEGORIES
94- else :
95- self .categories = ['general' ] + categories
88+ self .threadpools = self ._parse_threadpools (threadpools )
89+ self .categories = self ._parse_categories (categories )
9690
9791 # check for port in host
9892 if ':' in host :
@@ -108,6 +102,26 @@ def __init__(self, host, port, username, password, delay_interval, categories, t
108102
109103 self .es_client = Elasticsearch ([host_dict ])
110104
105+ def _parse_categories (self , categories ):
106+ if isinstance (categories , list ):
107+ if categories [0 ] == 'all' :
108+ return CATEGORIES
109+ if ',' in categories [0 ]:
110+ categories = categories [0 ].split (',' )
111+ else :
112+ if categories == 'all' :
113+ return CATEGORIES
114+ for category in categories :
115+ if category not in CATEGORIES :
116+ msg = "{0} is not valid, please choose categories from {1}" .format (category , ', ' .join (CATEGORIES [1 :]))
117+ raise argparse .ArgumentTypeError (msg )
118+ return ['general' ] + categories
119+
120+ def _parse_threadpools (self , threadpools ):
121+ if isinstance (threadpools , list ) and ',' in threadpools [0 ]:
122+ threadpools = threadpools [0 ].split (',' )
123+ return threadpools
124+
111125 def colorize (self , msg , color ):
112126 if self .no_color == True :
113127 return (msg )
@@ -319,8 +333,6 @@ def format_headings(self):
319333 self .node_headings = " " .join (node_heading_segments )
320334
321335 def print_stats (self ):
322- counter = 0
323-
324336 # just run forever until ctrl-c
325337 while True :
326338 cluster_health = self .es_client .cluster .health ()
@@ -330,10 +342,9 @@ def print_stats(self):
330342 # Print cluster health
331343 cluster_health ['timestamp' ] = self .thetime ()
332344 status = cluster_health ['status' ]
333- #cluster_health['status'] = self.colorize(status, self.STATUS_COLOR[status])
334345 print self .colorize (self .cluster_headings , ESColors .GRAY )
335346 print self .colorize (CLUSTER_TEMPLATE .format (** cluster_health ), self .STATUS_COLOR [status ])
336- print "" # space for readability
347+ # print "" # space for readability
337348
338349 # Nodes can join and leave cluster with each iteration -- in order to report on nodes
339350 # that have left the cluster, maintain a list grouped by role.
@@ -395,7 +406,7 @@ def main():
395406 default = 'all' ,
396407 metavar = 'CATEGORY' ,
397408 nargs = '+' ,
398- help = 'Statistic categories to show' )
409+ help = 'Statistic categories to show [all or choose from {0}]' . format ( ', ' . join ( CATEGORIES [ 1 :])) )
399410 parser .add_argument ('-t' ,
400411 '--threadpools' ,
401412 dest = 'threadpools' ,
0 commit comments