You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/28 13:59:36 UTC

[13/50] chttpd commit: updated refs/heads/master to 58020ab

Return stats for couch_file mailboxes in _system requests


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/6c1f455e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/6c1f455e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/6c1f455e

Branch: refs/heads/master
Commit: 6c1f455e8c3a00b856f3be487e1837c0de87b4ed
Parents: d98c857
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Fri Aug 2 13:27:52 2013 -0700
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 29 18:02:57 2014 +0100

----------------------------------------------------------------------
 src/chttpd_misc.erl | 38 ++++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6c1f455e/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 75f2676..62cd903 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -266,6 +266,8 @@ handle_system_req(Req) ->
         processes_used, binary, code, ets])],
     {NumberOfGCs, WordsReclaimed, _} = statistics(garbage_collection),
     {{input, Input}, {output, Output}} = statistics(io),
+    CouchFile = {couch_file, {couch_file_stats()}},
+    MessageQueues = [CouchFile|message_queues(registered())],
     send_json(Req, {[
         {uptime, element(1,statistics(wall_clock)) div 1000},
         {memory, {Memory}},
@@ -281,11 +283,40 @@ handle_system_req(Req) ->
         {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, message_queues(registered())},
+        {message_queues, {MessageQueues}},
         {internal_replication_jobs, mem3_sync:get_backlog()},
         {distribution, {get_distribution_stats()}}
     ]}).
 
+couch_file_stats() ->
+    {monitors, M} = process_info(whereis(couch_stats_collector), monitors),
+    Candidates = [Pid || {process, Pid} <- M],
+    Mailboxes = lists:foldl(
+        fun(Pid, Acc) ->
+            PI = process_info(Pid, [message_queue_len, dictionary]),
+            Dictionary = proplists:get_value(dictionary, PI, []),
+            case proplists:get_value('$initial_call', Dictionary) of
+                {couch_file, init, 1} ->
+                    case proplists:get_value(message_queue_len, PI) of
+                        undefined -> Acc;
+                        Len -> [Len|Acc]
+                    end;
+                _  ->
+                    Acc
+            end
+        end, [], Candidates
+    ),
+    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),
@@ -306,9 +337,8 @@ handle_up_req(Req) ->
     send_method_not_allowed(Req, "GET,HEAD").
 
 message_queues(Registered) ->
-    Queues = lists:map(fun(Name) ->
+    lists:map(fun(Name) ->
         Type = message_queue_len,
         {Type, Length} = process_info(whereis(Name), Type),
         {Name, Length}
-    end, Registered),
-    {Queues}.
+    end, Registered).