@@ -74,7 +74,6 @@ class Elasticstat:
74
74
STATUS_COLOR = {'red' : ESColors .RED , 'green' : ESColors .GREEN , 'yellow' : ESColors .YELLOW }
75
75
76
76
def __init__ (self , host , port , username , password , delay_interval , categories , threadpools , no_color ):
77
-
78
77
self .sleep_interval = delay_interval
79
78
self .node_counters = {}
80
79
self .node_counters ['gc' ] = {}
@@ -85,14 +84,9 @@ def __init__(self, host, port, username, password, delay_interval, categories, t
85
84
self .node_names = {} # node names, organized by id
86
85
self .new_nodes = [] # used to track new nodes that join the cluster
87
86
self .active_master = ""
88
- self .threadpools = threadpools
89
87
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 )
96
90
97
91
# check for port in host
98
92
if ':' in host :
@@ -108,6 +102,26 @@ def __init__(self, host, port, username, password, delay_interval, categories, t
108
102
109
103
self .es_client = Elasticsearch ([host_dict ])
110
104
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
+
111
125
def colorize (self , msg , color ):
112
126
if self .no_color == True :
113
127
return (msg )
@@ -319,8 +333,6 @@ def format_headings(self):
319
333
self .node_headings = " " .join (node_heading_segments )
320
334
321
335
def print_stats (self ):
322
- counter = 0
323
-
324
336
# just run forever until ctrl-c
325
337
while True :
326
338
cluster_health = self .es_client .cluster .health ()
@@ -330,10 +342,9 @@ def print_stats(self):
330
342
# Print cluster health
331
343
cluster_health ['timestamp' ] = self .thetime ()
332
344
status = cluster_health ['status' ]
333
- #cluster_health['status'] = self.colorize(status, self.STATUS_COLOR[status])
334
345
print self .colorize (self .cluster_headings , ESColors .GRAY )
335
346
print self .colorize (CLUSTER_TEMPLATE .format (** cluster_health ), self .STATUS_COLOR [status ])
336
- print "" # space for readability
347
+ # print "" # space for readability
337
348
338
349
# Nodes can join and leave cluster with each iteration -- in order to report on nodes
339
350
# that have left the cluster, maintain a list grouped by role.
@@ -395,7 +406,7 @@ def main():
395
406
default = 'all' ,
396
407
metavar = 'CATEGORY' ,
397
408
nargs = '+' ,
398
- help = 'Statistic categories to show' )
409
+ help = 'Statistic categories to show [all or choose from {0}]' . format ( ', ' . join ( CATEGORIES [ 1 :])) )
399
410
parser .add_argument ('-t' ,
400
411
'--threadpools' ,
401
412
dest = 'threadpools' ,
0 commit comments