couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r748582 - in /couchdb/trunk: share/www/script/test/stats.js src/couchdb/couch_httpd.erl src/couchdb/couch_httpd_db.erl src/couchdb/couch_stats.hrl src/couchdb/couch_stats_aggregator.erl
Date Fri, 27 Feb 2009 16:44:54 GMT
Author: jan
Date: Fri Feb 27 16:44:53 2009
New Revision: 748582

URL: http://svn.apache.org/viewvc?rev=748582&view=rev
Log:
- group HTTP method stats into httpd_requests_methods as per Christopher Lenz's suggestion
- renamed http_status_codes to httpd_status_codes
- better internal variable naming
- remove comments that were leftovers from earlier refactoring

Modified:
    couchdb/trunk/share/www/script/test/stats.js
    couchdb/trunk/src/couchdb/couch_httpd.erl
    couchdb/trunk/src/couchdb/couch_httpd_db.erl
    couchdb/trunk/src/couchdb/couch_stats.hrl
    couchdb/trunk/src/couchdb/couch_stats_aggregator.erl

Modified: couchdb/trunk/share/www/script/test/stats.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/stats.js?rev=748582&r1=748581&r2=748582&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/stats.js (original)
+++ couchdb/trunk/share/www/script/test/stats.js Fri Feb 27 16:44:53 2009
@@ -187,22 +187,22 @@
  
  var http_requests_by_method_tests = {
    'should count GET requests': function(name) {
-     var requests = requestStatsTest("httpd", "get_requests").current;
-     var new_requests = requestStatsTest("httpd", "get_requests").current;
+     var requests = requestStatsTest("httpd_request_methods", "GET").current;
+     var new_requests = requestStatsTest("httpd_request_methods", "GET").current;
 
      TEquals(requests + 1, new_requests, name);
    },
    'should not count GET requests for POST request': function(name) {
-     var requests = requestStatsTest("httpd", "get_requests").current;
+     var requests = requestStatsTest("httpd_request_methods", "GET").current;
      CouchDB.request("POST", "/");
-     var new_requests = requestStatsTest("httpd", "get_requests").current;
+     var new_requests = requestStatsTest("httpd_request_methods", "GET").current;
 
      TEquals(requests + 1, new_requests, name);        
    },
    'should count POST requests': function(name) {
-     var requests = requestStatsTest("httpd", "post_requests").current;
+     var requests = requestStatsTest("httpd_request_methods", "POST").current;
      CouchDB.request("POST", "/");
-     var new_requests = requestStatsTest("httpd", "post_requests").current;
+     var new_requests = requestStatsTest("httpd_request_methods", "POST").current;
 
      TEquals(requests + 1, new_requests, name);
    }
@@ -341,9 +341,9 @@
      var db = new CouchDB("nonexistant_db");
      db.deleteDb();
 
-     var not_founds = requestStatsTest("http_status_codes", "404").current;
+     var not_founds = requestStatsTest("httpd_status_codes", "404").current;
      CouchDB.request("GET", "/nonexistant_db");
-     var new_not_founds = requestStatsTest("http_status_codes", "404").current;
+     var new_not_founds = requestStatsTest("httpd_status_codes", "404").current;
 
      TEquals(not_founds + 1, new_not_founds, name);
    },

Modified: couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=748582&r1=748581&r2=748582&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd.erl Fri Feb 27 16:44:53 2009
@@ -176,8 +176,7 @@
     {ok, Resp}.
 
 increment_method_stats(Method) ->
-    CounterName = list_to_atom(string:to_lower(atom_to_list(Method)) ++ "_requests"),
-    couch_stats_collector:increment({httpd, CounterName}).
+    couch_stats_collector:increment({httpd_request_methods, Method}).
 
 special_test_authentication_handler(Req) ->
     case header_value(Req, "WWW-Authenticate") of
@@ -338,7 +337,7 @@
 
 
 start_chunked_response(#httpd{mochi_req=MochiReq}, Code, Headers) ->
-    couch_stats_collector:increment({http_status_codes, Code}),
+    couch_stats_collector:increment({httpd_status_codes, Code}),
     {ok, MochiReq:respond({Code, Headers ++ server_header(), chunked})}.
 
 send_chunk(Resp, Data) ->
@@ -346,7 +345,7 @@
     {ok, Resp}.
 
 send_response(#httpd{mochi_req=MochiReq}, Code, Headers, Body) ->
-    couch_stats_collector:increment({http_status_codes, Code}),
+    couch_stats_collector:increment({httpd_status_codes, Code}),
     if Code >= 400 ->
         ?LOG_DEBUG("HTTPd ~p error response:~n ~s", [Code, Body]);
     true -> ok

Modified: couchdb/trunk/src/couchdb/couch_httpd_db.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_db.erl?rev=748582&r1=748581&r2=748582&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_httpd_db.erl (original)
+++ couchdb/trunk/src/couchdb/couch_httpd_db.erl Fri Feb 27 16:44:53 2009
@@ -80,7 +80,6 @@
     Doc = couch_doc:from_json_obj(couch_httpd:json_body(Req)),
     DocId = couch_util:new_uuid(),
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=[]}, []),
-    % couch_stats_collector:increment({httpd, document_creates}),
     DocUrl = absolute_uri(Req, 
         binary_to_list(<<"/",DbName/binary,"/",DocId/binary>>)),
     send_json(Req, 201, [{"Location", DocUrl}], {[
@@ -379,7 +378,6 @@
         couch_httpd:send_error(Req, 409, <<"missing_rev">>,
             <<"Document rev/etag must be specified to delete">>);
     RevToDelete ->
-        % couch_stats_collector:increment({httpd, document_deletes}),
         {ok, NewRev} = couch_db:delete_doc(Db, DocId, [RevToDelete]),
         send_json(Req, 200, {[
             {ok, true},
@@ -394,7 +392,6 @@
         open_revs = Revs,
         options = Options
     } = parse_doc_query(Req),
-    % couch_stats_collector:increment({httpd, document_reads}),
     case Revs of
     [] ->
         Doc = couch_doc_open(Db, DocId, Rev, Options),
@@ -471,10 +468,8 @@
     end,
     case extract_header_rev(Req, ExplicitRev) of
     missing_rev ->
-        % couch_stats_collector:increment({httpd, document_creates}),
         Revs = [];
     Rev ->
-        % couch_stats_collector:increment({httpd, document_updates}),
         Revs = [Rev]
     end,
     {ok, NewRev} = couch_db:update_doc(Db, Doc#doc{id=DocId, revs=Revs}, Options),
@@ -498,7 +493,6 @@
 
     % save new doc
     {ok, NewTargetRev} = couch_db:update_doc(Db, Doc#doc{id=TargetDocId, revs=TargetRev},
[]),
-    % couch_stats_collector:increment({httpd, document_copies}),
 
     send_json(Req, 201, [{"Etag", "\"" ++ binary_to_list(NewTargetRev) ++ "\""}], {[
         {ok, true},
@@ -525,7 +519,6 @@
         #doc{id=SourceDocId, revs=[SourceRev], deleted=true}
         ],
     {ok, ResultRevs} = couch_db:update_docs(Db, Docs, []),
-    % couch_stats_collector:increment({httpd, document_moves}),
     
     DocResults = lists:zipwith(
         fun(FDoc, NewRev) ->
@@ -629,10 +622,8 @@
 
     Doc = case extract_header_rev(Req, couch_httpd:qs_value(Req, "rev")) of
         missing_rev -> % make the new doc
-            % couch_stats_collector:increment({httpd, document_creates}),
             #doc{id=DocId};
         Rev ->
-            % couch_stats_collector:increment({httpd, document_updates}),
             case couch_db:open_doc_revs(Db, DocId, [Rev], []) of
             {ok, [{ok, Doc0}]}  -> Doc0#doc{revs=[Rev]};
             {ok, [Error]}       -> throw(Error)

Modified: couchdb/trunk/src/couchdb/couch_stats.hrl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_stats.hrl?rev=748582&r1=748581&r2=748582&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_stats.hrl (original)
+++ couchdb/trunk/src/couchdb/couch_stats.hrl Fri Feb 27 16:44:53 2009
@@ -17,6 +17,6 @@
     variance = 0.0,
     stddev = 0.0,
     count = 0,
-    last = 0,
+    current = 0,
     description
 }).

Modified: couchdb/trunk/src/couchdb/couch_stats_aggregator.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_stats_aggregator.erl?rev=748582&r1=748581&r2=748582&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_stats_aggregator.erl (original)
+++ couchdb/trunk/src/couchdb/couch_stats_aggregator.erl Fri Feb 27 16:44:53 2009
@@ -147,13 +147,14 @@
     %% default Time is 0, which is when CouchDB started
     get_aggregate(Key, State, '0').
 get_aggregate(Key, #state{aggregates=StatsList}, Time) ->
+    Description = get_description(Key),
     Aggregates = case proplists:lookup(Key, StatsList) of
         % if we don't have any data here, return an empty record
-        none -> #aggregates{};
+        none -> #aggregates{description=Description};
         {Key, Stats} ->
             case proplists:lookup(Time, Stats) of
-                none -> #aggregates{}; % empty record again
-                {Time, Stat} -> Stat#aggregates{description=get_description(Key)}
+                none -> #aggregates{description=Description}; % empty record again
+                {Time, Stat} -> Stat#aggregates{description=Description}
             end
     end,
     Aggregates.
@@ -217,7 +218,7 @@
             variance=0,
             stddev=0,
             count=1,
-            last=Value
+            current=Value
         };
         % this sure could look nicer -- any ideas?
         StatsRecord ->
@@ -227,12 +228,12 @@
                 mean=Mean,
                 variance=Variance,
                 count=Count,
-                last=Last
+                current=Current
             } = StatsRecord,
 
             % incremental counters need to keep track of the last update's value
             NewValue = case CounterType of
-                incremental -> Value - Last;
+                incremental -> Value - Current;
                 absolute -> Value
             end,
                 % Knuth, The Art of Computer Programming, vol. 2, p. 232. 
@@ -246,15 +247,14 @@
                     variance=NewVariance,
                     stddev=math:sqrt(NewVariance / NewCount),
                     count=NewCount,
-                    last=Value
+                    current=Value
                 }
     end.
 
 
-aggregate_to_json_term(#aggregates{min=Min,max=Max,mean=Mean,stddev=Stddev,count=Count,last=Last,description=Description})
->
+aggregate_to_json_term(#aggregates{min=Min,max=Max,mean=Mean,stddev=Stddev,count=Count,current=Current,description=Description})
->
     {[
-        % current is redundant, but reads nicer in JSON
-        {current, Last},
+        {current, Current},
         {count, Count},
         {mean, Mean},
         {min, Min},
@@ -305,32 +305,33 @@
     ets:insert(?MODULE, {{couchdb, open_databases}, <<"number of open databases">>}),
     ets:insert(?MODULE, {{couchdb, os_files_open}, <<"number of file descriptors CouchDB
has open">>}),
     ets:insert(?MODULE, {{couchdb, request_time}, <<"length of a request inside CouchDB
without Mochiweb">>}),
-
-    ets:insert(?MODULE, {{http_status_codes, '200'}, <<"number of HTTP 200 OK responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '201'}, <<"number of HTTP 201 Created
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '202'}, <<"number of HTTP 202 Accepted
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '301'}, <<"number of HTTP 301 Moved Permanently
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '304'}, <<"number of HTTP 304 Not Modified
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '400'}, <<"number of HTTP 400 Bad Request
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '401'}, <<"number of HTTP 401 Unauthorized
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '403'}, <<"number of HTTP 403 Forbidden
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '404'}, <<"number of HTTP 404 Not Found
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '405'}, <<"number of HTTP 405 Method Not
Allowed responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '409'}, <<"number of HTTP 409 Conflict
responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '412'}, <<"number of HTTP 412 Precondition
Failed responses">>}),
-    ets:insert(?MODULE, {{http_status_codes, '500'}, <<"number of HTTP 500 Internal
Server Error responses">>}),
-
+    
     ets:insert(?MODULE, {{httpd, bulk_requests}, <<"number of bulk requests">>}),
-    ets:insert(?MODULE, {{httpd, copy_requests}, <<"number of HTTP COPY requests">>}),
-    ets:insert(?MODULE, {{httpd, delete_requests}, <<"number of HTTP DELETE requests">>}),
-    ets:insert(?MODULE, {{httpd, get_requests}, <<"number of HTTP GET requests">>}),
-    ets:insert(?MODULE, {{httpd, head_requests}, <<"number of HTTP HEAD requests">>}),
-    ets:insert(?MODULE, {{httpd, move_requests}, <<"number of HTTP MOVE requests">>}),
-    ets:insert(?MODULE, {{httpd, post_requests}, <<"number of HTTP POST 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, put_requests}, <<"number of HTTP PUT requests">>}).
+    
+    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">>}),
+    ets:insert(?MODULE, {{httpd_request_methods, 'HEAD'}, <<"number of HTTP HEAD requests">>}),
+    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">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '301'}, <<"number of HTTP 301 Moved Permanently
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '304'}, <<"number of HTTP 304 Not Modified
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '400'}, <<"number of HTTP 400 Bad Request
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '401'}, <<"number of HTTP 401 Unauthorized
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '403'}, <<"number of HTTP 403 Forbidden
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '404'}, <<"number of HTTP 404 Not Found
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '405'}, <<"number of HTTP 405 Method
Not Allowed responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '409'}, <<"number of HTTP 409 Conflict
responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '412'}, <<"number of HTTP 412 Precondition
Failed responses">>}),
+    ets:insert(?MODULE, {{httpd_status_codes, '500'}, <<"number of HTTP 500 Internal
Server Error responses">>}).
     % please keep this in alphabetical order
 
 



Mime
View raw message