Erlang has a powerful trace utility, similar to strace. Instead of tracing system calls, you can trace any piece of Erlang code. RabbitMQ is written in Erlang, so we can use Erlang trace to see what its doing. The extra load may flood the system, so be very careful running this in prod.
In this example we will see how Rabbit is invoking mnesia. Mnesia is the database rabbit is using.
Step 1: run all this on the same host as your Rabbit broker.
Step 2: get the Erlang cookie:
sudo rabbitmqctl eval 'erlang:get_cookie().'
# note the period after the parenthesis!
This will give you a string like IMGBQSGLNYEFMMSEUNHW
Step 3: get the Erlang node name:
sudo rabbitmqctl eval 'node().'
This will give you a string like rabbit@my-host
Step 4: Start up an Erlang shell and connect to the rabbit instance.
erl -sname debug -setcookie IMGBQSGLNYEFMMSEUNHW -remsh rabbit@my-host
The string after -remsh
should be the node name you got from step 2.
The string after set-cookie
should be the cookie you got from step 1.
The string after -sname
can be anything.
The next 3 steps should be run inside your Erlang shell. You can exit it with "Control-G", then "q".
Step 4: start the tracer with dbg:tracer().
# again notice the period.
Step 5: tell the tracer to trace function calls: dbg:p(all, c)
.
Step 6: tell the tracer to trace mnesia functions: dbg:tpl(mnesia, x)
The first argument to tpl
is the module name, the second is the atom x
, which is an alias for 'everything'.
Step 7: quit the shell with "Control-G" and "q"
Step 8: Your output will be where Rabbit is logging its output to. On my system this is /var/log/rabbitmq/startup_log. And you'll see lines like this:
(<0.239.0>) call mnesia:system_info(is_running)
(<0.239.0>) call mnesia:system_info2(is_running)
(<0.239.0>) returned from mnesia:system_info2/1 -> yes
(<0.239.0>) returned from mnesia:system_info/1 -> yes
Step 9: Stop the tracer. This is very important, otherwise the flood of trace messages may take down the system!
Restart the Erlang shell from step 4, and run dbg:stop().
in the shell