Created
January 7, 2015 19:13
-
-
Save xcsrz/cd081af4b29189a241d2 to your computer and use it in GitHub Desktop.
Prints out how how many primary and secondary shards on each node in an Elasticsearch Cluster.
This file contains 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 ruby | |
require "json" | |
state = JSON.parse `curl localhost:9200/_cluster/state` | |
dets = {} | |
state["nodes"].each do |name, details| | |
dets[name] = { "name" => details["name"], "address" => details["transport_address"] } | |
end | |
nodes = {} | |
state["routing_nodes"]["nodes"].each do |node,shards| | |
nodes[node] = {"primary" => 0, "replica" => 0 } | |
shards.each do |shard| | |
if shard["primary"] | |
nodes[node]["primary"] += 1 | |
else | |
nodes[node]["replica"] += 1 | |
end | |
end | |
end | |
nodes.each do |name, status| | |
puts "#{name} (#{dets[name]["name"]} - #{dets[name]["address"].gsub(/[^\d\.]/,'').sub(/930\d/,'')}):" | |
puts "\tPrimary Shards: #{status["primary"]}" | |
puts "\tReplica Shards: #{status["replica"]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment