Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import re
- import collections
- import operator
- open_indices = []
- closed_indices = []
- prefixes = collections.defaultdict(int)
- with open(sys.argv[1], "r") as fp:
- header = fp.readline()
- for line in fp.readlines():
- parts = line[:-1].split()
- if len(parts) == 2 and parts[0] == "close":
- closed_indices.append(parts[1])
- else:
- open_indices.append({ 'index': parts[2], 'status': parts[1], 'health': parts[0], 'pri': int(parts[3]), 'rep': int(parts[4]), 'docs.count': int(parts[5]), 'docs.deleted': int(parts[6]), 'store.size': int(parts[7]), 'pri.store.size': int(parts[8]) })
- dotdate_r = re.compile(r"(.+)([0-9]{4,})\.([0-9]{2,})\.([0-9]{2,})$")
- dashdate_r = re.compile(r"(.+)([0-9]{4,})-([0-9]{2,})-([0-9]{2,})$")
- dashdateym_r = re.compile(r"(.+)([0-9]{4,})-([0-9]{2,})$")
- numdate_r = re.compile(r"(.+)([0-9]{4,})([0-9]{2,})([0-9]{2,})$")
- numdateym_r = re.compile(r"(.+)([0-9]{4,})([0-9]{2,})$")
- def domatch(pat, index):
- m = pat.match(index)
- if m is None:
- return False
- prefix = m.group(1)
- prefixes[prefix] += 1
- return True
- for idx in open_indices:
- name = idx['index']
- v = domatch(dotdate_r, name)
- if v:
- continue
- v = domatch(dashdate_r, name)
- if v:
- continue
- v = domatch(dashdateym_r, name)
- if v:
- continue
- v = domatch(numdate_r, name)
- if v:
- continue
- v = domatch(numdateym_r, name)
- if v:
- continue
- prefixes[name] += 1
- for idx in closed_indices:
- v = domatch(dotdate_r, idx)
- if v:
- continue
- v = domatch(dashdate_r, idx)
- if v:
- continue
- v = domatch(dashdateym_r, idx)
- if v:
- continue
- v = domatch(numdate_r, idx)
- if v:
- continue
- v = domatch(numdateym_r, idx)
- if v:
- continue
- prefixes[idx] += 1
- stats = {}
- for pre in prefixes:
- closed = 0
- for idx in closed_indices:
- if idx.startswith(pre):
- closed += 1
- opened = 0
- green = 0
- yellow = 0
- red = 0
- docs = 0
- deleted = 0
- size = 0
- for idx in open_indices:
- if idx['index'].startswith(pre):
- opened += 1
- if idx['health'] == 'green':
- green += 1
- elif idx['health'] == 'yellow':
- yellow += 1
- else:
- assert idx['health'] == 'red'
- red += 1
- docs += idx['docs.count']
- deleted += idx['docs.deleted']
- size += idx['store.size']
- stats[pre] = { 'closed': closed, 'opened': opened, 'green': green, 'yellow': yellow, 'red': red, 'docs': docs, 'deleted': deleted, 'size': size }
- sorted_prefixes = sorted(prefixes.items(), key=operator.itemgetter(1), reverse=True)
- for pre,v in sorted_prefixes:
- stat = stats[pre]
- print "%6d %5d %5d %5d %3d %3d %20d %10d %20d %s" % (v, stat['closed'], stat['opened'], stat['green'], stat['yellow'], stat['red'], stat['docs'], stat['deleted'], stat['size'], pre)
- if 0:
- for idx in open_indices:
- print repr(idx)
- for idx in closed_indices:
- print idx
Add Comment
Please, Sign In to add comment