Elasticsearch want to retrieve all nodes memory percentage

Viewed 113

I am able to get "os.mem.used_percent" by this way curl -GET "http://localhost:9200/_nodes/stats/os".

But I need to get all nodes percent only. So, that I make automation script which check if percentage not goes beyond 90 and if then send the node name.

Is there any way to get only node name and its memory used percentage.

Thanks

1 Answers

Yes you can do using python.

curl -X -GET "http://localhost:9200/_nodes/stats/os" > es.json  

with open("es.json") as f:
    es = json.load(f)

memory_used_per_node = {}
nodes_memory = {}

for n in es["nodes"]:
    nodes_memory[n] = es["nodes"][n]["os"]["mem"]["used_percent"]

memory_used_per_node["nodes_memory"] = nodes_memory
memory_used_per_node["cluster_name"] = es["cluster_name"]
Related