Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Honor ?flush=true for _stats call
  • Loading branch information
rnewson committed Aug 29, 2014
1 parent c675e2e commit 81483c1e3261c1314959dd8ace869d2268a72dfc
Showing 2 changed files with 27 additions and 9 deletions.
@@ -15,7 +15,8 @@
-behaviour(gen_server).

-export([
fetch/0
fetch/0,
flush/0
]).

-export([
@@ -39,6 +40,9 @@ fetch() ->
{ok, Stats} = gen_server:call(?MODULE, fetch),
Stats.

flush() ->
gen_server:call(?MODULE, flush).

start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

@@ -53,20 +57,16 @@ init([]) ->

handle_call(fetch, _from, #st{stats = Stats}=State) ->
{reply, {ok, Stats}, State};
handle_call(flush, _From, State) ->
{reply, ok, collect(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(collect, State) ->
{noreply, collect(State)};
handle_info(reload, State) ->
{ok, Descriptions} = reload_metrics(),
{noreply, State#st{descriptions=Descriptions}};
@@ -126,3 +126,12 @@ load_metrics_for_application(AppName) ->
error
end
end.

collect(State) ->
Stats = lists:map(
fun({Name, Props}) ->
{Name, [{value, couch_stats:sample(Name)}|Props]}
end,
State#st.descriptions
),
State#st{stats=Stats}.
@@ -16,6 +16,7 @@
-export([handle_stats_req/1]).

handle_stats_req(#httpd{method='GET', path_parts=[_ | Path]}=Req) ->
flush(Req),
Stats0 = couch_stats:fetch(),
Stats = transform_stats(Stats0),
Nested = nest(Stats),
@@ -95,3 +96,11 @@ maybe_format_key(Key) when is_atom(Key) ->
list_to_binary(atom_to_list(Key));
maybe_format_key(Key) when is_binary(Key) ->
Key.

flush(Req) ->
case couch_util:get_value("flush", couch_httpd:qs(Req)) of
"true" ->
couch_stats_aggregator:flush();
_Else ->
ok
end.

0 comments on commit 81483c1

Please sign in to comment.