From 1b3f2540aadfafe5aaf80b1e37fe172e33a841bc Mon Sep 17 00:00:00 2001 From: jiangph Date: Tue, 26 Jan 2021 12:57:18 +0800 Subject: 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 4abdcc9a3..f3c526c13 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 6116c79ba..592b1a19f 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 4fde14acb..dfa783641 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}. -- cgit v1.2.1