summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Sun <tony.sun427@gmail.com>2020-04-15 12:30:32 -0700
committerTony Sun <tony.sun427@gmail.com>2020-04-15 12:30:32 -0700
commitc706ee64b3738e0323f313867158372041e641e3 (patch)
tree75e65eab208070cd5155c6ef28a318cdcafdc4cc
parentb78bc93abac65a01af3ce03b7c088dfc03f70215 (diff)
downloadcouchdb-c706ee64b3738e0323f313867158372041e641e3.tar.gz
use boolean to check if report should happen
-rw-r--r--src/chttpd/src/chttpd_stats.erl28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/chttpd/src/chttpd_stats.erl b/src/chttpd/src/chttpd_stats.erl
index 954e3dc3b..cf333de71 100644
--- a/src/chttpd/src/chttpd_stats.erl
+++ b/src/chttpd/src/chttpd_stats.erl
@@ -34,6 +34,7 @@
reads = 0,
writes = 0,
rows = 0,
+ reporter,
last_report_ts = 0,
interval,
request
@@ -41,14 +42,15 @@
-define(KEY, chttpd_stats).
--define(INTERVAL, 60).
+-define(INTERVAL_IN_SEC, 60).
init(Request) ->
+ Reporter = config:get("chttpd", "stats_reporter"),
Time = erlang:monotonic_time(second),
- Interval = config:get_integer("chttpd", "stats_reset_interval",
- ?INTERVAL),
- put(?KEY, #st{last_report_ts = Time, interval = Interval,
- request = Request}).
+ Interval = config:get_integer("chttpd", "stats_reporting_interval",
+ ?INTERVAL_IN_SEC),
+ put(?KEY, #st{reporter = Reporter, last_report_ts = Time,
+ interval = Interval, request = Request}).
report(HttpResp) ->
@@ -66,8 +68,8 @@ report(HttpResp) ->
end.
-report(HttpResp, St) ->
- case config:get("chttpd", "stats_reporter") of
+report(HttpResp, #st{reporter = Reporter} = St) ->
+ case Reporter of
undefined ->
ok;
ModStr ->
@@ -126,13 +128,19 @@ maybe_report_intermittent(State) ->
% Since response is not available during the request, we set
% this undefined. Modules that call:
% Mod:report(HttpReq, HttpResp, Reads, Writes, Rows) should
- % be aware of this.
- report(undefined),
- reset_stats(State, CurrentTime);
+ % be aware of this. Mod:report should also return a boolean
+ % to indicate if reset should occur
+ case report(undefined) of
+ true ->
+ reset_stats(State, CurrentTime);
+ _ ->
+ ok
+ end;
_ ->
ok
end.
+
update_interval(Interval) ->
case get(?KEY) of
#st{} = St ->