summaryrefslogtreecommitdiff
path: root/src/couchdb
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
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')
-rw-r--r--src/couchdb/couch_httpd_stats_handlers.erl33
-rw-r--r--src/couchdb/couch_server.erl2
-rw-r--r--src/couchdb/couch_stats_aggregator.erl4
3 files changed, 30 insertions, 9 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)).
diff --git a/src/couchdb/couch_server.erl b/src/couchdb/couch_server.erl
index 8f747a56..164af094 100644
--- a/src/couchdb/couch_server.erl
+++ b/src/couchdb/couch_server.erl
@@ -183,7 +183,7 @@ maybe_close_lru_db(#server{dbs_open=NumOpen}=Server) ->
% must free up the lru db.
case try_close_lru(now()) of
ok ->
- couch_stats_collector:decrement({couchdb, open_databases}),
+ couch_stats_collector:decrement({couchdb, open_databases}),
{ok, Server#server{dbs_open=NumOpen - 1}};
Error -> Error
end.
diff --git a/src/couchdb/couch_stats_aggregator.erl b/src/couchdb/couch_stats_aggregator.erl
index 97f6bc14..3d3db0ef 100644
--- a/src/couchdb/couch_stats_aggregator.erl
+++ b/src/couchdb/couch_stats_aggregator.erl
@@ -241,10 +241,10 @@ update_aggregates(Value, Stat, CounterType) ->
end.
-aggregate_to_json_term(#aggregates{min=Min,max=Max,mean=Mean,stddev=Stddev,count=Count}) ->
+aggregate_to_json_term(#aggregates{min=Min,max=Max,mean=Mean,stddev=Stddev,count=Count,last=Last}) ->
{[
% current is redundant, but reads nicer in JSON
- {current, Count},
+ {current, Last},
{count, Count},
{mean, Mean},
{min, Min},