monitor_nodes(Flag) -> ok | Error
monitor_nodes(Flag, Options) -> ok | Error
Types:
Flag = boolean()
Options = [Option]
Option = {node_type, NodeType} | nodedown_reason
NodeType = visible | hidden | all
Error = error | {error, term()}

-module(rabbit_node_monitor).
-behaviour(gen_server).
-export([start_link/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
%%--------------------------------------------------------------------
start_link() ->
gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).
%%--------------------------------------------------------------------
init([]) ->
ok = net_kernel:monitor_nodes(true),
{ok, no_state}.
handle_call(_Request, _From, State) ->
{noreply, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info({nodeup, Node}, State) ->
rabbit_log:info("node ~p up", [Node]),
{noreply, State};
handle_info({nodedown, Node}, State) ->
rabbit_log:info("node ~p down", [Node]),
%% TODO: This may turn out to be a performance hog when there are
%% lots of nodes. We really only need to execute this code on
%%*one* node, rather than all of them.
ok = rabbit_networking:on_node_down(Node),
ok = rabbit_amqqueue:on_node_down(Node),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%%--------------------------------------------------------------------

When you
use same cookie for all nodes in a distributed Erlang system, you might have
probably seen that all the nodes are interconnected with each other.
(mathu@mathu)>
(mathu@mathu)> nodes().
[mathu9@mathu,mathu1@mathu,mathu2@mathu,mathu3@mathu,
mathu4@mathu,mathu5@mathu,mathu6@mathu,mathu7@mathu,
mathu15@mathu,mathu12@mathu,mathu14@mathu,mathu11@mathu,
mathu10@mathu,mathu13@mathu,mathu8@mathu,mathu9@mathu]
(mathu@mathu)>
Having unwanted nodes connected is overhead for the system. Therefore the
bellow one-liner will help to make it
clean.
[net_kernel:disconnect(X) || X <- nodes()
-- [List_of_wanted_nodes]].
(mathu@mathu)>
(mathu@mathu)> nodes().
[mathu9@mathu,mathu1@mathu,mathu2@mathu,mathu3@mathu,
mathu4@mathu,mathu5@mathu,mathu6@mathu,mathu7@mathu,
mathu15@mathu,mathu12@mathu,mathu14@mathu,mathu11@mathu,
mathu10@mathu,mathu13@mathu,mathu8@mathu,mathu9@mathu]
(mathu@mathu)>
allow(Nodes) -> ok | error
Types:
Nodes = [node()]
Limits access to the specified set of nodes. Any access attempts made from (or to) nodes not in Nodes will be rejected.
Returns error if any element in Nodes is not an atom.