Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

expose vm stats to the HTTP api.

GET /_stats/vm/system : system info
GET /_stats/vm/memory : memory info
GET /_stats/vm/port : ports info
GET /_stats/vm/process : process info
GET /_stats/vm/ets : ets info
GET /_stats/vm/dets : dets info
  • Loading branch information...
commit 46be0065c3aaadb4ea9dbc16a2e55a38e415577f 1 parent 32fea30
@benoitc benoitc authored
View
2  apps/couch_httpd/src/couch_httpd.erl
@@ -34,6 +34,8 @@
-export([vendor_id/0]).
-export([display_uris/0, display_uris/1, get_bindings/0]).
-export([http_1_0_keep_alive/2]).
+-export([initialize_jsonp/1, negotiate_content_type/1, start_jsonp/0,
+ end_jsonp/0]).
ssl_options() ->
CertFile = couch_config:get("ssl", "cert_file", nil),
View
41 apps/couch_httpd/src/couch_httpd_stats_handlers.erl
@@ -28,6 +28,34 @@ handle_stats_req(#httpd{method='GET', path_parts=[_]}=Req) ->
handle_stats_req(#httpd{method='GET', path_parts=[_, _Mod]}) ->
throw({bad_request, <<"Stat names must have exactly to parts.">>});
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"system">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_system_info());
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"memory">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_memory());
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"statistics">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_statistics());
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"process">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_process_info());
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"port">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_port_info());
+handle_stats_req(#httpd{method='GET',
+ path_parts=[_, <<"vm">>, <<"ets">>]}=Req) ->
+ flush(Req),
+ send_vm_json(Req, couch_stats_vm:get_ets_info());
+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=[_, Mod, Key]}=Req) ->
flush(Req),
Stats = couch_stats_aggregator:get_json({list_to_atom(binary_to_list(Mod)),
@@ -40,6 +68,19 @@ handle_stats_req(#httpd{method='GET', path_parts=[_, _Mod, _Key | _Extra]}) ->
handle_stats_req(Req) ->
send_method_not_allowed(Req, "GET").
+
+
+send_vm_json(Req, Value) ->
+ couch_httpd:initialize_jsonp(Req),
+ Headers = [
+ {"Content-Type", couch_httpd:negotiate_content_type(Req)},
+ {"Cache-Control", "must-revalidate"}
+ ],
+ Body = [couch_httpd:start_jsonp(), mochijson2:encode(Value),
+ couch_httpd:end_jsonp(), $\n],
+ couch_httpd:send_response(Req, 200, Headers, Body).
+
+
range(Req) ->
case couch_util:get_value("range", couch_httpd:qs(Req)) of
undefined ->
Please sign in to comment.
Something went wrong with that request. Please try again.