From 5865411c353a9b571c2c103624b2714773677799 Mon Sep 17 00:00:00 2001 From: Tony Sun Date: Mon, 1 Mar 2021 16:38:52 -0800 Subject: initial commit to add prometheus endpoint --- rebar.config.script | 1 + rel/reltool.config | 2 ++ src/chttpd/src/chttpd_node.erl | 6 ++++++ src/couch/src/couch.app.src | 3 ++- src/couch_prometheus | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) create mode 160000 src/couch_prometheus diff --git a/rebar.config.script b/rebar.config.script index 4abdcc9a3..c4cd7a24e 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -146,6 +146,7 @@ SubDirs = [ "src/setup", "src/smoosh", "src/ebtree", + "src/couch_prometheus", "rel" ]. diff --git a/rel/reltool.config b/rel/reltool.config index 16096cefb..9c59aa53b 100644 --- a/rel/reltool.config +++ b/rel/reltool.config @@ -72,6 +72,7 @@ smoosh, snappy, thrift_protocol, + couch_prometheus, %% extra recon ]}, @@ -143,6 +144,7 @@ {app, smoosh, [{incl_cond, include}]}, {app, snappy, [{incl_cond, include}]}, {app, thrift_protocol, [{incl_cond, include}]}, + {app, couch_prometheus, [{incl_cond, include}]}, %% extra {app, recon, [{incl_cond, include}]} diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl index 0159672f5..e2f17ce22 100644 --- a/src/chttpd/src/chttpd_node.erl +++ b/src/chttpd/src/chttpd_node.erl @@ -117,6 +117,12 @@ handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_stats">> | Path]}= chttpd:send_json(Req, EJSON1); handle_node_req(#httpd{path_parts=[_, _Node, <<"_stats">>]}=Req) -> send_method_not_allowed(Req, "GET"); +handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_metrics">>]}=Req) -> + Metrics = call_node(Node, couch_prometheus_server, scrape, []), + Header = [{<<"Content-Type">>, <<"text/plain">>}], + chttpd:send_response(Req, 200, Header, Metrics); +handle_node_req(#httpd{path_parts=[_, _Node, <<"_metrics">>]}=Req) -> + send_method_not_allowed(Req, "GET"); % GET /_node/$node/_system handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_system">>]}=Req) -> Stats = call_node(Node, chttpd_node, get_stats, []), diff --git a/src/couch/src/couch.app.src b/src/couch/src/couch.app.src index 6116c79ba..74674bbb5 100644 --- a/src/couch/src/couch.app.src +++ b/src/couch/src/couch.app.src @@ -45,7 +45,8 @@ couch_event, ioq, couch_stats, - hyper + hyper, + couch_prometheus ]}, {env, [ { httpd_global_handlers, [ diff --git a/src/couch_prometheus b/src/couch_prometheus new file mode 160000 index 000000000..70717a722 --- /dev/null +++ b/src/couch_prometheus @@ -0,0 +1 @@ +Subproject commit 70717a722df02e4a5f5175fea43d52c014cf52a6 -- cgit v1.2.1