couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [couchdb] branch master updated: Make stats interval into config parameter (#830)
Date Mon, 25 Sep 2017 20:04:40 GMT
This is an automated email from the ASF dual-hosted git repository.

eiri pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b8b9a3  Make stats interval into config parameter (#830)
3b8b9a3 is described below

commit 3b8b9a3f4e778b20bbffcaa91c86993d6a64452f
Author: Eric Avdey <eiri@eiri.ca>
AuthorDate: Mon Sep 25 17:04:38 2017 -0300

    Make stats interval into config parameter (#830)
---
 rel/overlay/etc/default.ini                                  |  4 ++++
 src/couch_stats/src/couch_stats.app.src                      |  4 +---
 src/couch_stats/src/couch_stats.erl                          |  6 +++++-
 src/couch_stats/src/{couch_stats.app.src => couch_stats.hrl} | 12 ++----------
 src/couch_stats/src/couch_stats_aggregator.erl               | 11 ++++++-----
 5 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 653131e..43a40fb 100644
--- a/rel/overlay/etc/default.ini
+++ b/rel/overlay/etc/default.ini
@@ -541,3 +541,7 @@ writer = stderr
 ; syslog_port = 514
 ; syslog_appid = couchdb
 ; syslog_facility = local2
+
+[stats]
+; Stats collection interval in seconds. Default 10 seconds.
+;interval = 10
diff --git a/src/couch_stats/src/couch_stats.app.src b/src/couch_stats/src/couch_stats.app.src
index d60ce1c..6339a0f 100644
--- a/src/couch_stats/src/couch_stats.app.src
+++ b/src/couch_stats/src/couch_stats.app.src
@@ -16,7 +16,5 @@
     {registered, [couch_stats_aggregator, couch_stats_process_tracker]},
     {applications, [kernel, stdlib, folsom, couch_log]},
     {mod, {couch_stats_app, []}},
-    {env, [
-        {collection_interval, 10}
-    ]}
+    {env, []}
 ]}.
diff --git a/src/couch_stats/src/couch_stats.erl b/src/couch_stats/src/couch_stats.erl
index e02da29..59175f7 100644
--- a/src/couch_stats/src/couch_stats.erl
+++ b/src/couch_stats/src/couch_stats.erl
@@ -29,6 +29,10 @@
     update_gauge/2
 ]).
 
+
+-include("couch_stats.hrl").
+
+
 -type response() :: ok | {error, unknown_metric}.
 -type stat() :: {any(), [{atom(), any()}]}.
 
@@ -56,7 +60,7 @@ new(counter, Name) ->
         {error, Name, metric_already_exists} -> {error, metric_exists}
     end;
 new(histogram, Name) ->
-    {ok, Time} = application:get_env(couch_stats, collection_interval),
+    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}
diff --git a/src/couch_stats/src/couch_stats.app.src b/src/couch_stats/src/couch_stats.hrl
similarity index 63%
copy from src/couch_stats/src/couch_stats.app.src
copy to src/couch_stats/src/couch_stats.hrl
index d60ce1c..3cffe99 100644
--- a/src/couch_stats/src/couch_stats.app.src
+++ b/src/couch_stats/src/couch_stats.hrl
@@ -10,13 +10,5 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
-{application, couch_stats, [
-    {description, "Simple statistics collection"},
-    {vsn, git},
-    {registered, [couch_stats_aggregator, couch_stats_process_tracker]},
-    {applications, [kernel, stdlib, folsom, couch_log]},
-    {mod, {couch_stats_app, []}},
-    {env, [
-        {collection_interval, 10}
-    ]}
-]}.
+-define(DEFAULT_INTERVAL, 10).
+-define(RELOAD_INTERVAL, 600).
diff --git a/src/couch_stats/src/couch_stats_aggregator.erl b/src/couch_stats/src/couch_stats_aggregator.erl
index 0f6c9dd..17bd6fc 100644
--- a/src/couch_stats/src/couch_stats_aggregator.erl
+++ b/src/couch_stats/src/couch_stats_aggregator.erl
@@ -30,6 +30,9 @@
     terminate/2
 ]).
 
+
+-include("couch_stats.hrl").
+
 -record(st, {
     descriptions,
     stats,
@@ -52,11 +55,9 @@ start_link() ->
 
 init([]) ->
     {ok, Descs} = reload_metrics(),
-    Interval = case application:get_env(couch_stats, collection_interval) of
-        {ok, I} -> I * 1000
-    end,
-    {ok, CT} = timer:send_interval(Interval, self(), collect),
-    {ok, RT} = timer:send_interval(600000, self(), reload),
+    Interval = config:get_integer("stats", "interval", ?DEFAULT_INTERVAL),
+    {ok, CT} = timer:send_interval(Interval * 1000, self(), collect),
+    {ok, RT} = timer:send_interval(?RELOAD_INTERVAL * 1000, self(), reload),
     {ok, #st{descriptions=Descs, stats=[], collect_timer=CT, reload_timer=RT}}.
 
 handle_call(fetch, _from, #st{stats = Stats}=State) ->

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message