Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Trace messages going to the queues so we can get the number of messag…

…es delivered
  • Loading branch information...
commit a0fd1cef7062f67c56274b33e13e0afd61425bc6 1 parent 48511b3
epicads-scott epicads-scott authored
12 snmp/RABBITMQ-MIB.mib
@@ -105,7 +105,8 @@ QueueStatisticsEntry ::= SEQUENCE {
105 105 queueAcksUncommitted Gauge32,
106 106 queueConsumers Gauge32,
107 107 queueTransactions Gauge32,
108   - queueMemory Counter64
  108 + queueMemory Counter64,
  109 + queueMessagesDelivered Counter64
109 110 }
110 111
111 112 queueVhost OBJECT-TYPE
@@ -192,6 +193,13 @@ queueMemory OBJECT-TYPE
192 193 DESCRIPTION "Amount of memory used"
193 194 ::= { queueTableEntry 12 }
194 195
  196 +queueMessagesDelivered OBJECT-TYPE
  197 + SYNTAX Counter64
  198 + MAX-ACCESS read-only
  199 + STATUS current
  200 + DESCRIPTION "Number of messages delivered to this queue"
  201 + ::= { queueTableEntry 13 }
  202 +
195 203 exchangeTable OBJECT-TYPE
196 204 SYNTAX SEQUENCE OF ExchangeEntry
197 205 MAX-ACCESS not-accessible
@@ -253,7 +261,7 @@ exchangeAutoDelete OBJECT-TYPE
253 261
254 262 rabbitGroup OBJECT-GROUP
255 263 OBJECTS {
256   - vhostQueueCount, vhostExchangeCount, vhostMessageCount, queueVhost, queueName, queueDurable, queueAutoDelete, queueMessages, queueUnAcknowledged, queueUnCommitted, queueReady, queueAcksUncommitted, queueConsumers, queueTransactions, queueMemory, vhostName, exchangeVhost, exchangeType, exchangeName, exchangeDurable, exchangeAutoDelete
  264 + vhostQueueCount, vhostExchangeCount, vhostMessageCount, queueVhost, queueName, queueDurable, queueAutoDelete, queueMessages, queueUnAcknowledged, queueUnCommitted, queueReady, queueAcksUncommitted, queueConsumers, queueTransactions, queueMemory, queueMessagesDelivered, vhostName, exchangeVhost, exchangeType, exchangeName, exchangeDurable, exchangeAutoDelete
257 265 }
258 266 STATUS current
259 267 DESCRIPTION "Groups"
10 src/rabbit_snmp_sup.erl
@@ -8,10 +8,16 @@ start_link() ->
8 8
9 9 init([]) ->
10 10 {ok, {{one_for_one, 3, 10},
11   - [{rabbit_snmp_worker,
  11 + [{rabbit_snmp_tracer,
  12 + {rabbit_snmp_tracer, start_link, []},
  13 + permanent,
  14 + 10000,
  15 + worker,
  16 + [rabbit_snmp_tracer]},
  17 + {rabbit_snmp_worker,
12 18 {rabbit_snmp_worker, start_link, []},
13 19 permanent,
14 20 10000,
15 21 worker,
16 22 [rabbit_snmp_worker]}
17   - ]}}.
  23 + ]}}.
76 src/rabbit_snmp_tracer.erl
... ... @@ -0,0 +1,76 @@
  1 +-module(rabbit_snmp_tracer).
  2 +-behaviour(gen_server).
  3 +
  4 +-export([start/0, start/2, stop/0, stop/1, start_link/0]).
  5 +-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
  6 +
  7 +-export([start_trace/1, stop_trace/1]).
  8 +
  9 +-record(state, {table}).
  10 +
  11 +start() ->
  12 + start_link(),
  13 + ok.
  14 +
  15 +start(normal, []) ->
  16 + start_link().
  17 +
  18 +stop() ->
  19 + ok.
  20 +
  21 +stop(_State) ->
  22 + stop().
  23 +
  24 +start_link() ->
  25 + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
  26 +
  27 +init([]) ->
  28 + Table = ets:new(queue_throughput_stats, []),
  29 + {ok, #state{table = Table}}.
  30 +
  31 +handle_call({start_trace, Pid}, _From, State) ->
  32 + ets:insert(State#state.table, {Pid, 0}),
  33 + erlang:trace(Pid, true, [{tracer, self()}, 'receive']),
  34 + {reply, ok, State};
  35 +
  36 +handle_call({stop_trace, Pid}, _From, State) ->
  37 + ets:delete(State#state.table, Pid),
  38 + erlang:trace(Pid, false, [{tracer, self()}, 'receive']),
  39 + {reply, ok, State};
  40 +
  41 +handle_call({get_count, Pid}, _From, State) ->
  42 + Result = case ets:lookup(State#state.table, Pid) of
  43 + [] -> no_stats;
  44 + [{Pid, Count}] -> Count
  45 + end,
  46 + {reply, Result, State};
  47 +
  48 +handle_call(_Msg,_From,State) ->
  49 + %io:format("Call: ~p~nState: ~p~n", [Msg, State]),
  50 + {reply, unknown_command, State}.
  51 +
  52 +handle_cast(_Msg,State) ->
  53 + %io:format("Cast: ~p~nState: ~p~n", [Msg, State]),
  54 + {noreply, State}.
  55 +
  56 +handle_info({trace, Pid, 'receive', {'$gen_cast', {deliver,_,_,_}}}, State) ->
  57 + ets:update_counter(State#state.table, Pid, 1),
  58 + {noreply, State};
  59 +
  60 +handle_info(_Info, State) ->
  61 + {noreply, State}.
  62 +
  63 +start_trace(Pid) ->
  64 + io:format("Starting Trace of: ~p~n", [Pid]),
  65 + gen_server:call(?MODULE, {start_trace, Pid}).
  66 +
  67 +stop_trace(Pid) ->
  68 + io:format("Stopping Trace of: ~p~n", [Pid]),
  69 + gen_server:call(?MODULE, {stop_trace, Pid}).
  70 +
  71 +terminate(_,_State) ->
  72 + ok.
  73 +
  74 +code_change(_OldVsn, State, _Extra) ->
  75 + {ok, State}.
  76 +
15 src/rabbit_snmp_worker.erl
@@ -21,11 +21,14 @@ stop(_State) ->
21 21 stop().
22 22
23 23 start_link() ->
24   - gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).
  24 + gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
25 25
26 26 init([]) ->
27 27 application:start(snmp),
28   - {ok, UpdateInterval} = application:get_env(rabbit_snmp, update_interval),
  28 + UpdateInterval = case application:get_env(rabbit_snmp, update_interval) of
  29 + undefined -> 1000;
  30 + Value -> Value
  31 + end,
29 32 io:format("Started snmp state poller w/~pms interval~n", [UpdateInterval]),
30 33 erlang:send_after(1, self(), update_stats),
31 34 {ok, #state{update_interval = UpdateInterval}}.
@@ -60,6 +63,11 @@ create_queue_row([Row|Rest]) ->
60 63 {resource, Vhost, queue, QueueName} = proplists:get_value(name, Row),
61 64 ListVhost = binary_to_list(Vhost),
62 65 ListQueue = binary_to_list(QueueName),
  66 + QueuePid = proplists:get_value(pid, Row),
  67 + MessagesSent = case gen_server:call(rabbit_snmp_tracer, {get_count, QueuePid}) of
  68 + no_stats -> gen_server:call(rabbit_snmp_tracer, {start_trace, QueuePid}), 0;
  69 + Count -> Count
  70 + end,
63 71
64 72 SnmpRow = {ListVhost, ListQueue,
65 73 proplists:get_value(durable, Row),
@@ -71,7 +79,8 @@ create_queue_row([Row|Rest]) ->
71 79 proplists:get_value(acks_uncommitted, Row),
72 80 proplists:get_value(consumers, Row),
73 81 proplists:get_value(transactions, Row),
74   - proplists:get_value(memory, Row)
  82 + proplists:get_value(memory, Row),
  83 + MessagesSent
75 84 },
76 85
77 86 snmpa_local_db:table_create_row(queueTable, ListVhost ++ ListQueue, SnmpRow),

0 comments on commit a0fd1ce

Please sign in to comment.
Something went wrong with that request. Please try again.