Skip to content
Browse files

made update interval configurable. added gitignore

  • Loading branch information...
1 parent 2ea6567 commit d9a8ee25f2ac7a5cd30c88c829c4371b02695caf @ddossot ddossot committed
Showing with 75 additions and 63 deletions.
  1. +4 −0 .gitignore
  2. +8 −0 README
  3. +63 −63 src/rabbit_snmp_worker.erl
View
4 .gitignore
@@ -0,0 +1,4 @@
+ebin
+dist
+include/RABBITMQ-MIB.hrl
+snmp/RABBITMQ-MIB.bin
View
8 README
@@ -22,6 +22,14 @@ based off of: http://www.rabbitmq.com/plugin-development.html
5: Install the dist/rabbitmq-snmp.ez plugin into your server.
+6: Add the following to you RabbitMQ configuration (usually /etc/rabbitmq/rabbitmq.config):
+
+ {rabbit_snmp,
+ [
+ % set the desired data update interval in milliseconds
+ {update_interval, 10000}
+ ]
+ },
{snmp, [
{agent, [
% db_dir will be set by the snmp plugin before it starts snmp so leave this commented out
View
126 src/rabbit_snmp_worker.erl
@@ -8,101 +8,101 @@
-record(state, {update_interval}).
start() ->
- start_link(),
- ok.
+ start_link(),
+ ok.
start(normal, []) ->
- start_link().
+ start_link().
stop() ->
- ok.
+ ok.
stop(_State) ->
- stop().
+ stop().
start_link() ->
- gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).
+ gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).
init([]) ->
- application:start(snmp),
- io:format("Started snmp state poller~n", []),
- UpdateInterval = 10000,
- erlang:send_after(1, self(), update_stats),
- {ok, #state{update_interval = UpdateInterval}}.
+ application:start(snmp),
+ {ok, UpdateInterval} = application:get_env(rabbit_snmp, update_interval),
+ io:format("Started snmp state poller w/~pms interval~n", [UpdateInterval]),
+ erlang:send_after(1, self(), update_stats),
+ {ok, #state{update_interval = UpdateInterval}}.
create_exchange_row([]) ->
- ok;
+ ok;
create_exchange_row([Row|Rest]) ->
- {exchange, {resource, Vhost, exchange, ExchangeName}, ExchangeType, ExchangeDurability, ExchangeAutoDelete, _Args} = Row,
- ListVhost = binary_to_list(Vhost),
- ListExchange = binary_to_list(ExchangeName),
-
- SnmpRow = {ListVhost, ListExchange,
- atom_to_list(ExchangeType),
- ExchangeDurability,
- ExchangeAutoDelete
- },
- snmpa_local_db:table_create_row(exchangeTable, ListVhost ++ ListExchange, SnmpRow),
- create_exchange_row(Rest).
+ {exchange, {resource, Vhost, exchange, ExchangeName}, ExchangeType, ExchangeDurability, ExchangeAutoDelete, _Args} = Row,
+ ListVhost = binary_to_list(Vhost),
+ ListExchange = binary_to_list(ExchangeName),
+
+ SnmpRow = {ListVhost, ListExchange,
+ atom_to_list(ExchangeType),
+ ExchangeDurability,
+ ExchangeAutoDelete
+ },
+ snmpa_local_db:table_create_row(exchangeTable, ListVhost ++ ListExchange, SnmpRow),
+ create_exchange_row(Rest).
create_vhost_row([]) ->
- ok;
+ ok;
create_vhost_row([Row|Rest]) ->
- SnmpRow = {binary_to_list(Row)},
- snmpa_local_db:table_create_row(vhostTable, binary_to_list(Row), SnmpRow),
- create_vhost_row(Rest).
+ SnmpRow = {binary_to_list(Row)},
+ snmpa_local_db:table_create_row(vhostTable, binary_to_list(Row), SnmpRow),
+ create_vhost_row(Rest).
create_queue_row([]) ->
- ok;
+ ok;
create_queue_row([Row|Rest]) ->
- {resource, Vhost, queue, QueueName} = proplists:get_value(name, Row),
- ListVhost = binary_to_list(Vhost),
- ListQueue = binary_to_list(QueueName),
-
- SnmpRow = {ListVhost, ListQueue,
- proplists:get_value(durable, Row),
- proplists:get_value(auto_delete, Row),
- proplists:get_value(messages, Row),
- proplists:get_value(messages_unacknowledged, Row),
- proplists:get_value(messages_uncommitted, Row),
- proplists:get_value(messages_ready, Row),
- proplists:get_value(acks_uncommitted, Row),
- proplists:get_value(consumers, Row),
- proplists:get_value(transactions, Row),
- proplists:get_value(memory, Row)
- },
-
- snmpa_local_db:table_create_row(queueTable, ListVhost ++ ListQueue, SnmpRow),
- create_queue_row(Rest).
+ {resource, Vhost, queue, QueueName} = proplists:get_value(name, Row),
+ ListVhost = binary_to_list(Vhost),
+ ListQueue = binary_to_list(QueueName),
+
+ SnmpRow = {ListVhost, ListQueue,
+ proplists:get_value(durable, Row),
+ proplists:get_value(auto_delete, Row),
+ proplists:get_value(messages, Row),
+ proplists:get_value(messages_unacknowledged, Row),
+ proplists:get_value(messages_uncommitted, Row),
+ proplists:get_value(messages_ready, Row),
+ proplists:get_value(acks_uncommitted, Row),
+ proplists:get_value(consumers, Row),
+ proplists:get_value(transactions, Row),
+ proplists:get_value(memory, Row)
+ },
+
+ snmpa_local_db:table_create_row(queueTable, ListVhost ++ ListQueue, SnmpRow),
+ create_queue_row(Rest).
update_stats() ->
- Vhosts = rabbit_access_control:list_vhosts(),
- create_vhost_row(Vhosts),
- Queues = lists:append([rabbit_amqqueue:info_all(X) || X <- Vhosts]),
- create_queue_row(Queues),
- Exchanges = lists:append([rabbit_exchange:list(X) || X <- Vhosts]),
- create_exchange_row(Exchanges),
- ok.
+ Vhosts = rabbit_access_control:list_vhosts(),
+ create_vhost_row(Vhosts),
+ Queues = lists:append([rabbit_amqqueue:info_all(X) || X <- Vhosts]),
+ create_queue_row(Queues),
+ Exchanges = lists:append([rabbit_exchange:list(X) || X <- Vhosts]),
+ create_exchange_row(Exchanges),
+ ok.
handle_call(_Msg,_From,State) ->
- {reply, unknown_command, State}.
+ {reply, unknown_command, State}.
handle_cast(_,State) ->
- {noreply, State}.
+ {noreply, State}.
handle_info(update_stats, State) ->
- update_stats(),
- erlang:send_after(State#state.update_interval, self(), update_stats),
- {noreply, State};
+ update_stats(),
+ erlang:send_after(State#state.update_interval, self(), update_stats),
+ {noreply, State};
handle_info(Info, State) ->
- io:format("Info: ~p~nState: ~p~n", [Info, State]),
- {noreply, State}.
+ io:format("Info: ~p~nState: ~p~n", [Info, State]),
+ {noreply, State}.
terminate(_,_State) ->
- ok.
+ ok.
code_change(_OldVsn, State, _Extra) ->
- {ok, State}.
+ {ok, State}.

0 comments on commit d9a8ee2

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