Skip to content

Instantly share code, notes, and snippets.

@MarcialRosales
Last active July 19, 2018 15:54
Show Gist options
  • Save MarcialRosales/46fd1c21308e4b0ffeb79c5ad54024d1 to your computer and use it in GitHub Desktop.
Save MarcialRosales/46fd1c21308e4b0ffeb79c5ad54024d1 to your computer and use it in GitHub Desktop.
Gather consumer channel information from RabbitMQ in order to troubleshoot an issue with unexpected unacknowledged messages

Instructions

  1. Copy the provided script (gatherChannelInfo.erl) onto one of the rabbitmq vms
    e.g.
bosh -d <yourDeploymentName> scp gatherChannelInfo.erl rmq/b9b26ca8-6a15-4bf6-9881-68486042f46b:/tmp/gatherChannelInfo.erl
  1. Ssh onto the same rabbitmq vms and switch to root (sudo -i)
    e.g.
bosh -d <yourDeploymentName> ssh rmq/b9b26ca8-6a15-4bf6-9881-68486042f46b
  1. Make sure erl is on the path
which erl
  1. Run the following command to connect to one of the erlang VMs:
erl -sname "remsh-1" -hidden -remsh "$RABBITMQ_NODENAME"
  1. Copy and paste this command onto the erl shell:
c("/tmp/gatherChannelInfo", [{outdir, "/tmp"}] ).
  1. Copy and paste this command onto the erl shell. Replace VirtualHost(e.g./) and queue name (e.g.test-1) with yours.
gatherChannelInfo:main(<<"/">>, <<"test-1">>).
  1. Send us the outcome from the last command

  2. To exit from erl shell : ^g q Enter

-module(gatherChannelInfo).
-export([main/2]).
-import(io, [format/1]).
find(What, List) ->
hd([ Value || {Key, Value} <- List, Key =:= What]).
main(VirtualHost, QueueName) ->
%% Get queue information
Queue = erlang:process_info(rabbit_amqqueue:pid_of(VirtualHost, QueueName), dictionary),
io:format("Queue ~p on ~p information ~n ~p~n", [QueueName, VirtualHost, Queue]),
io:format("-----------------------------------~n"),
ChannelPids = [X || { {ch, X}, _} <- element(2,Queue)],
%% Print acktags and unsent_message_count from each channel bound to the queue
ChannelDetails = [ { Pid, AckTags, Unsent } || { {ch, Pid}, {cr, _, _, AckTags, _, _, _, Unsent}} <- element(2,Queue)],
io:format("Channel consumer details ~n ~p~n", [ChannelDetails]),
io:format("-----------------------------------~n"),
%% Get channel information bound to a queue called test-1
ChannelInfos = [rabbit_channel:info(X) || X <- ChannelPids],
Channels = [erlang:process_info(X) || X <- ChannelPids],
io:format("Channel info ~n ~p~n", [ChannelInfos]),
io:format("-----------------------------------~n"),
io:format("Channel Processes ~n ~p~n", [Channels]),
io:format("-----------------------------------~n"),
%% Get connection information associated to those channels.
Connections = [ erlang:process_info(X) || X <- sets:to_list(sets:from_list([ find(connection,X) || X <- ChannelInfos])) ],
io:format("Connection Processes ~n ~p~n", [Connections]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment