Skip to content

Instantly share code, notes, and snippets.

@haginara
Created July 1, 2017 01:47
Show Gist options
  • Save haginara/09de876d8af5afe28100f6b9b8cdd305 to your computer and use it in GitHub Desktop.
Save haginara/09de876d8af5afe28100f6b9b8cdd305 to your computer and use it in GitHub Desktop.
import requests
import sys
import json
import os
def out(text, *args):
print(text % args)
HOST = "http://127.0.0.1:9200"
QUERY = "_nodes/stats"
NODE = 'data'
out("Start to get Nodes")
response = requests.get("%s/%s" % (HOST, QUERY))
data = json.loads(response.text)
name = data.get('cluster_name', None)
out("NAME: %s", name)
nodes = data.get('nodes', None)
for uuid in nodes:
node = nodes[uuid]
if 'data' not in node['attributes']:
index_total = node['indices']['indexing']['index_total']
index_time_in_millis = node['indices']['indexing']['index_time_in_millis']
out("node: %s, %d docs/sec, %f sec/doc", node['name'],
float(index_total) / (float(index_time_in_millis)/1000),
(float(index_time_in_millis) / float(index_total)) / 1000)
else:
out("No more node")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment