summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_httpd_stats_handlers.erl
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2009-02-25 16:39:55 +0000
committerJan Lehnardt <jan@apache.org>2009-02-25 16:39:55 +0000
commit8a5b0c697a6fdb3169afe82391368c26bec86978 (patch)
tree00b4b6a482fb8e6af481c8f5a52fb24655554ef7 /src/couchdb/couch_httpd_stats_handlers.erl
parent0fb2f9696d8005eb46d5efeac1ae217fe0fb6a04 (diff)
add js test suite for stats, enable access for a previously internal metric
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@747852 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_stats_handlers.erl')
-rw-r--r--src/couchdb/couch_httpd_stats_handlers.erl33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/couchdb/couch_httpd_stats_handlers.erl b/src/couchdb/couch_httpd_stats_handlers.erl
index 0b136be9..20b0afb9 100644
--- a/src/couchdb/couch_httpd_stats_handlers.erl
+++ b/src/couchdb/couch_httpd_stats_handlers.erl
@@ -22,12 +22,27 @@
-define(b2a(V), list_to_atom(binary_to_list(V))).
+-record(stats_query_args, {
+ range='0',
+ flush=false
+}).
+
handle_stats_req(#httpd{method='GET', path_parts=[_]}=Req) ->
send_json(Req, couch_stats_aggregator:all());
handle_stats_req(#httpd{method='GET', path_parts=[_Stats, Module, Key]}=Req) ->
- Time = parse_stats_query(Req),
- Stats = couch_stats_aggregator:get_json({?b2a(Module), ?b2a(Key)}, Time),
+ #stats_query_args{
+ range=Range,
+ flush=Flush
+ } = parse_stats_query(Req),
+
+ case Flush of
+ true ->
+ couch_stats_aggregator:time_passed();
+ _ -> ok
+ end,
+
+ Stats = couch_stats_aggregator:get_json({?b2a(Module), ?b2a(Key)}, Range),
Response = {[{Module, {[{Key, Stats}]}}]},
send_json(Req, Response);
@@ -35,7 +50,13 @@ handle_stats_req(Req) ->
send_method_not_allowed(Req, "GET").
parse_stats_query(Req) ->
- case couch_httpd:qs(Req) of
- [{"range", Time}] -> list_to_atom(Time);
- _ -> '0'
- end.
+ lists:foldl(fun({Key,Value}, Args) ->
+ case {Key, Value} of
+ {"range", Range} ->
+ Args#stats_query_args{range=list_to_atom(Range)};
+ {"flush", "true"} ->
+ Args#stats_query_args{flush=true};
+ _Else -> % unknown key value pair, ignore.
+ Args
+ end
+ end, #stats_query_args{}, couch_httpd:qs(Req)).