summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chttpd.erl28
-rw-r--r--src/chttpd_db.erl1
-rw-r--r--src/chttpd_misc.erl13
3 files changed, 28 insertions, 14 deletions
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 51edbef2..122a98a2 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -136,18 +136,21 @@ handle_request(MochiReq) ->
send_error(HttpReq, Error)
end,
- RequestTime = round(timer:now_diff(now(), Begin)/1000),
- RequestInfo = [
- MochiReq:get(peer),
- MochiReq:get_header_value("Host"),
- atom_to_list(Method1),
- RawUri,
- Resp:get(code),
- RequestTime
- ],
- % Customer = cloudant_util:customer_name(HttpReq),
- % couch_metrics_req:notify({request, [Customer|RequestInfo]}),
- showroom_log:message(notice, "~s ~s ~s ~s ~B ~B", RequestInfo),
+ RequestTime = timer:now_diff(now(), Begin)/1000,
+ Peer = MochiReq:get(peer),
+ Code = Resp:get(code),
+ Host = MochiReq:get_header_value("Host"),
+ couch_metrics_event:notify(#response{
+ peer = Peer,
+ host = Host,
+ customer = Customer,
+ code = Code,
+ time = RequestTime,
+ method = Method1,
+ uri = RawUri
+ }),
+ showroom_log:message(notice, "~s ~s ~s ~s ~B ~B", [Peer, Host,
+ atom_to_list(Method1), RawUri, Code, round(RequestTime)]),
couch_stats_collector:record({couchdb, request_time}, RequestTime),
couch_stats_collector:increment({httpd, requests}),
{ok, Resp}.
@@ -190,6 +193,7 @@ url_handler("_session") -> fun chttpd_auth:handle_session_req/1;
url_handler("_user") -> fun chttpd_auth:handle_user_req/1;
url_handler("_oauth") -> fun chttpd_oauth:handle_oauth_req/1;
url_handler("_stats") -> fun chttpd_stats:handle_stats_req/1;
+url_handler("_metrics") -> fun chttpd_misc:handle_metrics_req/1;
url_handler("_restart") -> fun showroom_http:handle_restart_req/1;
url_handler("_cloudant") -> fun showroom_httpd_admin:handle_cloudant_req/1;
url_handler(_) -> fun chttpd_db:handle_request/1.
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 277a33bc..9aae4c6e 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -158,7 +158,6 @@ create_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) ->
delete_db_req(#httpd{user_ctx=UserCtx}=Req, DbName) ->
case fabric:delete_db(DbName, [{user_ctx, UserCtx}]) of
ok ->
- % couch_metrics_disk:notify({db_delete, {UserCtx#user_ctx.name, DbName}}),
send_json(Req, 200, {[{ok, true}]});
Error ->
throw(Error)
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 26297d34..3ed70bea 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -16,7 +16,7 @@
handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1,
handle_uuids_req/1,handle_config_req/1,handle_log_req/1,
handle_task_status_req/1,handle_sleep_req/1,handle_welcome_req/1,
- handle_utils_dir_req/1, handle_favicon_req/1]).
+ handle_utils_dir_req/1, handle_favicon_req/1, handle_metrics_req/1]).
-export([increment_update_seq_req/2]).
@@ -214,4 +214,15 @@ handle_log_req(#httpd{method='GET'}=Req) ->
handle_log_req(Req) ->
send_method_not_allowed(Req, "GET").
+handle_metrics_req(#httpd{method='GET', path_parts=[_, Id]}=Req) ->
+ case chttpd:qs_value(Req, "slice") of
+ undefined ->
+ Data = couch_metrics_event:get_global_metrics(?b2a(Id));
+ SliceStr ->
+ Slice = list_to_integer(SliceStr),
+ Data = couch_metrics_event:get_global_metrics(?b2a(Id), Slice)
+ end,
+ send_json(Req, Data);
+handle_metrics_req(Req) ->
+ send_method_not_allowed(Req, "GET,HEAD").