summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2017-09-25 17:04:38 -0300
committerGitHub <noreply@github.com>2017-09-25 17:04:38 -0300
commit3b8b9a3f4e778b20bbffcaa91c86993d6a64452f (patch)
treeec49d29ff417e3c321125d46eb6e89119512de40
parent1eaf17890ab8d6bf7504355e4e32aaf2357b1398 (diff)
downloadcouchdb-3b8b9a3f4e778b20bbffcaa91c86993d6a64452f.tar.gz
Make stats interval into config parameter (#830)
-rw-r--r--rel/overlay/etc/default.ini4
-rw-r--r--src/couch_stats/src/couch_stats.app.src4
-rw-r--r--src/couch_stats/src/couch_stats.erl6
-rw-r--r--src/couch_stats/src/couch_stats.hrl14
-rw-r--r--src/couch_stats/src/couch_stats_aggregator.erl11
5 files changed, 30 insertions, 9 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini
index 653131e0c..43a40fbcc 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 d60ce1c0a..6339a0f1d 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 e02da29f1..59175f7a8 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.hrl b/src/couch_stats/src/couch_stats.hrl
new file mode 100644
index 000000000..3cffe99f1
--- /dev/null
+++ b/src/couch_stats/src/couch_stats.hrl
@@ -0,0 +1,14 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-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 0f6c9dd83..17bd6fc33 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) ->