diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2011-05-20 14:51:57 +0100 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2011-05-20 14:51:57 +0100 |
commit | 48839e8428559495ec7d9b43068a5caef3ca4418 (patch) | |
tree | a840e37e08f2316bcc5b6d1dbedaf2ca3cce7a29 | |
parent | 7effbff31ee2cee9b2a543ab10e210e74e80129d (diff) | |
download | rabbitmq-server-48839e8428559495ec7d9b43068a5caef3ca4418.tar.gz |
Rewrite the rabbitmqctl interface. Define trace_exchanges in rabbit.app.
-rw-r--r-- | docs/rabbitmqctl.1.xml | 41 | ||||
-rw-r--r-- | ebin/rabbit_app.in | 1 | ||||
-rw-r--r-- | src/rabbit.erl | 16 | ||||
-rw-r--r-- | src/rabbit_control.erl | 24 | ||||
-rw-r--r-- | src/rabbit_trace.erl | 34 |
5 files changed, 46 insertions, 70 deletions
diff --git a/docs/rabbitmqctl.1.xml b/docs/rabbitmqctl.1.xml index 62869158..0e212f10 100644 --- a/docs/rabbitmqctl.1.xml +++ b/docs/rabbitmqctl.1.xml @@ -1266,59 +1266,38 @@ </refsect2> <refsect2> - <title>Configuration variables</title> - <para> - Some configuration values can be changed at run time. Note - that this does not apply to all variables; many are only read - at startup - changing them will have no effect. - </para> + <title>Message Tracing</title> <variablelist> <varlistentry> - <term><cmdsynopsis><command>set_env</command> <arg choice="req"><replaceable>variable</replaceable></arg> <arg choice="req"><replaceable>value</replaceable></arg></cmdsynopsis></term> + <term><cmdsynopsis><command>start_tracing</command> <arg choice="opt">-p <replaceable>vhost</replaceable></arg> <arg choice="req"><replaceable>exchange</replaceable></arg></cmdsynopsis></term> <listitem> <variablelist> <varlistentry> - <term>variable</term> - <listitem><para>The name of the variable to set, as the string form of an Erlang term.</para></listitem> + <term>vhost</term> + <listitem><para>The name of the virtual host for which to start tracing.</para></listitem> </varlistentry> <varlistentry> <term>value</term> - <listitem><para>The value to set it to, as the string form of an Erlang term.</para></listitem> + <listitem><para>The name of the exchange to which trace messages should be published.</para></listitem> </varlistentry> </variablelist> <para> - Set the value of a configuration variable. + Starts tracing. </para> </listitem> </varlistentry> <varlistentry> - <term><cmdsynopsis><command>get_env</command> <arg choice="req"><replaceable>variable</replaceable></arg></cmdsynopsis></term> + <term><cmdsynopsis><command>stop_tracing</command> <arg choice="opt">-p <replaceable>vhost</replaceable></arg></cmdsynopsis></term> <listitem> <variablelist> <varlistentry> - <term>variable</term> - <listitem><para>The name of the variable to get, as the string form of an Erlang term.</para></listitem> - </varlistentry> - </variablelist> - <para> - Get the value of a configuration variable, printing either - {ok,<command>Value</command>} or undefined. - </para> - </listitem> - </varlistentry> - - <varlistentry> - <term><cmdsynopsis><command>unset_env</command> <arg choice="req"><replaceable>variable</replaceable></arg></cmdsynopsis></term> - <listitem> - <variablelist> - <varlistentry> - <term>variable</term> - <listitem><para>The name of the variable to clear, as the string form of an Erlang term.</para></listitem> + <term>vhost</term> + <listitem><para>The name of the virtual host for which to stop tracing.</para></listitem> </varlistentry> </variablelist> <para> - Clear the value of a configuration variable. + Stops tracing. </para> </listitem> </varlistentry> diff --git a/ebin/rabbit_app.in b/ebin/rabbit_app.in index 014c18b0..7972ba86 100644 --- a/ebin/rabbit_app.in +++ b/ebin/rabbit_app.in @@ -36,6 +36,7 @@ {auth_mechanisms, ['PLAIN', 'AMQPLAIN']}, {auth_backends, [rabbit_auth_backend_internal]}, {delegate_count, 16}, + {trace_exchanges, []}, {tcp_listen_options, [binary, {packet, raw}, {reuseaddr, true}, diff --git a/src/rabbit.erl b/src/rabbit.erl index 9052f2f9..e6e80b4a 100644 --- a/src/rabbit.erl +++ b/src/rabbit.erl @@ -25,8 +25,6 @@ -export([log_location/1]). --export([get_env/1, set_env/2, unset_env/1]). - %%--------------------------------------------------------------------------- %% Boot steps. -export([maybe_insert_default_data/0, boot_delegate/0, recover/0]). @@ -188,9 +186,6 @@ -spec(maybe_insert_default_data/0 :: () -> 'ok'). -spec(boot_delegate/0 :: () -> 'ok'). -spec(recover/0 :: () -> 'ok'). --spec(get_env/1 :: (atom()) -> term()). --spec(set_env/2 :: (atom(), term()) -> 'ok'). --spec(unset_env/1 :: (atom()) -> 'ok'). -endif. @@ -519,14 +514,3 @@ log_rotation_result(ok, {error, SaslLogError}) -> {error, {cannot_rotate_sasl_logs, SaslLogError}}; log_rotation_result(ok, ok) -> ok. - -get_env(Key) -> - application:get_env(rabbit, Key). - -set_env(Key, Value) -> - application:set_env(rabbit, Key, Value), - rabbit_channel:refresh_config_all(). - -unset_env(Key) -> - application:unset_env(rabbit, Key), - rabbit_channel:refresh_config_all(). diff --git a/src/rabbit_control.erl b/src/rabbit_control.erl index 5a013711..2a9dd463 100644 --- a/src/rabbit_control.erl +++ b/src/rabbit_control.erl @@ -282,18 +282,15 @@ action(list_consumers, Node, _Args, Opts, Inform) -> Other -> Other end; -action(set_env, Node, [Var, Term], _Opts, Inform) -> - Inform("Setting control variable ~s for node ~p to ~s", [Var, Node, Term]), - rpc_call(Node, rabbit, set_env, [parse(Var), parse(Term)]); +action(start_tracing, Node, [XName], Opts, Inform) -> + VHost = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)), + Inform("Starting tracing", []), + rpc_call(Node, rabbit_trace, start, [VHost, XName]); -action(get_env, Node, [Var], _Opts, Inform) -> - Inform("Getting control variable ~s for node ~p", [Var, Node]), - Val = rpc_call(Node, rabbit, get_env, [parse(Var)]), - io:format("~p~n", [Val]); - -action(unset_env, Node, [Var], _Opts, Inform) -> - Inform("Clearing control variable ~s for node ~p", [Var, Node]), - rpc_call(Node, rabbit, unset_env, [parse(Var)]); +action(stop_tracing, Node, [], Opts, Inform) -> + VHost = list_to_binary(proplists:get_value(?VHOST_OPT, Opts)), + Inform("Stopping tracing", []), + rpc_call(Node, rabbit_trace, stop, [VHost]); action(set_permissions, Node, [Username, CPerm, WPerm, RPerm], Opts, Inform) -> VHost = proplists:get_value(?VHOST_OPT, Opts), @@ -338,11 +335,6 @@ default_if_empty(List, Default) when is_list(List) -> true -> [list_to_atom(X) || X <- List] end. -parse(Str) -> - {ok, Tokens, _} = erl_scan:string(Str ++ "."), - {ok, Term} = erl_parse:parse_term(Tokens), - Term. - display_info_list(Results, InfoItemKeys) when is_list(Results) -> lists:foreach( fun (Result) -> display_row( diff --git a/src/rabbit_trace.erl b/src/rabbit_trace.erl index 09f2545d..6228c54e 100644 --- a/src/rabbit_trace.erl +++ b/src/rabbit_trace.erl @@ -16,11 +16,13 @@ -module(rabbit_trace). --export([init/1, tap_trace_in/2, tap_trace_out/2]). +-export([init/1, tap_trace_in/2, tap_trace_out/2, start/2, stop/1]). -include("rabbit.hrl"). -include("rabbit_framing.hrl"). +-define(TRACE_EXCHANGES, trace_exchanges). + %%---------------------------------------------------------------------------- -ifdef(use_specs). @@ -31,17 +33,18 @@ -spec(tap_trace_in/2 :: (rabbit_types:basic_message(), state()) -> 'ok'). -spec(tap_trace_out/2 :: (rabbit_amqqueue:qmsg(), state()) -> 'ok'). +-spec(start/2 :: (rabbit_types:vhost(), binary()) -> 'ok'). +-spec(stop/1 :: (rabbit_types:vhost()) -> 'ok'). + -endif. %%---------------------------------------------------------------------------- init(VHost) -> - case application:get_env(rabbit, trace_exchanges) of - undefined -> none; - {ok, XNs} -> case proplists:get_value(VHost, XNs, none) of - none -> none; - Name -> rabbit_misc:r(VHost, exchange, Name) - end + {ok, XNs} = application:get_env(rabbit, ?TRACE_EXCHANGES), + case proplists:get_value(VHost, XNs, none) of + none -> none; + Name -> rabbit_misc:r(VHost, exchange, Name) end. tap_trace_in(Msg = #basic_message{exchange_name = #resource{name = XName}}, @@ -54,6 +57,23 @@ tap_trace_out({#resource{name = QName}, _QPid, _QMsgId, Redelivered, Msg}, maybe_trace(TraceXN, Msg, <<"deliver">>, QName, [{<<"redelivered">>, signedint, RedeliveredNum}]). +%%---------------------------------------------------------------------------- + +start(VHost, XN) -> + update_config(fun (Xs) -> orddict:store(VHost, list_to_binary(XN), Xs) end). + +stop(VHost) -> + update_config(fun (Xs) -> orddict:erase(VHost, Xs) end). + +update_config(Fun) -> + {ok, Xs0} = application:get_env(rabbit, ?TRACE_EXCHANGES), + Xs = Fun(orddict:from_list(Xs0)), + application:set_env(rabbit, ?TRACE_EXCHANGES, Xs), + rabbit_channel:refresh_config_all(), + ok. + +%%---------------------------------------------------------------------------- + maybe_trace(none, _Msg, _RKPrefix, _RKSuffix, _Extra) -> ok; maybe_trace(XName, #basic_message{exchange_name = #resource{name = XName}}, |