0

I'm writing a TCP server in Erlang, using Ranch. The clients will reconnect immediately the connection is dropped, which means that one particular failure mode is listeners being started and killed dozens of times a second.

I'd like to detect this happening and publish statistics to statsd, for monitoring in production.

So, can I use something in Ranch to monitor when a listener is recycled? Or can I use something in Erlang to monitor process mortality for the entire node, without having to link to each process, and where those processes were started by some other supervisor, so I don't have a reference to them?

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • I would actually go about this using process_flag(trap_exit, true) in your protocol definition. That way you can have the process update statsd itself in a terminate routine. The easiest way to go about this may be to turn your protocol handler into a gen_server (because gen_server automatically catches callbacks), as demonstrated here: http://ninenines.eu/docs/en/ranch/HEAD/guide/protocols/ – Soup d'Campbells Dec 20 '13 at 02:48
  • Could you clarify this, please? I'm having trouble understanding how the protocol traps itself crashing. – Roger Lipscombe Dec 21 '13 at 20:36

1 Answers1

0

It's not a direct answer to my question, but I opted, instead, to have a separate process periodically polling ranch_server:count_connections(my_ref), and publish that to statsd.

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380