Monitoring messages in process mailboxes

I haven’t used this yet, but as of OTP 27.0, you can subscribe to notifications about mailbox lengths.

:erlang.system_monitor(self(), [{:long_message_queue, {disable, enable}}])

disable and enable are integer thresholds for when you want receive a message. More explanation is in the docs.