You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2021/01/26 04:58:03 UTC

[couchdb] 01/01: introduce prometheus endpoint

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

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

commit 1b3f2540aadfafe5aaf80b1e37fe172e33a841bc
Author: jiangph <ji...@cn.ibm.com>
AuthorDate: Tue Jan 26 12:57:18 2021 +0800

    introduce prometheus endpoint
---
 rebar.config.script                 |  3 ++-
 src/couch/src/couch.app.src         |  3 ++-
 src/couch_stats/src/couch_stats.erl | 21 ++++++++++++++++++---
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/rebar.config.script b/rebar.config.script
index 4abdcc9..f3c526c 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -174,7 +174,8 @@ DepDescs = [
 {meck,             "meck",             {tag, "0.8.8"}},
 {recon,            "recon",            {tag, "2.5.0"}},
 {passage,          "passage",          {tag, "0.2.6"}},
-{thrift_protocol,  "thrift-protocol",  {tag, "0.1.5"}}
+{thrift_protocol,  "thrift-protocol",  {tag, "0.1.5"}},
+{prometheus,  "prometheus",  {tag, "master"}}
 ].
 
 WithProper = lists:keyfind(with_proper, 1, CouchConfig) == {with_proper, true}.
diff --git a/src/couch/src/couch.app.src b/src/couch/src/couch.app.src
index 6116c79..592b1a1 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,
+        prometheus
     ]},
     {env, [
         { httpd_global_handlers, [
diff --git a/src/couch_stats/src/couch_stats.erl b/src/couch_stats/src/couch_stats.erl
index 4fde14a..dfa7836 100644
--- a/src/couch_stats/src/couch_stats.erl
+++ b/src/couch_stats/src/couch_stats.erl
@@ -58,18 +58,33 @@ new(counter, Name) ->
     case folsom_metrics:new_counter(Name) of
         ok -> ok;
         {error, Name, metric_already_exists} -> {error, metric_exists}
-    end;
+    end,
+    FlatName = lists:foldl(fun(NamePart, Acc) ->
+        atom_to_list(NamePart) ++ "_"  ++  Acc
+    end, "", Name),
+    prometheus_counter:new([{name, list_to_atom(FlatName)}, {help, FlatName}]);
 new(histogram, Name) ->
     Time = config:get_integer("stats", "interval", ?DEFAULT_INTERVAL),
     case folsom_metrics:new_histogram(Name, slide_uniform, {Time, 1024}) of
         ok -> ok;
         {error, Name, metric_already_exists} -> {error, metric_exists}
-    end;
+    end,
+    FlatName = lists:foldl(fun(NamePart, Acc) ->
+        atom_to_list(NamePart) ++ "_"  ++  Acc
+    end, "", Name),
+    prometheus_histogram:new([{name, list_to_atom(FlatName)},
+        {labels, [method]},
+        {buckets, [50, 75, 90, 95, 99, 999]},
+        {help, FlatName}]);
 new(gauge, Name) ->
     case folsom_metrics:new_gauge(Name) of
         ok -> ok;
         {error, Name, metric_already_exists} -> {error, metric_exists}
-    end;
+    end,
+    FlatName = lists:foldl(fun(NamePart, Acc) ->
+        atom_to_list(NamePart) ++ "_"  ++  Acc
+    end, "", Name),
+    prometheus_gauge:new([{name, list_to_atom(FlatName)}, {help, FlatName}]);
 new(_, _) ->
     {error, unsupported_type}.