@cryptotaxi247 / netdata-1 / commits / 0f2f25e34

logger limiter fix

lgz committed Oct 22, 2017 at 17:41 UTC 0f2f25e34d5a65a79b3a7727dd8be24adba745c1
1 file changed +9 -12
python.d/python_modules/bases/loggers.py
+9 -12
@@ -30,18 +30,16 @@ def limiter(log_max_count=30, allowed_in_seconds=60):
30 def on_decorator(func):
31
32 def on_call(*args, **kwargs):
33 - self = args[0]
33 + current_time = args[0]._runtime_counters.START_RUN
34 + lc = args[0]._logger_counters
35
35 - if self._logger_counters.allowed > log_max_count:
36 - current_time = time()
37 - if current_time - self._logger_counters.time_to_compare <= allowed_in_seconds:
38 - self._logger_counters.dropped += 1
36 + if lc.logged and lc.logged % log_max_count == 0:
37 + if current_time - lc.time_to_compare <= allowed_in_seconds:
38 + lc.dropped += 1
39 return
40 - self._logger_counters.allowed = 0
41 - self._logger_counters.time_to_compare = current_time
40 + lc.time_to_compare = current_time
41
43 - self._logger_counters.allowed += 1
44 - self._logger_counters.logged += 1
42 + lc.logged += 1
43 func(*args, **kwargs)
44
45 return on_call
@@ -52,12 +50,11 @@ class LoggerCounters:
50 def __init__(self):
51 self.logged = 0
52 self.dropped = 0
55 - self.allowed = 0
53 self.time_to_compare = time()
54
55 def __repr__(self):
59 - return '<LoggerCounter: {{logged: {logged}, dropped: {dropped}}}>'.format(logged=self.logged,
60 - dropped=self.dropped)
56 + return 'LoggerCounter(logged: {logged}, dropped: {dropped})'.format(logged=self.logged,
57 + dropped=self.dropped)
58
59
60 class BaseLogger(object):