Skip to content

Commit

Permalink
remove repeated node id look ups (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
charless-splunk authored and mahdibh committed Sep 30, 2016
1 parent db27db4 commit d39ab36
Show file tree
Hide file tree
Showing 59 changed files with 97 additions and 63 deletions.
39 changes: 22 additions & 17 deletions elasticsearch_collectd.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

ES_CURRENT_MASTER = False
MASTER_ONLY = False
NODE_ID = None

DEFAULTS = set([
# AUTOMATICALLY GENERATED METRIC NAMES
Expand Down Expand Up @@ -846,7 +847,10 @@ def fetch_stats():
log.info('Parsing cluster stats')
parse_cluster_stats(cluster_json_stats, CLUSTER_STATS)

if (ENABLE_INDEX_STATS and ES_MASTER_ELIGIBLE and SKIP_COUNT >= INDEX_SKIP) and ((MASTER_ONLY and ES_CURRENT_MASTER) or (not MASTER_ONLY )):
if (ENABLE_INDEX_STATS and ES_MASTER_ELIGIBLE and
SKIP_COUNT >= INDEX_SKIP) \
and ((MASTER_ONLY and ES_CURRENT_MASTER)
or (not MASTER_ONLY)):
# Reset skip count
SKIP_COUNT = 0
indices = fetch_url(ES_INDEX_URL)
Expand Down Expand Up @@ -882,7 +886,7 @@ def fetch_url(url):


def load_es_info():
global ES_VERSION, ES_CLUSTER, ES_MASTER_ELIGIBLE
global ES_VERSION, ES_CLUSTER, ES_MASTER_ELIGIBLE, NODE_ID

json = fetch_url("http://" + ES_HOST + ":" + str(ES_PORT) +
"/_nodes/_local")
Expand All @@ -898,6 +902,10 @@ def load_es_info():
(ES_VERSION, ES_CLUSTER, ES_MASTER_ELIGIBLE))
return

# Identify the current node
NODE_ID = json['nodes'].keys()[0]
log.notice('current node id: %s' % NODE_ID)

cluster_name = json['cluster_name']
# we should have only one entry with the current node information
node_info = json['nodes'].itervalues().next()
Expand All @@ -920,23 +928,20 @@ def load_es_info():


def detect_es_master():
"""Determines if this is the current master. This method sets ES_CURRENT_MASTER"""
"""Determines if this is the current master. This method sets
ES_CURRENT_MASTER"""
global ES_CURRENT_MASTER

json = fetch_url("http://" + ES_HOST + ":" + str(ES_PORT) +
"/_nodes/_local")
if json is None:
ES_CURRENT_MASTER = False
log.warning('Unable to determine node \
information, defaulting to current master %s' % ES_CURRENT_MASTER)
return

# determine current master and update globel setting
# determine current master
cluster_state = fetch_url("http://" + ES_HOST + ":" + str(ES_PORT) +
"/_cluster/state/master_node")
ES_CURRENT_MASTER = cluster_state['master_node'] == json['nodes'].keys()[0]

log.notice('current master: %s' % ES_CURRENT_MASTER)
"/_cluster/state/master_node")
if ES_CURRENT_MASTER is False and cluster_state['master_node'] == NODE_ID:
ES_CURRENT_MASTER = True
log.notice('current master: %s' % ES_CURRENT_MASTER)
elif ES_CURRENT_MASTER is True and cluster_state['master_node'] != NODE_ID:
ES_CURRENT_MASTER = False
log.notice('current master: %s' % ES_CURRENT_MASTER)
else:
log.debug('current master: %s' % ES_CURRENT_MASTER)


def parse_node_stats(json, stats):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/1.4.5/_all/_stats/index.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_shards":{"total":10,"successful":5,"failed":0},"_all":{"primaries":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":575,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":99,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":5,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":10,"total_time_in_millis":24},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":335544320,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}},"total":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":575,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":99,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":5,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":10,"total_time_in_millis":24},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":335544320,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}}},"indices":{"twitter":{"primaries":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":575,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":99,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":5,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":10,"total_time_in_millis":24},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":335544320,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}},"total":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":575,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":99,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":5,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":10,"total_time_in_millis":24},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":335544320,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}}}}}
{"_shards":{"total":10,"successful":4,"failed":0},"_all":{"primaries":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":460,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":112,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":4,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":8,"total_time_in_millis":36},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":268435456,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}},"total":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":460,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":112,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":4,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":8,"total_time_in_millis":36},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":268435456,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}}},"indices":{"twitter":{"primaries":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":460,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":112,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":4,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":8,"total_time_in_millis":36},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":268435456,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}},"total":{"docs":{"count":0,"deleted":0},"store":{"size_in_bytes":460,"throttle_time_in_millis":0},"indexing":{"index_total":1,"index_time_in_millis":112,"index_current":0,"delete_total":0,"delete_time_in_millis":0,"delete_current":0,"noop_update_total":0,"is_throttled":false,"throttle_time_in_millis":0},"get":{"total":0,"time_in_millis":0,"exists_total":0,"exists_time_in_millis":0,"missing_total":0,"missing_time_in_millis":0,"current":0},"search":{"open_contexts":0,"query_total":0,"query_time_in_millis":0,"query_current":0,"fetch_total":0,"fetch_time_in_millis":0,"fetch_current":0},"merges":{"current":0,"current_docs":0,"current_size_in_bytes":0,"total":0,"total_time_in_millis":0,"total_docs":0,"total_size_in_bytes":0},"refresh":{"total":4,"total_time_in_millis":0},"flush":{"total":0,"total_time_in_millis":0},"warmer":{"current":0,"total":8,"total_time_in_millis":36},"filter_cache":{"memory_size_in_bytes":0,"evictions":0},"id_cache":{"memory_size_in_bytes":0},"fielddata":{"memory_size_in_bytes":0,"evictions":0},"percolate":{"total":0,"time_in_millis":0,"current":0,"memory_size_in_bytes":-1,"memory_size":"-1b","queries":0},"completion":{"size_in_bytes":0},"segments":{"count":0,"memory_in_bytes":0,"index_writer_memory_in_bytes":100216,"index_writer_max_memory_in_bytes":268435456,"version_map_memory_in_bytes":160,"fixed_bit_set_memory_in_bytes":0},"translog":{"operations":1,"size_in_bytes":17},"suggest":{"total":0,"time_in_millis":0,"current":0},"query_cache":{"memory_size_in_bytes":0,"evictions":0,"hit_count":0,"miss_count":0}}}}}
1 change: 1 addition & 0 deletions tests/data/1.4.5/_cluster/state/master_node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"cluster_name":"elasticsearch","master_node":"sOHvNQWTSAOKf3X42952lQ"}
Loading

0 comments on commit d39ab36

Please sign in to comment.