@cryptotaxi247 / netdata-1 / commits / f934da973

log flood should not be disabled; (#4344)

* log flood should not be disabled; #4312 * use 10x the logs with the minimum of 10000

Costa Tsaousis committed Oct 3, 2018 at 12:03 UTC f934da9731e5995afbc3561a2a7cfb4f7945b619
4 files changed +18 -11
conf.d/edit-config.in
+4 -2
@@ -15,7 +15,10 @@ then
15 USAGE:
16 ${0} FILENAME
17
18 - Find the stock config file named FILENAME and edit it.
18 + Copy and edit the stock config file named: FILENAME
19 + if FILENAME is already copied, it will be edited as-is.
20 +
21 + The EDITOR shell variable is used to define the editor to be used.
22
23 Stock config files at: '${NETDATA_STOCK_CONFIG_DIR}'
24 User config files at: '${NETDATA_USER_CONFIG_DIR}'
@@ -83,7 +86,6 @@ fi
86 # already exists
87 if [ -f "${NETDATA_USER_CONFIG_DIR}/${file}" ]
88 then
86 - echo >&2 "Editing existing file '${NETDATA_USER_CONFIG_DIR}/${file}' ... "
89 edit "${NETDATA_USER_CONFIG_DIR}/${file}"
90 fi
91
src/log.c
+6 -4
@@ -161,14 +161,16 @@ void open_all_log_files() {
161 // ----------------------------------------------------------------------------
162 // error log throttling
163
164 -time_t error_log_throttle_period_backup = 0;
164 time_t error_log_throttle_period = 1200;
165 unsigned long error_log_errors_per_period = 200;
166 +unsigned long error_log_errors_per_period_backup = 0;
167
168 int error_log_limit(int reset) {
169 static time_t start = 0;
170 static unsigned long counter = 0, prevented = 0;
171
172 + // fprintf(stderr, "FLOOD: counter=%lu, allowed=%lu, backup=%lu, period=%llu\n", counter, error_log_errors_per_period, error_log_errors_per_period_backup, (unsigned long long)error_log_throttle_period);
173 +
174 // do not throttle if the period is 0
175 if(error_log_throttle_period == 0)
176 return 0;
@@ -188,7 +190,7 @@ int error_log_limit(int reset) {
190 if(prevented) {
191 char date[LOG_DATE_LENGTH];
192 log_date(date, LOG_DATE_LENGTH);
191 - fprintf(stderr, "%s: %s Resetting logging for process '%s' (prevented %lu logs in the last %ld seconds).\n"
193 + fprintf(stderr, "%s: %s LOG FLOOD PROTECTION reset for process '%s' (prevented %lu logs in the last %ld seconds).\n"
194 , date
195 , program_name
196 , program_name
@@ -209,7 +211,7 @@ int error_log_limit(int reset) {
211 if(prevented) {
212 char date[LOG_DATE_LENGTH];
213 log_date(date, LOG_DATE_LENGTH);
212 - fprintf(stderr, "%s: %s Resuming logging from process '%s' (prevented %lu logs in the last %ld seconds).\n"
214 + fprintf(stderr, "%s: %s LOG FLOOD PROTECTION resuming logging from process '%s' (prevented %lu logs in the last %ld seconds).\n"
215 , date
216 , program_name
217 , program_name
@@ -231,7 +233,7 @@ int error_log_limit(int reset) {
233 if(!prevented) {
234 char date[LOG_DATE_LENGTH];
235 log_date(date, LOG_DATE_LENGTH);
234 - fprintf(stderr, "%s: %s Too many logs (%lu logs in %ld seconds, threshold is set to %lu logs in %ld seconds). Preventing more logs from process '%s' for %ld seconds.\n"
236 + fprintf(stderr, "%s: %s LOG FLOOD PROTECTION too many logs (%lu logs in %ld seconds, threshold is set to %lu logs in %ld seconds). Preventing more logs from process '%s' for %ld seconds.\n"
237 , date
238 , program_name
239 , counter
src/log.h
+7 -4
@@ -59,8 +59,8 @@ extern int access_log_syslog;
59 extern int error_log_syslog;
60 extern int output_log_syslog;
61
62 -extern time_t error_log_throttle_period, error_log_throttle_period_backup;
63 -extern unsigned long error_log_errors_per_period;
62 +extern time_t error_log_throttle_period;
63 +extern unsigned long error_log_errors_per_period, error_log_errors_per_period_backup;
64 extern int error_log_limit(int reset);
65
66 extern void open_all_log_files();
@@ -68,8 +68,11 @@ extern void reopen_all_log_files();
68
69 static inline void debug_dummy(void) {}
70
71 -#define error_log_limit_reset() do { error_log_throttle_period = error_log_throttle_period_backup; error_log_limit(1); } while(0)
72 -#define error_log_limit_unlimited() do { error_log_throttle_period = 0; } while(0)
71 +#define error_log_limit_reset() do { error_log_errors_per_period = error_log_errors_per_period_backup; error_log_limit(1); } while(0)
72 +#define error_log_limit_unlimited() do { \
73 + error_log_limit_reset(); \
74 + error_log_errors_per_period = ((error_log_errors_per_period_backup * 10) < 10000) ? 10000 : (error_log_errors_per_period_backup * 10); \
75 + } while(0)
76
77 #ifdef NETDATA_INTERNAL_CHECKS
78 #define debug(type, args...) do { if(unlikely(debug_flags & type)) debug_int(__FILE__, __FUNCTION__, __LINE__, ##args); } while(0)
src/main.c
+1 -1
@@ -359,9 +359,9 @@ void log_init(void) {
359 snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
360 stdaccess_filename = config_get(CONFIG_SECTION_GLOBAL, "access log", filename);
361
362 - error_log_throttle_period_backup =
362 error_log_throttle_period = config_get_number(CONFIG_SECTION_GLOBAL, "errors flood protection period", error_log_throttle_period);
363 error_log_errors_per_period = (unsigned long)config_get_number(CONFIG_SECTION_GLOBAL, "errors to trigger flood protection", (long long int)error_log_errors_per_period);
364 + error_log_errors_per_period_backup = error_log_errors_per_period;
365
366 setenv("NETDATA_ERRORS_THROTTLE_PERIOD", config_get(CONFIG_SECTION_GLOBAL, "errors flood protection period" , ""), 1);
367 setenv("NETDATA_ERRORS_PER_PERIOD", config_get(CONFIG_SECTION_GLOBAL, "errors to trigger flood protection", ""), 1);