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/20 15:09:14 UTC

[06/14] couch-stats commit: updated refs/heads/master to bb24add

Rename couch_stats_stats_collector to couch_stats_aggregator


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/commit/d40741a6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/tree/d40741a6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/diff/d40741a6

Branch: refs/heads/master
Commit: d40741a6556910c7cff5cf1146561f220883be82
Parents: b4543ab
Author: Benjamin Anderson <b...@banjiewen.net>
Authored: Thu Jan 16 15:16:03 2014 -0800
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Aug 19 14:48:31 2014 +0100

----------------------------------------------------------------------
 src/couch_stats.app.src             |   2 +-
 src/couch_stats.erl                 |   2 +-
 src/couch_stats_aggregator.erl      | 117 +++++++++++++++++++++++++++++++
 src/couch_stats_stats_collector.erl | 117 -------------------------------
 src/couch_stats_sup.erl             |   2 +-
 5 files changed, 120 insertions(+), 120 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d40741a6/src/couch_stats.app.src
----------------------------------------------------------------------
diff --git a/src/couch_stats.app.src b/src/couch_stats.app.src
index 4f94d46..665636e 100644
--- a/src/couch_stats.app.src
+++ b/src/couch_stats.app.src
@@ -1,7 +1,7 @@
 {application, couch_stats, [
     {description, "Simple statistics collection"},
     {vsn, git},
-    {registered, [couch_stats_stats_collector, couch_stats_process_tracker]},
+    {registered, [couch_stats_aggregator, couch_stats_process_tracker]},
     {applications, [kernel, stdlib, folsom]},
     {mod, {couch_stats_app, []}},
     {env, [

http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d40741a6/src/couch_stats.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats.erl b/src/couch_stats.erl
index f4d753a..563a67c 100644
--- a/src/couch_stats.erl
+++ b/src/couch_stats.erl
@@ -26,7 +26,7 @@ stop() ->
     application:stop(couch_stats).
 
 fetch() ->
-    couch_stats_stats_collector:fetch().
+    couch_stats_aggregator:fetch().
 
 -spec sample(any()) -> stat().
 sample(Name) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d40741a6/src/couch_stats_aggregator.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_aggregator.erl b/src/couch_stats_aggregator.erl
new file mode 100644
index 0000000..fae59f1
--- /dev/null
+++ b/src/couch_stats_aggregator.erl
@@ -0,0 +1,117 @@
+-module(couch_stats_aggregator).
+
+-behaviour(gen_server).
+
+-export([
+    fetch/0
+]).
+
+-export([
+    start_link/0,
+    init/1,
+    handle_call/3,
+    handle_cast/2,
+    handle_info/2,
+    code_change/3,
+    terminate/2
+]).
+
+-record(st, {
+    descriptions,
+    stats,
+    collect_timer,
+    reload_timer
+}).
+
+fetch() ->
+    {ok, Stats} = gen_server:call(?MODULE, fetch),
+    Stats.
+
+start_link() ->
+    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
+
+init([]) ->
+    {ok, Descs} = reload_metrics(),
+    Interval = case application:get_env(couch_stats, collection_interval) of
+        {ok, I} -> I * 1000
+    end,
+    {ok, CT} = timer:send_interval(Interval, self(), collect),
+    {ok, RT} = timer:send_interval(600000, self(), reload),
+    {ok, #st{descriptions=Descs, stats=[], collect_timer=CT, reload_timer=RT}}.
+
+handle_call(fetch, _from, #st{stats = Stats}=State) ->
+    {reply, {ok, Stats}, State};
+handle_call(Msg, _From, State) ->
+    {stop, {unknown_call, Msg}, error, State}.
+
+handle_cast(Msg, State) ->
+    {stop, {unknown_cast, Msg}, State}.
+
+handle_info(collect, #st{descriptions=Descriptions}=State) ->
+    Stats = lists:map(
+        fun({Name, Props}) ->
+            {Name, [{value, couch_stats:sample(Name)}|Props]}
+        end,
+        Descriptions
+    ),
+    {noreply, State#st{stats=Stats}};
+handle_info(reload, State) ->
+    {ok, Descriptions} = reload_metrics(),
+    {noreply, State#st{descriptions=Descriptions}};
+handle_info(Msg, State) ->
+    {stop, {unknown_info, Msg}, State}.
+
+terminate(_Reason, _State) ->
+    ok.
+
+code_change(_OldVsn, State, _Extra) ->
+    {ok, State}.
+
+reload_metrics() ->
+    Existing = couch_stats:list(),
+    Current = load_metrics_for_applications(),
+    ToDelete = lists:foldl(
+        fun({_, {Name, [{type, Type}, _]}}, Acc) ->
+            E = {Name, [{type, Type}]},
+            case sets:is_element(E, Acc) of
+                true ->
+                    sets:del_element(E, Acc);
+                false ->
+                    couch_stats:new(Type, Name),
+                    Acc
+            end
+        end,
+        sets:from_list(Existing),
+        Current
+    ),
+    lists:foreach(
+        fun({Name, _}) -> couch_stats:delete(Name) end,
+        sets:to_list(ToDelete)
+    ),
+    {ok, Current}.
+
+load_metrics_for_applications() ->
+    Apps = [element(1, A) || A <- application:which_applications()],
+    lists:foldl(
+        fun(AppName, Acc) ->
+            case load_metrics_for_application(AppName) of
+                error -> Acc;
+                Descriptions -> [{AppName, Descriptions}|Acc]
+            end
+        end,
+        [],
+        Apps
+    ).
+
+load_metrics_for_application(AppName) ->
+    case code:priv_dir(AppName) of
+        {error, _Error} ->
+            error;
+        Dir ->
+            case file:consult(Dir ++ "/stat_descriptions.cfg") of
+                {ok, Descriptions} ->
+                    Descriptions;
+                {error, _Error} ->
+                    error
+            end
+    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d40741a6/src/couch_stats_stats_collector.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_stats_collector.erl b/src/couch_stats_stats_collector.erl
deleted file mode 100644
index 3176cf5..0000000
--- a/src/couch_stats_stats_collector.erl
+++ /dev/null
@@ -1,117 +0,0 @@
--module(couch_stats_stats_collector).
-
--behaviour(gen_server).
-
--export([
-    fetch/0
-]).
-
--export([
-    start_link/0,
-    init/1,
-    handle_call/3,
-    handle_cast/2,
-    handle_info/2,
-    code_change/3,
-    terminate/2
-]).
-
--record(st, {
-    descriptions,
-    stats,
-    collect_timer,
-    reload_timer
-}).
-
-fetch() ->
-    {ok, Stats} = gen_server:call(?MODULE, fetch),
-    Stats.
-
-start_link() ->
-    gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-init([]) ->
-    {ok, Descs} = reload_metrics(),
-    Interval = case application:get_env(couch_stats, collection_interval) of
-        {ok, I} -> I * 1000
-    end,
-    {ok, CT} = timer:send_interval(Interval, self(), collect),
-    {ok, RT} = timer:send_interval(600000, self(), reload),
-    {ok, #st{descriptions=Descs, stats=[], collect_timer=CT, reload_timer=RT}}.
-
-handle_call(fetch, _from, #st{stats = Stats}=State) ->
-    {reply, {ok, Stats}, State};
-handle_call(Msg, _From, State) ->
-    {stop, {unknown_call, Msg}, error, State}.
-
-handle_cast(Msg, State) ->
-    {stop, {unknown_cast, Msg}, State}.
-
-handle_info(collect, #st{descriptions=Descriptions}=State) ->
-    Stats = lists:map(
-        fun({Name, Props}) ->
-            {Name, [{value, couch_stats:sample(Name)}|Props]}
-        end,
-        Descriptions
-    ),
-    {noreply, State#st{stats=Stats}};
-handle_info(reload, State) ->
-    {ok, Descriptions} = reload_metrics(),
-    {noreply, State#st{descriptions=Descriptions}};
-handle_info(Msg, State) ->
-    {stop, {unknown_info, Msg}, State}.
-
-terminate(_Reason, _State) ->
-    ok.
-
-code_change(_OldVsn, State, _Extra) ->
-    {ok, State}.
-
-reload_metrics() ->
-    Existing = couch_stats:list(),
-    Current = load_metrics_for_applications(),
-    ToDelete = lists:foldl(
-        fun({_, {Name, [{type, Type}, _]}}, Acc) ->
-            E = {Name, [{type, Type}]},
-            case sets:is_element(E, Acc) of
-                true ->
-                    sets:del_element(E, Acc);
-                false ->
-                    couch_stats:new(Type, Name),
-                    Acc
-            end
-        end,
-        sets:from_list(Existing),
-        Current
-    ),
-    lists:foreach(
-        fun({Name, _}) -> couch_stats:delete(Name) end,
-        sets:to_list(ToDelete)
-    ),
-    {ok, Current}.
-
-load_metrics_for_applications() ->
-    Apps = [element(1, A) || A <- application:which_applications()],
-    lists:foldl(
-        fun(AppName, Acc) ->
-            case load_metrics_for_application(AppName) of
-                error -> Acc;
-                Descriptions -> [{AppName, Descriptions}|Acc]
-            end
-        end,
-        [],
-        Apps
-    ).
-
-load_metrics_for_application(AppName) ->
-    case code:priv_dir(AppName) of
-        {error, _Error} ->
-            error;
-        Dir ->
-            case file:consult(Dir ++ "/stat_descriptions.cfg") of
-                {ok, Descriptions} ->
-                    Descriptions;
-                {error, _Error} ->
-                    error
-            end
-    end.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d40741a6/src/couch_stats_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_sup.erl b/src/couch_stats_sup.erl
index 0b296d4..4943826 100644
--- a/src/couch_stats_sup.erl
+++ b/src/couch_stats_sup.erl
@@ -16,7 +16,7 @@ start_link() ->
 init([]) ->
     {ok, {
         {one_for_one, 5, 10}, [
-            ?CHILD(couch_stats_stats_collector, worker),
+            ?CHILD(couch_stats_aggregator, worker),
             ?CHILD(couch_stats_process_tracker, worker)
         ]
     }}.