You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by to...@apache.org on 2021/03/02 00:40:17 UTC

[couchdb] 01/01: initial commit to add prometheus endpoint

This is an automated email from the ASF dual-hosted git repository.

tonysun83 pushed a commit to branch add-couchdb-prometheus
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5865411c353a9b571c2c103624b2714773677799
Author: Tony Sun <to...@gmail.com>
AuthorDate: Mon Mar 1 16:38:52 2021 -0800

    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(-)

diff --git a/rebar.config.script b/rebar.config.script
index 4abdcc9..c4cd7a2 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 16096ce..9c59aa5 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 0159672..e2f17ce 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 6116c79..74674bb 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 0000000..70717a7
--- /dev/null
+++ b/src/couch_prometheus
@@ -0,0 +1 @@
+Subproject commit 70717a722df02e4a5f5175fea43d52c014cf52a6