From commits-return-38464-archive-asf-public=cust-asf.ponee.io@couchdb.apache.org Fri Oct 11 18:08:18 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2EA3B180667 for ; Fri, 11 Oct 2019 20:08:18 +0200 (CEST) Received: (qmail 71393 invoked by uid 500); 11 Oct 2019 18:08:17 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 71267 invoked by uid 99); 11 Oct 2019 18:08:17 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 Oct 2019 18:08:16 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id D2E26811D7; Fri, 11 Oct 2019 18:08:16 +0000 (UTC) Date: Fri, 11 Oct 2019 18:08:19 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 03/03: Move get_stats/0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: rnewson@apache.org In-Reply-To: <157081729655.12547.10251144451679803150@gitbox.apache.org> References: <157081729655.12547.10251144451679803150@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/1523-bye-bye-5986-rnewson X-Git-Reftype: branch X-Git-Rev: 1f011b9779bbd617136e45417649660f310b3850 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20191011180816.D2E26811D7@gitbox.apache.org> This is an automated email from the ASF dual-hosted git repository. rnewson pushed a commit to branch 1523-bye-bye-5986-rnewson in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 1f011b9779bbd617136e45417649660f310b3850 Author: Joan Touzet AuthorDate: Fri Oct 11 18:07:10 2019 +0100 Move get_stats/0 --- src/chttpd/src/chttpd_misc.erl | 89 +---------------------------------------- src/chttpd/src/chttpd_node.erl | 91 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 90 deletions(-) diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl index a75f108..ffb5295 100644 --- a/src/chttpd/src/chttpd_misc.erl +++ b/src/chttpd/src/chttpd_misc.erl @@ -25,8 +25,7 @@ handle_utils_dir_req/2, handle_uuids_req/1, handle_welcome_req/1, - handle_welcome_req/2, - get_stats/0 + handle_welcome_req/2 ]). -include_lib("couch/include/couch_db.hrl"). @@ -273,85 +272,6 @@ handle_uuids_req(Req) -> couch_httpd_misc_handlers:handle_uuids_req(Req). -get_stats() -> - Other = erlang:memory(system) - lists:sum([X || {_,X} <- - erlang:memory([atom, code, binary, ets])]), - Memory = [{other, Other} | erlang:memory([atom, atom_used, processes, - processes_used, binary, code, ets])], - {NumberOfGCs, WordsReclaimed, _} = statistics(garbage_collection), - {{input, Input}, {output, Output}} = statistics(io), - {CF, CDU} = db_pid_stats(), - MessageQueues0 = [{couch_file, {CF}}, {couch_db_updater, {CDU}}], - MessageQueues = MessageQueues0 ++ message_queues(registered()), - [ - {uptime, couch_app:uptime() div 1000}, - {memory, {Memory}}, - {run_queue, statistics(run_queue)}, - {ets_table_count, length(ets:all())}, - {context_switches, element(1, statistics(context_switches))}, - {reductions, element(1, statistics(reductions))}, - {garbage_collection_count, NumberOfGCs}, - {words_reclaimed, WordsReclaimed}, - {io_input, Input}, - {io_output, Output}, - {os_proc_count, couch_proc_manager:get_proc_count()}, - {stale_proc_count, couch_proc_manager:get_stale_proc_count()}, - {process_count, erlang:system_info(process_count)}, - {process_limit, erlang:system_info(process_limit)}, - {message_queues, {MessageQueues}}, - {internal_replication_jobs, mem3_sync:get_backlog()}, - {distribution, {get_distribution_stats()}} - ]. - -db_pid_stats() -> - {monitors, M} = process_info(whereis(couch_stats_process_tracker), monitors), - Candidates = [Pid || {process, Pid} <- M], - CouchFiles = db_pid_stats(couch_file, Candidates), - CouchDbUpdaters = db_pid_stats(couch_db_updater, Candidates), - {CouchFiles, CouchDbUpdaters}. - -db_pid_stats(Mod, Candidates) -> - Mailboxes = lists:foldl( - fun(Pid, Acc) -> - case process_info(Pid, [message_queue_len, dictionary]) of - undefined -> - Acc; - PI -> - Dictionary = proplists:get_value(dictionary, PI, []), - case proplists:get_value('$initial_call', Dictionary) of - {Mod, init, 1} -> - case proplists:get_value(message_queue_len, PI) of - undefined -> Acc; - Len -> [Len|Acc] - end; - _ -> - Acc - end - end - end, [], Candidates - ), - format_pid_stats(Mailboxes). - -format_pid_stats([]) -> - []; -format_pid_stats(Mailboxes) -> - Sorted = lists:sort(Mailboxes), - Count = length(Sorted), - [ - {count, Count}, - {min, hd(Sorted)}, - {max, lists:nth(Count, Sorted)}, - {'50', lists:nth(round(Count * 0.5), Sorted)}, - {'90', lists:nth(round(Count * 0.9), Sorted)}, - {'99', lists:nth(round(Count * 0.99), Sorted)} - ]. - -get_distribution_stats() -> - lists:map(fun({Node, Socket}) -> - {ok, Stats} = inet:getstat(Socket), - {Node, {Stats}} - end, erlang:system_info(dist_ctrl)). - handle_up_req(#httpd{method='GET'} = Req) -> case config:get("couchdb", "maintenance_mode") of "true" -> @@ -371,13 +291,6 @@ handle_up_req(#httpd{method='GET'} = Req) -> handle_up_req(Req) -> send_method_not_allowed(Req, "GET,HEAD"). -message_queues(Registered) -> - lists:map(fun(Name) -> - Type = message_queue_len, - {Type, Length} = process_info(whereis(Name), Type), - {Name, Length} - end, Registered). - get_docroot() -> % if the env var isn’t set, let’s not throw an error, but % assume the current working dir is what we want diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl index 0f0b7e9..6381a4e 100644 --- a/src/chttpd/src/chttpd_node.erl +++ b/src/chttpd/src/chttpd_node.erl @@ -13,7 +13,8 @@ -module(chttpd_node). -export([ - handle_node_req/1 + handle_node_req/1, + get_stats/0 ]). -include_lib("couch/include/couch_db.hrl"). @@ -104,7 +105,7 @@ handle_node_req(#httpd{path_parts=[_, _Node, <<"_stats">>]}=Req) -> send_method_not_allowed(Req, "GET"); % GET /_node/$node/_system handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_system">>]}=Req) -> - Stats = call_node(Node, chttpd_misc, get_stats, []), + Stats = call_node(Node, chttpd_node, get_stats, []), EJSON = couch_stats_httpd:to_ejson(Stats), send_json(Req, EJSON); handle_node_req(#httpd{path_parts=[_, _Node, <<"_system">>]}=Req) -> @@ -147,3 +148,89 @@ flush(Node, Req) -> _Else -> ok end. + +get_stats() -> + Other = erlang:memory(system) - lists:sum([X || {_,X} <- + erlang:memory([atom, code, binary, ets])]), + Memory = [{other, Other} | erlang:memory([atom, atom_used, processes, + processes_used, binary, code, ets])], + {NumberOfGCs, WordsReclaimed, _} = statistics(garbage_collection), + {{input, Input}, {output, Output}} = statistics(io), + {CF, CDU} = db_pid_stats(), + MessageQueues0 = [{couch_file, {CF}}, {couch_db_updater, {CDU}}], + MessageQueues = MessageQueues0 ++ message_queues(registered()), + [ + {uptime, couch_app:uptime() div 1000}, + {memory, {Memory}}, + {run_queue, statistics(run_queue)}, + {ets_table_count, length(ets:all())}, + {context_switches, element(1, statistics(context_switches))}, + {reductions, element(1, statistics(reductions))}, + {garbage_collection_count, NumberOfGCs}, + {words_reclaimed, WordsReclaimed}, + {io_input, Input}, + {io_output, Output}, + {os_proc_count, couch_proc_manager:get_proc_count()}, + {stale_proc_count, couch_proc_manager:get_stale_proc_count()}, + {process_count, erlang:system_info(process_count)}, + {process_limit, erlang:system_info(process_limit)}, + {message_queues, {MessageQueues}}, + {internal_replication_jobs, mem3_sync:get_backlog()}, + {distribution, {get_distribution_stats()}} + ]. + +db_pid_stats() -> + {monitors, M} = process_info(whereis(couch_stats_process_tracker), monitors), + Candidates = [Pid || {process, Pid} <- M], + CouchFiles = db_pid_stats(couch_file, Candidates), + CouchDbUpdaters = db_pid_stats(couch_db_updater, Candidates), + {CouchFiles, CouchDbUpdaters}. + +db_pid_stats(Mod, Candidates) -> + Mailboxes = lists:foldl( + fun(Pid, Acc) -> + case process_info(Pid, [message_queue_len, dictionary]) of + undefined -> + Acc; + PI -> + Dictionary = proplists:get_value(dictionary, PI, []), + case proplists:get_value('$initial_call', Dictionary) of + {Mod, init, 1} -> + case proplists:get_value(message_queue_len, PI) of + undefined -> Acc; + Len -> [Len|Acc] + end; + _ -> + Acc + end + end + end, [], Candidates + ), + format_pid_stats(Mailboxes). + +format_pid_stats([]) -> + []; +format_pid_stats(Mailboxes) -> + Sorted = lists:sort(Mailboxes), + Count = length(Sorted), + [ + {count, Count}, + {min, hd(Sorted)}, + {max, lists:nth(Count, Sorted)}, + {'50', lists:nth(round(Count * 0.5), Sorted)}, + {'90', lists:nth(round(Count * 0.9), Sorted)}, + {'99', lists:nth(round(Count * 0.99), Sorted)} + ]. + +get_distribution_stats() -> + lists:map(fun({Node, Socket}) -> + {ok, Stats} = inet:getstat(Socket), + {Node, {Stats}} + end, erlang:system_info(dist_ctrl)). + +message_queues(Registered) -> + lists:map(fun(Name) -> + Type = message_queue_len, + {Type, Length} = process_info(whereis(Name), Type), + {Name, Length} + end, Registered).