summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_stats_aggregator.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/couchdb/couch_stats_aggregator.erl')
-rw-r--r--src/couchdb/couch_stats_aggregator.erl48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/couchdb/couch_stats_aggregator.erl b/src/couchdb/couch_stats_aggregator.erl
index 821bf60f..2e8ea380 100644
--- a/src/couchdb/couch_stats_aggregator.erl
+++ b/src/couchdb/couch_stats_aggregator.erl
@@ -18,7 +18,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
--export([start/0, stop/0,
+-export([start/0, stop/0,
get/1, get/2, get_json/1, get_json/2, all/0,
time_passed/0, clear_aggregates/1]).
@@ -34,7 +34,7 @@
start() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
+
stop() ->
gen_server:call(?MODULE, stop).
@@ -47,18 +47,18 @@ get_json(Key) ->
gen_server:call(?MODULE, {get_json, Key}).
get_json(Key, Time) ->
gen_server:call(?MODULE, {get_json, Key, Time}).
-
+
time_passed() ->
gen_server:call(?MODULE, time_passed).
-clear_aggregates(Time) ->
+clear_aggregates(Time) ->
gen_server:call(?MODULE, {clear_aggregates, Time}).
all() ->
gen_server:call(?MODULE, all).
% GEN_SERVER
-
+
init(_) ->
ets:new(?MODULE, [named_table, set, protected]),
init_timers(),
@@ -86,13 +86,13 @@ handle_call(time_passed, _, OldState) ->
% the foldls below could probably be refactored into a less code-duping form
% update aggregates on incremental counters
- NextState = lists:foldl(fun(Counter, State) ->
+ NextState = lists:foldl(fun(Counter, State) ->
{Key, Value} = Counter,
update_aggregates_loop(Key, Value, State, incremental)
end, OldState, ?COLLECTOR:all(incremental)),
% update aggregates on absolute value counters
- NewState = lists:foldl(fun(Counter, State) ->
+ NewState = lists:foldl(fun(Counter, State) ->
{Key, Value} = Counter,
% clear the counter, we've got the important bits in State
?COLLECTOR:clear(Key),
@@ -117,7 +117,7 @@ handle_call(stop, _, State) ->
% Stats = [{Key, TimesProplist}]
% TimesProplist = [{Time, Aggrgates}]
% Aggregates = #aggregates{}
-%
+%
% [
% {Key, [
% {TimeA, #aggregates{}},
@@ -126,7 +126,7 @@ handle_call(stop, _, State) ->
% {TimeD, #aggregates{}}
% ]
% },
-%
+%
% ]
%% clear the aggregats record for a specific Time = 60 | 300 | 900
@@ -134,7 +134,7 @@ do_clear_aggregates(Time, #state{aggregates=Stats}) ->
NewStats = lists:map(fun({Key, TimesProplist}) ->
{Key, case proplists:lookup(Time, TimesProplist) of
% do have stats for this key, if we don't, return Stat unmodified
- none ->
+ none ->
TimesProplist;
% there are stats, let's unset the Time one
{_Time, _Stat} ->
@@ -177,12 +177,12 @@ update_aggregates_loop(Key, Values, State, CounterType) ->
% {'900',{aggregates,1,1,1,0,0,1,1}}]}]
[{_Key, StatsList}] = case proplists:lookup(Key, AllStats) of
none -> [{Key, [
- {'0', empty},
+ {'0', empty},
{'60', empty},
{'300', empty},
{'900', empty}
]}];
- AllStatsMatch ->
+ AllStatsMatch ->
[AllStatsMatch]
end,
@@ -236,7 +236,7 @@ update_aggregates(Value, Stat, CounterType) ->
incremental -> Value - Current;
absolute -> Value
end,
- % Knuth, The Art of Computer Programming, vol. 2, p. 232.
+ % Knuth, The Art of Computer Programming, vol. 2, p. 232.
NewCount = Count + 1,
NewMean = Mean + (NewValue - Mean) / NewCount, % NewCount is never 0.
NewVariance = Variance + (NewValue - Mean) * (NewValue - NewMean),
@@ -288,29 +288,29 @@ do_get_all(#state{aggregates=Stats}=State) ->
init_descriptions() ->
- % ets is probably overkill here, but I didn't manage to keep the
+ % ets is probably overkill here, but I didn't manage to keep the
% descriptions in the gen_server state. Which means there is probably
% a bug in one of the handle_call() functions most likely the one that
% handles the time_passed message. But don't tell anyone, the math is
% correct :) -- Jan
- % Style guide for descriptions: Start with a lowercase letter & do not add
+ % Style guide for descriptions: Start with a lowercase letter & do not add
% a trailing full-stop / period.
-
+
% please keep this in alphabetical order
ets:insert(?MODULE, {{couchdb, database_writes}, <<"number of times a database was changed">>}),
ets:insert(?MODULE, {{couchdb, database_reads}, <<"number of times a document was read from a database">>}),
ets:insert(?MODULE, {{couchdb, open_databases}, <<"number of open databases">>}),
ets:insert(?MODULE, {{couchdb, open_os_files}, <<"number of file descriptors CouchDB has open">>}),
ets:insert(?MODULE, {{couchdb, request_time}, <<"length of a request inside CouchDB without MochiWeb">>}),
-
+
ets:insert(?MODULE, {{httpd, bulk_requests}, <<"number of bulk requests">>}),
ets:insert(?MODULE, {{httpd, requests}, <<"number of HTTP requests">>}),
ets:insert(?MODULE, {{httpd, temporary_view_reads}, <<"number of temporary view reads">>}),
ets:insert(?MODULE, {{httpd, view_reads}, <<"number of view reads">>}),
ets:insert(?MODULE, {{httpd, clients_requesting_changes}, <<"Number of clients currently requesting continuous _changes">>}),
-
+
ets:insert(?MODULE, {{httpd_request_methods, 'COPY'}, <<"number of HTTP COPY requests">>}),
ets:insert(?MODULE, {{httpd_request_methods, 'DELETE'}, <<"number of HTTP DELETE requests">>}),
ets:insert(?MODULE, {{httpd_request_methods, 'GET'}, <<"number of HTTP GET requests">>}),
@@ -318,7 +318,7 @@ init_descriptions() ->
ets:insert(?MODULE, {{httpd_request_methods, 'MOVE'}, <<"number of HTTP MOVE requests">>}),
ets:insert(?MODULE, {{httpd_request_methods, 'POST'}, <<"number of HTTP POST requests">>}),
ets:insert(?MODULE, {{httpd_request_methods, 'PUT'}, <<"number of HTTP PUT requests">>}),
-
+
ets:insert(?MODULE, {{httpd_status_codes, '200'}, <<"number of HTTP 200 OK responses">>}),
ets:insert(?MODULE, {{httpd_status_codes, '201'}, <<"number of HTTP 201 Created responses">>}),
ets:insert(?MODULE, {{httpd_status_codes, '202'}, <<"number of HTTP 202 Accepted responses">>}),
@@ -338,12 +338,12 @@ init_descriptions() ->
% Timer
init_timers() ->
-
+
% OTP docs on timer: http://erlang.org/doc/man/timer.html
% start() -> ok
- % Starts the timer server. Normally, the server does not need to be
- % started explicitly. It is started dynamically if it is needed. This is
- % useful during development, but in a target system the server should be
+ % Starts the timer server. Normally, the server does not need to be
+ % started explicitly. It is started dynamically if it is needed. This is
+ % useful during development, but in a target system the server should be
% started explicitly. Use configuration parameters for kernel for this.
%
% TODO: Add timer_start to kernel start options.
@@ -361,7 +361,7 @@ init_timers() ->
% Unused gen_server behaviour API functions that we need to declare.
-
+
%% @doc Unused
handle_cast(foo, State) ->
{noreply, State}.