Monitor remote applications like nodes with net_kernel:monitor_nodes/1

Hi!

I’m working on a library where instances of an application on multiple nodes (dynamically added and removed) collaborate together.

At first I was using net_kernel:monitor_nodes/1 to do so, assuming that the application would be started before receiving a nodeup message but that’s node the case (for instance when starting a node with the local-cluster library, the nodes connect before applications are started).

Also applications can be stopped for other legitimate reasons. For example, stopping Mnesia is needed to remove an extra DB node from a it.

One solution I’ve been thinking of is to:

  • having the application sending a presence message to other application instances on other nodes on startup
  • monitor the application processes with erlang:monitor/2

Is there a simpler solution or a standard library which already does that? Maybe something like pg but with join/leave messages?

Cheers