nietaki
nietaki

Reputation: 9008

Getting the total message queue size in Erlang/Elixir

I'm building some monitoring for an Elixir app and want to be tracking the total length of process' message queues - if they go over any reasonable value it would mean the system isn't keeping up.

How would one query in a real-life system? :erlang.system_info/1 doesn't seem to be providing it, and you can only get per-process information from :erlang.process_info/1. I don't like the idea of using the latter and manually aggregating the message queue lengths, since there's potentially thousands of relevant GenServer processes and instrumenting them feels like unnecessary overhead.

I seem to remember Wombat OAM having this functionality which makes me think it's possible, but I might be mistaken.

Upvotes: 3

Views: 2512

Answers (2)

Jason Harrelson
Jason Harrelson

Reputation: 2693

In Erlang:

All info: :erlang.process_info(self())

Just the message queue length: :erlang.process_info(self(), :message_queue_len) # => {:message_queue_len, 2}

Just the messages: :erlang.process_info(self(), :messages) #=> {:messages, [:hello, :world]}


In Elixir:

All the info: Process.info(self())

Just the message queue length: Process.info(self(), :message_queue_len)

Just the messages: Process.info(self(), :messages)

Both give the same output which includes

Upvotes: 2

Asier Azkuenaga
Asier Azkuenaga

Reputation: 1189

For Erlang, I would recommend you using recon.

In Elixir, there is a wrapper to it: tap.

I would also suggest reading Stuff Goes Bad Erlang in Anger .

Upvotes: 1

Related Questions