Skip to content

Instantly share code, notes, and snippets.

@jtuple
Created August 25, 2011 19:08
Show Gist options
  • Save jtuple/1171514 to your computer and use it in GitHub Desktop.
Save jtuple/1171514 to your computer and use it in GitHub Desktop.
Script to print Riak ring ownership information
%% Script to print out Riak ring ownership.
%% Copy/paste into Erlang shell attached to a riak cluster (riak-admin attach).
%% Remember to use: CTRL-D to dettach from the shell once done.
fun() ->
{ok, Ring} = riak_core_ring_manager:get_my_ring(),
Owners = riak_core_ring:all_members(Ring),
Indices = riak_core_ring:all_owners(Ring),
RingSize = length(Indices),
Names = lists:zip(Owners, lists:seq(1, length(Owners))),
io:format("~36..=s Nodes ~36..=s~n", ["", ""]),
[begin
NodeIndices = [Idx || {Idx,Owner} <- Indices,
Owner =:= Node],
RingPercent = length(NodeIndices) * 100 / RingSize,
io:format("Node #~b: ~5.1f% ~s~n",
[Name, RingPercent, Node])
end || {Node, Name} <- Names],
Ownership =
[orddict:fetch(Owner, Names) || {_Idx, Owner} <- Indices],
io:format("~36..=s Ring ~37..=s~n", ["", ""]),
io:format("~p~n", [Ownership])
end().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment