Navigation Menu

Skip to content

Commit

Permalink
get the number of running connections
Browse files Browse the repository at this point in the history
GET /_stats/httpd/connections
  • Loading branch information
benoitc committed Sep 25, 2013
1 parent 1c1df4d commit e394ea3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apps/couch_httpd/src/couch_httpd_protocol.erl
Expand Up @@ -148,7 +148,7 @@ after_response(Body, Req) ->
case Req:should_close() of
true ->
mochiweb_socket:close(Socket),
ok;
exit(normal);
false ->
Req:cleanup(),
erlang:garbage_collect(),
Expand All @@ -169,4 +169,4 @@ mochiweb_socket(#hstate{transport=Transport, socket=Socket}) ->

terminate(#hstate{transport=Transport, socket=Socket}) ->
Transport:close(Socket),
ok.
exit(normal).
13 changes: 13 additions & 0 deletions apps/couch_httpd/src/couch_httpd_stats_handlers.erl
Expand Up @@ -56,6 +56,18 @@ handle_stats_req(#httpd{method='GET',
path_parts=[_, <<"vm">>, <<"dets">>]}=Req) ->
flush(Req),
send_vm_json(Req, couch_stats_vm:get_dets_info());
handle_stats_req(#httpd{method='GET',
path_parts=[_, <<"httpd">>, <<"connections">>]}=Req) ->
flush(Req),

NbConns = lists:foldl(fun(Ref, Sum) ->
N = ranch_server:count_connections(Ref),
Sum + N
end, 0, couch_httpd:get_bindings()),

send_json(Req, {[{<<"httpd">>, {[{<<"connections">>, NbConns}]}}]});


handle_stats_req(#httpd{method='GET', path_parts=[_, Mod, Key]}=Req) ->
flush(Req),
Stats = couch_stats_aggregator:get_json({list_to_atom(binary_to_list(Mod)),
Expand All @@ -70,6 +82,7 @@ handle_stats_req(Req) ->




send_vm_json(Req, Value) ->
couch_httpd:initialize_jsonp(Req),
Headers = [
Expand Down

0 comments on commit e394ea3

Please sign in to comment.