Go back to getting static queue details from Mnesia, allow filtering queue list by vhost.
This commit is contained in:
parent
dce819ab2f
commit
8c88f60c27
|
|
@ -74,7 +74,7 @@ function link_vhost(name) {
|
|||
}
|
||||
|
||||
function link_user(name) {
|
||||
return link_to(name, '#/user/' + esc(name))
|
||||
return link_to(name, '#/users/' + esc(name))
|
||||
}
|
||||
|
||||
function link_to(name, url) {
|
||||
|
|
|
|||
|
|
@ -58,6 +58,8 @@ dispatcher() ->
|
|||
{["json","exchanges", vhost], rabbit_mgmt_wm_exchanges, []},
|
||||
{["json","exchanges", vhost, exchange],rabbit_mgmt_wm_exchange, []},
|
||||
{["json","queues"], rabbit_mgmt_wm_queues, []},
|
||||
{["json","queues", vhost], rabbit_mgmt_wm_queues, []},
|
||||
%% {["json","queues", vhost, queue], rabbit_mgmt_wm_queue, []},
|
||||
{["json","vhosts"], rabbit_mgmt_wm_vhosts, []},
|
||||
{["json","vhosts", vhost], rabbit_mgmt_wm_vhost, []},
|
||||
{["json","users"], rabbit_mgmt_wm_users, []},
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
-export([start/0]).
|
||||
|
||||
-export([get_queues/0, get_connections/0, get_connection/1,
|
||||
-export([get_queues/1, get_connections/0, get_connection/1,
|
||||
get_overview/0, get_channels/0]).
|
||||
|
||||
-export([group_sum/2]).
|
||||
|
|
@ -51,8 +51,8 @@
|
|||
start() ->
|
||||
gen_event:add_sup_handler(rabbit_event, ?MODULE, []).
|
||||
|
||||
get_queues() ->
|
||||
gen_event:call(rabbit_event, ?MODULE, get_queues, infinity).
|
||||
get_queues(Qs) ->
|
||||
gen_event:call(rabbit_event, ?MODULE, {get_queues, Qs}, infinity).
|
||||
|
||||
get_connections() ->
|
||||
gen_event:call(rabbit_event, ?MODULE, get_connections, infinity).
|
||||
|
|
@ -175,7 +175,7 @@ augment_connection_pid(Pid, Tables) ->
|
|||
|
||||
%% augment_queue_pid(Pid, Tables) ->
|
||||
%% Q = lookup_element(
|
||||
%% orddict:fetch(queue_stats, Tables),
|
||||
%% orddict:fetch(queue_stats, Tables), NB this won't work any more
|
||||
%% {Pid, create}),
|
||||
%% [{name, pget(name, Q)},
|
||||
%% {vhost, pget(vhost, Q)}].
|
||||
|
|
@ -195,11 +195,13 @@ init([]) ->
|
|||
orddict:from_list(
|
||||
[{Key, ets:new(anon, [private])} || Key <- ?TABLES])}}.
|
||||
|
||||
handle_call(get_queues, State = #state{tables = Tables}) ->
|
||||
handle_call({get_queues, Qs0}, State = #state{tables = Tables}) ->
|
||||
Table = orddict:fetch(queue_stats, Tables),
|
||||
{ok, [augment(Q,
|
||||
[{owner_pid, fun augment_connection_pid/2}],
|
||||
Tables) || Q <- merge_created_stats(Table)], State};
|
||||
Qs1 = [queue_to_list(Q) || Q <- Qs0],
|
||||
Qs2 = merge_created_stats(Qs1, Table),
|
||||
Qs3 = [augment(Q, [{owner_pid, fun augment_connection_pid/2}],
|
||||
Tables) || Q <- Qs2],
|
||||
{ok, Qs3, State};
|
||||
|
||||
handle_call(get_connections, State = #state{tables = Tables}) ->
|
||||
Table = orddict:fetch(connection_stats, Tables),
|
||||
|
|
@ -226,12 +228,6 @@ handle_call(get_overview, State = #state{tables = Tables}) ->
|
|||
handle_call(_Request, State) ->
|
||||
{ok, not_understood, State}.
|
||||
|
||||
handle_event(#event{type = queue_created, props = Stats}, State) ->
|
||||
handle_created(
|
||||
queue_stats, Stats,
|
||||
[{fun rabbit_mgmt_format:pid/1, [pid, owner_pid]},
|
||||
{fun rabbit_mgmt_format:resource/1, [name]}], State);
|
||||
|
||||
handle_event(#event{type = queue_stats, props = Stats, timestamp = Timestamp},
|
||||
State) ->
|
||||
handle_stats(
|
||||
|
|
@ -358,8 +354,12 @@ fine_stats_key(ChPid, QPid) when is_pid(QPid) -> {ChPid, id(QPid)};
|
|||
fine_stats_key(ChPid, X) -> {ChPid, X}.
|
||||
|
||||
merge_created_stats(Table) ->
|
||||
[Stats ++ lookup_element(Table, {Pid, stats}) ||
|
||||
{{Pid, create}, Stats, _Name} <- ets:tab2list(Table)].
|
||||
merge_created_stats(
|
||||
[Facts || {{_, create}, Facts, _Name} <- ets:tab2list(Table)],
|
||||
Table).
|
||||
|
||||
merge_created_stats(In, Table) ->
|
||||
[Facts ++ lookup_element(Table, {pget(pid, Facts), stats}) || Facts <- In].
|
||||
|
||||
get_fine_stats(Type, GroupBy, Tables) ->
|
||||
Table = orddict:fetch(Type, Tables),
|
||||
|
|
@ -391,3 +391,19 @@ merge_fine_stats0(Props, Dict) ->
|
|||
proplists:delete(message_stats, Props)];
|
||||
error -> Props
|
||||
end.
|
||||
|
||||
queue_to_list(#amqqueue{name = Name, durable = Durable,
|
||||
auto_delete = AutoDelete,
|
||||
exclusive_owner = ExclusiveOwner,
|
||||
arguments = Arguments,
|
||||
pid = Pid }) ->
|
||||
rabbit_mgmt_format:format(
|
||||
[{durable, Durable},
|
||||
{name, Name},
|
||||
{auto_delete, AutoDelete},
|
||||
{owner_pid, ExclusiveOwner},
|
||||
{arguments, Arguments},
|
||||
{pid, Pid}],
|
||||
[{fun rabbit_mgmt_format:pid/1, [pid, owner_pid]},
|
||||
{fun rabbit_mgmt_format:resource/1, [name]},
|
||||
{fun rabbit_mgmt_format:table/1, [arguments]}]).
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
-export([is_authorized/2, now_ms/0, http_date/0, vhost/1, vhost_exists/1]).
|
||||
-export([bad_request/3, id/2, decode/2, flatten/1, parse_bool/1]).
|
||||
-export([with_decode/4, not_found/3, not_authorised/3, amqp_request/3]).
|
||||
-export([all_or_one_vhost/2]).
|
||||
|
||||
-include("rabbit_mgmt.hrl").
|
||||
-include_lib("amqp_client/include/amqp_client.hrl").
|
||||
|
|
@ -171,3 +172,14 @@ amqp_request(VHost, Context, Method) ->
|
|||
exit:{{server_initiated_close, Code, Reason}, _} ->
|
||||
throw({server_closed, Reason})
|
||||
end.
|
||||
|
||||
all_or_one_vhost(ReqData, Fun) ->
|
||||
case rabbit_mgmt_util:vhost(ReqData) of
|
||||
none ->
|
||||
rabbit_mgmt_util:flatten(
|
||||
[Fun(V) || V <- rabbit_access_control:list_vhosts()]);
|
||||
not_found ->
|
||||
vhost_not_found;
|
||||
VHost ->
|
||||
Fun(VHost)
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -47,14 +47,7 @@ to_json(ReqData, Context) ->
|
|||
is_authorized(ReqData, Context) ->
|
||||
rabbit_mgmt_util:is_authorized(ReqData, Context).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
exchanges(ReqData) ->
|
||||
case rabbit_mgmt_util:vhost(ReqData) of
|
||||
none ->
|
||||
rabbit_mgmt_util:flatten(
|
||||
[rabbit_exchange:info_all(V) ||
|
||||
V <- rabbit_access_control:list_vhosts()]);
|
||||
not_found ->
|
||||
vhost_not_found;
|
||||
VHost ->
|
||||
rabbit_exchange:info_all(VHost)
|
||||
end.
|
||||
rabbit_mgmt_util:all_or_one_vhost(ReqData, fun rabbit_exchange:info_all/1).
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
%%
|
||||
-module(rabbit_mgmt_wm_queues).
|
||||
|
||||
-export([init/1, to_json/2, content_types_provided/2, is_authorized/2]).
|
||||
-export([init/1, to_json/2, content_types_provided/2, is_authorized/2,
|
||||
resource_exists/2]).
|
||||
|
||||
-include("rabbit_mgmt.hrl").
|
||||
-include_lib("webmachine/include/webmachine.hrl").
|
||||
|
|
@ -33,11 +34,19 @@ init(_Config) -> {ok, #context{}}.
|
|||
content_types_provided(ReqData, Context) ->
|
||||
{[{"application/json", to_json}], ReqData, Context}.
|
||||
|
||||
resource_exists(ReqData, Context) ->
|
||||
{case queues(ReqData) of
|
||||
vhost_not_found -> false;
|
||||
_ -> true
|
||||
end, ReqData, Context}.
|
||||
|
||||
to_json(ReqData, Context) ->
|
||||
Qs = rabbit_mgmt_db:get_queues(),
|
||||
Qs0 = queues(ReqData),
|
||||
Qs = rabbit_mgmt_db:get_queues(Qs0),
|
||||
{rabbit_mgmt_format:encode(
|
||||
[{queues, [{struct, format(Q)} || Q <- Qs]}]), ReqData, Context}.
|
||||
|
||||
%% TODO move this to _db?
|
||||
format(Q) ->
|
||||
MsgsReady = rabbit_mgmt_db:pget(messages_ready, Q),
|
||||
MsgsUnacked = rabbit_mgmt_db:pget(messages_unacknowledged, Q),
|
||||
|
|
@ -45,3 +54,8 @@ format(Q) ->
|
|||
|
||||
is_authorized(ReqData, Context) ->
|
||||
rabbit_mgmt_util:is_authorized(ReqData, Context).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
queues(ReqData) ->
|
||||
rabbit_mgmt_util:all_or_one_vhost(ReqData, fun rabbit_amqqueue:list/1).
|
||||
|
|
|
|||
Loading…
Reference in New Issue