[erlang-questions] how: Monitor nodeup _and_ nodedown

Jay Nelson jay@REDACTED
Wed Nov 7 16:13:47 CET 2007


I must be leaving something out.  I am trying to monitor another  
node.  My initial attempt was to just use the erlang monitor:

erlang:monitor_node(NodeName, true).
receive Any -> Any after 30000 -> timeout end.

This only receives {nodedown, NodeName} if the node is not already  
started, or if it goes down.  I never see a {nodeup, NodeName}.   
Rereading the documentation and thinking about it a bit, I could  
understand why this might be the case.

(I then wrote my own node monitoring before realizing that net_kernel  
had a function.  It does what I want -- single node monitor, initial  
state reporting, both nodeup and nodedown.)

Switching to net_kernel:

net_kernel:monitor_nodes(true).
receive Any -> Any after 30000 -> timeout end.

Bringing up my other node (on the same Mac OSX laptop) gives me a  
{nodeup, NodeName} when I do a net_adm:ping(MonitorNode), but  
quitting the shell doesn't give me a {nodedown, NodeName}.

I tried with and without cookies, and made sure that my receive after  
timeout is greater than the default netticktime of 15000.   The  
documentation clearly shows that nodeup and nodedown should be  
available.

1) Am I leaving out a step?
2) Is there a way to only watch one node instead of all nodes?
3) In any case, I haven't seen the behavior that you get the initial  
state when the monitor is first started (e.g., if the node is already  
up, there is no indication until it goes down -- but  
erlang:monitor_node does give a nodedown if it is already down)


jay




More information about the erlang-questions mailing list