Created
March 3, 2016 17:46
-
-
Save slackorama/543a6f4f291f0e7a41b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""es-index-differ.py | |
Usage: | |
es-index-differ.py [options] <host> | |
Options: | |
-h --help show this | |
-v --version show version info | |
--sleep-time time to sleep between runs [default: 10] | |
--port PORT elasticsearch port [default: 9200] | |
""" | |
from collections import defaultdict | |
import time | |
from docopt import docopt | |
import requests | |
sleep_time = 10 | |
idx_counts = defaultdict(int) | |
def get_index_stats(host, port): | |
es_host = 'http://{host}:{port}'.format(host=host, port=port) | |
indices = requests.get('{es_host}/_stats'.format(es_host=es_host), | |
timeout=10) | |
return indices.json() | |
def main(): | |
arguments = docopt(__doc__, version="0.1") | |
host = arguments['<host>'] | |
port = int(arguments['--port']) | |
sleep_time = int(arguments['--sleep-time']) | |
indices = get_index_stats(host, port) | |
for (idx, obj) in indices['indices'].items(): | |
idx_counts[idx] = obj['total']['docs']['count'] | |
time.sleep(sleep_time) | |
indices = get_index_stats(host, port) | |
print('index, docs delta') | |
for idx, obj in indices['indices'].items(): | |
diff = obj['total']['docs']['count'] - idx_counts[idx] | |
if diff != 0: | |
print('{0}, {1}'.format(idx, diff)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment