diff options
| author | Diana Corbacho <diana@rabbitmq.com> | 2019-06-10 21:40:49 +0100 |
|---|---|---|
| committer | Diana Corbacho <diana@rabbitmq.com> | 2019-06-10 21:50:36 +0100 |
| commit | 1e771b0df2d2a93a7c246a7845656a110d3927c1 (patch) | |
| tree | 73628e42cdfef936946ced07d962a0934c4847cf | |
| parent | f613fd0372e1a89b9991534f0bae3553f345de4c (diff) | |
| download | rabbitmq-server-git-1e771b0df2d2a93a7c246a7845656a110d3927c1.tar.gz | |
Queue, connection and exchange count functions
Connection lookup using tracking tables.
Used in the management only HTTP API with all stats disabled
[#166445368]
| -rw-r--r-- | src/rabbit_amqqueue.erl | 6 | ||||
| -rw-r--r-- | src/rabbit_connection_tracking.erl | 26 | ||||
| -rw-r--r-- | src/rabbit_exchange.erl | 7 |
3 files changed, 37 insertions, 2 deletions
diff --git a/src/rabbit_amqqueue.erl b/src/rabbit_amqqueue.erl index 85c647ae8c..bfacef6d49 100644 --- a/src/rabbit_amqqueue.erl +++ b/src/rabbit_amqqueue.erl @@ -30,6 +30,7 @@ -export([list/0, list/1, info_keys/0, info/1, info/2, info_all/1, info_all/2, emit_info_all/5, list_local/1, info_local/1, emit_info_local/4, emit_info_down/4]). +-export([count/0]). -export([list_down/1, count/1, list_names/0, list_names/1, list_local_names/0, list_with_possible_retry/1]). -export([list_by_type/1]). @@ -794,6 +795,11 @@ list() -> do_list() -> mnesia:dirty_match_object(rabbit_queue, amqqueue:pattern_match_all()). +-spec count() -> non_neg_integer(). + +count() -> + mnesia:table_info(rabbit_queue, size). + -spec list_names() -> [rabbit_amqqueue:name()]. list_names() -> mnesia:dirty_all_keys(rabbit_queue). diff --git a/src/rabbit_connection_tracking.erl b/src/rabbit_connection_tracking.erl index aa5eb15464..88951eabe9 100644 --- a/src/rabbit_connection_tracking.erl +++ b/src/rabbit_connection_tracking.erl @@ -39,7 +39,9 @@ list/0, list/1, list_on_node/1, list_on_node/2, list_of_user/1, tracked_connection_from_connection_created/1, tracked_connection_from_connection_state/1, - count_connections_in/1]). + count_connections_in/1, + lookup/1, + count/0]). -include_lib("rabbit.hrl"). @@ -287,6 +289,20 @@ unregister_connection(ConnId = {Node, _Name}) when Node =:= node() -> mnesia:dirty_delete(TableName, ConnId) end. +-spec lookup(rabbit_types:connection_name()) -> rabbit_types:tracked_connection() | 'not_found'. + +lookup(Name) -> + Nodes = rabbit_mnesia:cluster_nodes(running), + lookup(Name, Nodes). + +lookup(_, []) -> + not_found; +lookup(Name, [Node | Nodes]) -> + TableName = tracked_connection_table_name_for(Node), + case mnesia:dirty_read(TableName, {Node, Name}) of + [] -> lookup(Name, Nodes); + [Row] -> Row + end. -spec list() -> [rabbit_types:tracked_connection()]. @@ -297,6 +313,14 @@ list() -> Acc ++ mnesia:dirty_match_object(Tab, #tracked_connection{_ = '_'}) end, [], rabbit_mnesia:cluster_nodes(running)). +-spec count() -> non_neg_integer(). + +count() -> + lists:foldl( + fun (Node, Acc) -> + Tab = tracked_connection_table_name_for(Node), + Acc + mnesia:table_info(Tab, size) + end, 0, rabbit_mnesia:cluster_nodes(running)). -spec list(rabbit_types:vhost()) -> [rabbit_types:tracked_connection()]. diff --git a/src/rabbit_exchange.erl b/src/rabbit_exchange.erl index b4ba89ca08..86c11c4ad2 100644 --- a/src/rabbit_exchange.erl +++ b/src/rabbit_exchange.erl @@ -23,7 +23,7 @@ lookup/1, lookup_or_die/1, list/0, list/1, lookup_scratch/2, update_scratch/3, update_decorators/1, immutable/1, info_keys/0, info/1, info/2, info_all/1, info_all/2, info_all/4, - route/2, delete/3, validate_binding/2]). + route/2, delete/3, validate_binding/2, count/0]). -export([list_names/0]). %% these must be run inside a mnesia tx -export([maybe_auto_delete/2, serial/1, peek_serial/1, update/2]). @@ -238,6 +238,11 @@ lookup_or_die(Name) -> list() -> mnesia:dirty_match_object(rabbit_exchange, #exchange{_ = '_'}). +-spec count() -> non_neg_integer(). + +count() -> + mnesia:table_info(rabbit_exchange, size). + -spec list_names() -> [rabbit_exchange:name()]. list_names() -> mnesia:dirty_all_keys(rabbit_exchange). |
