Last active
October 26, 2015 17:49
-
-
Save amontalenti/d04879a8b5de9302ce54 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
| from __future__ import print_function | |
| import elasticsearch | |
| import collections | |
| import json | |
| def flatten(d, parent_key='', sep='_'): | |
| items = [] | |
| for k, v in d.items(): | |
| new_key = parent_key + sep + k if parent_key else k | |
| if isinstance(v, collections.MutableMapping): | |
| items.extend(flatten(v, new_key, sep=sep).items()) | |
| else: | |
| items.append((new_key, v)) | |
| return dict(items) | |
| def sizeof_fmt(num, suffix='B'): | |
| for unit in ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi']: | |
| if abs(num) < 1024.0: | |
| return "%3.1f%s%s" % (num, unit, suffix) | |
| num /= 1024.0 | |
| return "%.1f%s%s" % (num, 'Yi', suffix) | |
| def get_node_jvm_usage(es, node): | |
| data = es.nodes.stats(node)["nodes"].values()[0]["jvm"] | |
| sorted_data = sorted(flatten(data).iteritems(), key=lambda x: x[0]) | |
| ordered_data = collections.OrderedDict() | |
| for key, val in sorted_data: | |
| # convert bytes to human readable automatically | |
| if key.endswith("bytes"): | |
| val = sizeof_fmt(val) | |
| if val.endswith("GiB"): | |
| key = key + " *" | |
| elif key.endswith("percent"): | |
| val = "%s%%" % val | |
| key = key + " *" | |
| elif key.endswith("count"): | |
| val = "{:0,}".format(val) | |
| elif key.endswith("millis"): | |
| second_in_millis = 1000 | |
| minute_in_millis = (60 * second_in_millis) | |
| hour_in_millis = (60 * minute_in_millis) | |
| if val > hour_in_millis: | |
| val = val / hour_in_millis | |
| val = "{:0,}hrs".format(val) | |
| elif val > minute_in_millis: | |
| val = val / minute_in_millis | |
| val = "{:0,}mins".format(val) | |
| elif val > second_in_millis: | |
| val = val / second_in_millis | |
| val = "{:0,}s".format(val) | |
| else: | |
| val = "{:0,}".format(val) | |
| else: | |
| val = val | |
| ordered_data[key] = val | |
| return ordered_data | |
| es = elasticsearch.Elasticsearch() | |
| data = get_node_jvm_usage(es, "ue1b-es-prod1-w1e") | |
| for key, val in data.iteritems(): | |
| print("%60s %20s" % (key, val)) |
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
| buffer_pools_direct_count 6,715 | |
| buffer_pools_direct_total_capacity_in_bytes 135.0MiB | |
| buffer_pools_direct_used_in_bytes 135.0MiB | |
| buffer_pools_mapped_count 2,282 | |
| buffer_pools_mapped_total_capacity_in_bytes * 470.1GiB | |
| buffer_pools_mapped_used_in_bytes * 470.1GiB | |
| gc_collectors_old_collection_count 12 | |
| gc_collectors_old_collection_time_in_millis 1s | |
| gc_collectors_young_collection_count 9,345 | |
| gc_collectors_young_collection_time_in_millis 7mins | |
| mem_heap_committed_in_bytes * 31.2GiB | |
| mem_heap_max_in_bytes * 31.2GiB | |
| mem_heap_used_in_bytes * 21.9GiB | |
| mem_heap_used_percent * 70% | |
| mem_non_heap_committed_in_bytes 116.8MiB | |
| mem_non_heap_used_in_bytes 79.5MiB | |
| mem_pools_old_max_in_bytes * 30.6GiB | |
| mem_pools_old_peak_max_in_bytes * 30.6GiB | |
| mem_pools_old_peak_used_in_bytes * 23.2GiB | |
| mem_pools_old_used_in_bytes * 21.7GiB | |
| mem_pools_survivor_max_in_bytes 66.5MiB | |
| mem_pools_survivor_peak_max_in_bytes 66.5MiB | |
| mem_pools_survivor_peak_used_in_bytes 66.5MiB | |
| mem_pools_survivor_used_in_bytes 33.1MiB | |
| mem_pools_young_max_in_bytes 532.6MiB | |
| mem_pools_young_peak_max_in_bytes 532.6MiB | |
| mem_pools_young_peak_used_in_bytes 532.6MiB | |
| mem_pools_young_used_in_bytes 117.9MiB | |
| threads_count 130 | |
| threads_peak_count 156 | |
| timestamp 1445881682231 | |
| uptime_in_millis 18hrs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment