summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_httpd.erl
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2009-02-22 13:50:38 +0000
committerJan Lehnardt <jan@apache.org>2009-02-22 13:50:38 +0000
commit598eee1cf5979b61171f623da7e3164244ca3792 (patch)
treec9ff009fe39f2f07b060ace1149a8f074040c2a6 /src/couchdb/couch_httpd.erl
parent1ebc2117452516f6ac6f4f458d7372bc710b79d2 (diff)
Add runtime statistics -- without EUnit tests for now.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@746691 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd.erl')
-rw-r--r--src/couchdb/couch_httpd.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 5549e40a..9b175825 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -102,6 +102,7 @@ stop() ->
handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
+ statistics(runtime), % prepare request_time counter, see end of function
AuthenticationFun = make_arity_1_fun(
couch_config:get("httpd", "authentication_handler")),
% for the path, use the raw path with the query string and fragment
@@ -123,11 +124,8 @@ handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
mochiweb_headers:to_list(MochiReq:get(headers))
]),
- Method =
+ Method1 =
case MochiReq:get(method) of
- % alias HEAD to GET as mochiweb takes care of stripping the body
- 'HEAD' -> 'GET';
-
% already an atom
Meth when is_atom(Meth) -> Meth;
@@ -135,6 +133,15 @@ handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
% possible (if any module references the atom, then it's existing).
Meth -> couch_util:to_existing_atom(Meth)
end,
+
+ increment_method_stats(Method1),
+
+ % alias HEAD to GET as mochiweb takes care of stripping the body
+ Method = case Method1 of
+ 'HEAD' -> 'GET';
+ Other -> Other
+ end,
+
HttpReq = #httpd{
mochi_req = MochiReq,
method = Method,
@@ -163,8 +170,14 @@ handle_request(MochiReq, UrlHandlers, DbUrlHandlers) ->
RawUri,
Resp:get(code)
]),
+ {_TotalRuntime, RequestTime} = statistics(runtime),
+ couch_stats_collector:record({couchdb, request_time}, RequestTime),
+ couch_stats_collector:increment({httpd, requests}),
{ok, Resp}.
+increment_method_stats(Method) ->
+ CounterName = list_to_atom(string:to_lower(atom_to_list(Method)) ++ "_requests"),
+ couch_stats_collector:increment({httpd, CounterName}).
special_test_authentication_handler(Req) ->
case header_value(Req, "WWW-Authenticate") of
@@ -325,6 +338,7 @@ basic_username_pw(Req) ->
start_chunked_response(#httpd{mochi_req=MochiReq}, Code, Headers) ->
+ couch_stats_collector:increment({http_status_codes, Code}),
{ok, MochiReq:respond({Code, Headers ++ server_header(), chunked})}.
send_chunk(Resp, Data) ->
@@ -332,6 +346,7 @@ send_chunk(Resp, Data) ->
{ok, Resp}.
send_response(#httpd{mochi_req=MochiReq}, Code, Headers, Body) ->
+ couch_stats_collector:increment({http_status_codes, Code}),
if Code >= 400 ->
?LOG_DEBUG("HTTPd ~p error response:~n ~s", [Code, Body]);
true -> ok