@cryptotaxi247 / netdata-1 / commits / 299a229c6

improved configuration and fixes for proxy mode

Costa Tsaousis (ktsaou) committed Feb 24, 2017 at 19:36 UTC 299a229c67fc74730317a4cf9a066de14ccf102c
20 files changed +459 -359
src/appconfig.c
+48 -27
@@ -195,38 +195,58 @@ int appconfig_exists(struct config *root, const char *section, const char *name)
195 return 1;
196 }
197
198 -int appconfig_rename(struct config *root, const char *section, const char *old, const char *new) {
199 - struct config_option *cv, *cv2;
198 +int appconfig_move(struct config *root, const char *section_old, const char *name_old, const char *section_new, const char *name_new) {
199 + struct config_option *cv_old, *cv_new;
200 + int ret = -1;
201
201 - debug(D_CONFIG, "request to rename config in section '%s', old name '%s', new name '%s'", section, old, new);
202 + debug(D_CONFIG, "request to rename config in section '%s', old name '%s', to section '%s', new name '%s'", section_old, name_old, section_new, name_new);
203
203 - struct section *co = appconfig_section_find(root, section);
204 - if(!co) return -1;
204 + struct section *co_old = appconfig_section_find(root, section_old);
205 + if(!co_old) return -1;
206
206 - config_section_wrlock(co);
207 + struct section *co_new = appconfig_section_find(root, section_new);
208 + if(!co_new) co_new = appconfig_section_create(root, section_new);
209
208 - cv = appconfig_option_index_find(co, old, 0);
209 - if(!cv) goto cleanup;
210 + config_section_wrlock(co_old);
211 + config_section_wrlock(co_new);
212
211 - cv2 = appconfig_option_index_find(co, new, 0);
212 - if(cv2) goto cleanup;
213 + cv_old = appconfig_option_index_find(co_old, name_old, 0);
214 + if(!cv_old) goto cleanup;
215
214 - if(unlikely(appconfig_option_index_del(co, cv) != cv))
215 - error("INTERNAL ERROR: deletion of config '%s' from section '%s', deleted tge wrong config entry.", cv->name, co->name);
216 + cv_new = appconfig_option_index_find(co_new, name_new, 0);
217 + if(cv_new) goto cleanup;
218
217 - freez(cv->name);
218 - cv->name = strdupz(new);
219 - cv->hash = simple_hash(cv->name);
220 - if(unlikely(appconfig_option_index_add(co, cv) != cv))
221 - error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv->name, co->name);
219 + if(unlikely(appconfig_option_index_del(co_old, cv_old) != cv_old))
220 + error("INTERNAL ERROR: deletion of config '%s' from section '%s', deleted tge wrong config entry.", cv_old->name, co_old->name);
221
223 - config_section_unlock(co);
222 + if(co_old->values == cv_old) {
223 + co_old->values = cv_old->next;
224 + }
225 + else {
226 + struct config_option *t;
227 + for(t = co_old->values; t && t->next != cv_old ;t = t->next) ;
228 + if(!t || t->next != cv_old)
229 + error("INTERNAL ERROR: cannot find variable '%s' in section '%s' of the config - but it should be there.", cv_old->name, co_old->name);
230 + else
231 + t->next = cv_old->next;
232 + }
233
225 - return 0;
234 + freez(cv_old->name);
235 + cv_old->name = strdupz(name_new);
236 + cv_old->hash = simple_hash(cv_old->name);
237 +
238 + cv_new->next = co_new->values;
239 + co_new->values = cv_new;
240 +
241 + if(unlikely(appconfig_option_index_add(co_new, cv_old) != cv_old))
242 + error("INTERNAL ERROR: indexing of config '%s' in section '%s', already exists.", cv_old->name, co_new->name);
243 +
244 + ret = 0;
245
246 cleanup:
228 - config_section_unlock(co);
229 - return -1;
247 + config_section_unlock(co_new);
248 + config_section_unlock(co_old);
249 + return ret;
250 }
251
252 char *appconfig_get(struct config *root, const char *section, const char *name, const char *default_value)
@@ -503,12 +523,13 @@ void appconfig_generate(struct config *root, BUFFER *wb, int only_changed)
523
524 appconfig_wrlock(root);
525 for(co = root->sections; co ; co = co->next) {
506 - if(!strcmp(co->name, "global")
507 - || !strcmp(co->name, "plugins")
508 - || !strcmp(co->name, "registry")
509 - || !strcmp(co->name, "health")
510 - || !strcmp(co->name, "backend")
511 - || !strcmp(co->name, "stream")
526 + if(!strcmp(co->name, CONFIG_SECTION_GLOBAL)
527 + || !strcmp(co->name, CONFIG_SECTION_API)
528 + || !strcmp(co->name, CONFIG_SECTION_PLUGINS)
529 + || !strcmp(co->name, CONFIG_SECTION_REGISTRY)
530 + || !strcmp(co->name, CONFIG_SECTION_HEALTH)
531 + || !strcmp(co->name, CONFIG_SECTION_BACKEND)
532 + || !strcmp(co->name, CONFIG_SECTION_STREAM)
533 )
534 pri = 0;
535 else if(!strncmp(co->name, "plugin:", 7)) pri = 1;
src/appconfig.h
+10 -2
@@ -3,6 +3,14 @@
3
4 #define CONFIG_FILENAME "netdata.conf"
5
6 +#define CONFIG_SECTION_GLOBAL "global"
7 +#define CONFIG_SECTION_API "api"
8 +#define CONFIG_SECTION_PLUGINS "plugins"
9 +#define CONFIG_SECTION_REGISTRY "registry"
10 +#define CONFIG_SECTION_HEALTH "health"
11 +#define CONFIG_SECTION_BACKEND "backend"
12 +#define CONFIG_SECTION_STREAM "stream"
13 +
14 // these are used to limit the configuration names and values lengths
15 // they are not enforced by config.c functions (they will strdup() all strings, no matter of their length)
16 #define CONFIG_MAX_NAME 1024
@@ -35,7 +43,7 @@ extern long long appconfig_set_number(struct config *root, const char *section,
43 extern int appconfig_set_boolean(struct config *root, const char *section, const char *name, int value);
44
45 extern int appconfig_exists(struct config *root, const char *section, const char *name);
38 -extern int appconfig_rename(struct config *root, const char *section, const char *old, const char *new);
46 +extern int appconfig_move(struct config *root, const char *section_old, const char *name_old, const char *section_new, const char *name_new);
47
48 extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed);
49
@@ -54,7 +62,7 @@ extern void appconfig_generate(struct config *root, BUFFER *wb, int only_changed
62 #define config_set_boolean(section, name, value) appconfig_set_boolean(&netdata_config, section, name, value)
63
64 #define config_exists(section, name) appconfig_exists(&netdata_config, section, name)
57 -#define config_rename(section, old, new) appconfig_rename(&netdata_config, section, old, new)
65 +#define config_move(section_old, name_old, section_new, name_new) appconfig_move(&netdata_config, section_old, name_old, section_new, name_new)
66
67 #define config_generate(buffer, only_changed) appconfig_generate(&netdata_config, buffer, only_changed)
68
src/backends.c
+9 -9
@@ -152,15 +152,15 @@ void *backends_main(void *ptr) {
152 .tv_usec = 0
153 };
154 uint32_t options;
155 - int enabled = config_get_boolean("backend", "enabled", 0);
156 - const char *source = config_get("backend", "data source", "average");
157 - const char *type = config_get("backend", "type", "graphite");
158 - const char *destination = config_get("backend", "destination", "localhost");
159 - const char *prefix = config_get("backend", "prefix", "netdata");
160 - const char *hostname = config_get("backend", "hostname", localhost->hostname);
161 - int frequency = (int)config_get_number("backend", "update every", 10);
162 - int buffer_on_failures = (int)config_get_number("backend", "buffer on failures", 10);
163 - long timeoutms = config_get_number("backend", "timeout ms", frequency * 2 * 1000);
155 + int enabled = config_get_boolean(CONFIG_SECTION_BACKEND, "enabled", 0);
156 + const char *source = config_get(CONFIG_SECTION_BACKEND, "data source", "average");
157 + const char *type = config_get(CONFIG_SECTION_BACKEND, "type", "graphite");
158 + const char *destination = config_get(CONFIG_SECTION_BACKEND, "destination", "localhost");
159 + const char *prefix = config_get(CONFIG_SECTION_BACKEND, "prefix", "netdata");
160 + const char *hostname = config_get(CONFIG_SECTION_BACKEND, "hostname", localhost->hostname);
161 + int frequency = (int)config_get_number(CONFIG_SECTION_BACKEND, "update every", 10);
162 + int buffer_on_failures = (int)config_get_number(CONFIG_SECTION_BACKEND, "buffer on failures", 10);
163 + long timeoutms = config_get_number(CONFIG_SECTION_BACKEND, "timeout ms", frequency * 2 * 1000);
164
165 // ------------------------------------------------------------------------
166 // validate configuration options
src/common.c
+1
@@ -8,6 +8,7 @@
8 # define MADV_DONTFORK INHERIT_NONE
9 #endif /* __FreeBSD__ || __APPLE__*/
10
11 +char *netdata_configured_hostname = NULL;
12 char *netdata_configured_config_dir = NULL;
13 char *netdata_configured_log_dir = NULL;
14 char *netdata_configured_plugins_dir = NULL;
src/common.h
+1
@@ -220,6 +220,7 @@
220 #include "web_api_v1.h"
221 #include "web_api_old.h"
222
223 +extern char *netdata_configured_hostname;
224 extern char *netdata_configured_config_dir;
225 extern char *netdata_configured_log_dir;
226 extern char *netdata_configured_plugins_dir;
src/daemon.c
+4 -4
@@ -156,7 +156,7 @@ int become_user(const char *username, int pid_fd)
156 }
157
158 static void oom_score_adj(void) {
159 - int score = (int)config_get_number("global", "OOM score", 1000);
159 + int score = (int)config_get_number(CONFIG_SECTION_GLOBAL, "OOM score", 1000);
160
161 int done = 0;
162 int fd = open("/proc/self/oom_score_adj", O_WRONLY);
@@ -175,7 +175,7 @@ static void oom_score_adj(void) {
175
176 static void process_nice_level(void) {
177 #ifdef HAVE_NICE
178 - int nice_level = (int)config_get_number("global", "process nice level", 19);
178 + int nice_level = (int)config_get_number(CONFIG_SECTION_GLOBAL, "process nice level", 19);
179 if(nice(nice_level) == -1) error("Cannot set netdata CPU nice level to %d.", nice_level);
180 else debug(D_SYSTEM, "Set netdata nice level to %d.", nice_level);
181 #endif // HAVE_NICE
@@ -239,7 +239,7 @@ static void sched_setscheduler_set(void) {
239 int found = 0;
240
241 // read the configuration
242 - name = config_get("global", "process scheduling policy", name);
242 + name = config_get(CONFIG_SECTION_GLOBAL, "process scheduling policy", name);
243 int i;
244 for(i = 0 ; scheduler_defaults[i].name ; i++) {
245 if(!strcmp(name, scheduler_defaults[i].name)) {
@@ -251,7 +251,7 @@ static void sched_setscheduler_set(void) {
251 return;
252
253 if(flags & SCHED_FLAG_PRIORITY_CONFIGURABLE)
254 - priority = (int)config_get_number("global", "process scheduling priority", priority);
254 + priority = (int)config_get_number(CONFIG_SECTION_GLOBAL, "process scheduling priority", priority);
255
256 #ifdef HAVE_SCHED_GET_PRIORITY_MIN
257 if(priority < sched_get_priority_min(policy)) {
src/health.c
+4 -4
@@ -9,13 +9,13 @@ int default_health_enabled = 1;
9 inline char *health_config_dir(void) {
10 char buffer[FILENAME_MAX + 1];
11 snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_config_dir);
12 - return config_get("health", "health configuration directory", buffer);
12 + return config_get(CONFIG_SECTION_HEALTH, "health configuration directory", buffer);
13 }
14
15 void health_init(void) {
16 debug(D_HEALTH, "Health configuration initializing");
17
18 - if(!(default_health_enabled = config_get_boolean("health", "enabled", 1))) {
18 + if(!(default_health_enabled = config_get_boolean(CONFIG_SECTION_HEALTH, "enabled", 1))) {
19 debug(D_HEALTH, "Health is disabled.");
20 return;
21 }
@@ -324,7 +324,7 @@ void *health_main(void *ptr) {
324 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
325 error("Cannot set pthread cancel state to ENABLE.");
326
327 - int min_run_every = (int)config_get_number("health", "run at least every seconds", 10);
327 + int min_run_every = (int)config_get_number(CONFIG_SECTION_HEALTH, "run at least every seconds", 10);
328 if(min_run_every < 1) min_run_every = 1;
329
330 BUFFER *wb = buffer_create(100);
@@ -333,7 +333,7 @@ void *health_main(void *ptr) {
333 time_t now_boottime = now_boottime_sec();
334 time_t last_now = now;
335 time_t last_now_boottime = now_boottime;
336 - time_t hibernation_delay = config_get_number("health", "postpone alarms during hibernation for seconds", 60);
336 + time_t hibernation_delay = config_get_number(CONFIG_SECTION_HEALTH, "postpone alarms during hibernation for seconds", 60);
337
338 unsigned int loop = 0;
339 while(!netdata_exit) {
src/health_log.c
+1 -1
@@ -32,7 +32,7 @@ inline void health_log_rotate(RRDHOST *host) {
32 static size_t rotate_every = 0;
33
34 if(unlikely(rotate_every == 0)) {
35 - rotate_every = (size_t)config_get_number("health", "rotate log every lines", 2000);
35 + rotate_every = (size_t)config_get_number(CONFIG_SECTION_HEALTH, "rotate log every lines", 2000);
36 if(rotate_every < 100) rotate_every = 100;
37 }
38
src/main.c
+222 -200
@@ -35,41 +35,35 @@ struct netdata_static_thread static_threads[] = {
35 #ifdef INTERNAL_PLUGIN_NFACCT
36 // nfacct requires root access
37 // so, we build it as an external plugin with setuid to root
38 - {"nfacct", "plugins", "nfacct", 1, NULL, NULL, nfacct_main},
38 + {"nfacct", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
39 #endif
40
41 - {"tc", "plugins", "tc", 1, NULL, NULL, tc_main},
42 - {"idlejitter", "plugins", "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
41 + {"tc", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
42 + {"idlejitter", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
43 #if defined(__FreeBSD__)
44 - {"freebsd", "plugins", "freebsd", 1, NULL, NULL, freebsd_main},
44 + {"freebsd", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
45 #elif defined(__APPLE__)
46 - {"macos", "plugins", "macos", 1, NULL, NULL, macos_main},
46 + {"macos", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
47 #else
48 - {"proc", "plugins", "proc", 1, NULL, NULL, proc_main},
49 - {"diskspace", "plugins", "diskspace", 1, NULL, NULL, proc_diskspace_main},
50 - {"cgroups", "plugins", "cgroups", 1, NULL, NULL, cgroups_main},
48 + {"proc", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
49 + {"diskspace", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
50 + {"cgroups", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
51 #endif /* __FreeBSD__, __APPLE__*/
52 - {"check", "plugins", "checks", 0, NULL, NULL, checks_main},
53 - {"backends", NULL, NULL, 1, NULL, NULL, backends_main},
54 - {"health", NULL, NULL, 1, NULL, NULL, health_main},
55 - {"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
56 - {"web", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
57 - {"web-single-threaded", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
58 - {"push-metrics", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
59 - {NULL, NULL, NULL, 0, NULL, NULL, NULL}
52 + {"check", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
53 + {"backends", NULL, NULL, 1, NULL, NULL, backends_main},
54 + {"health", NULL, NULL, 1, NULL, NULL, health_main},
55 + {"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
56 + {"web", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
57 + {"web-single-threaded", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
58 + {"push-metrics", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
59 + {NULL, NULL, NULL, 0, NULL, NULL, NULL}
60 };
61
62 void web_server_threading_selection(void) {
63 - int multi_threaded = 0;
64 - int single_threaded = 0;
63 + web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_API, "mode", web_server_mode_name(web_server_mode)));
64
66 - if(default_rrdpush_exclusive) {
67 - info("Web server is disabled - use the remote netdata.");
68 - }
69 - else {
70 - multi_threaded = config_get_boolean("global", "multi threaded web server", 1);
71 - single_threaded = !multi_threaded;
72 - }
65 + int multi_threaded = (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED);
66 + int single_threaded = (web_server_mode == WEB_SERVER_MODE_SINGLE_THREADED);
67
68 int i;
69 for(i = 0; static_threads[i].name ; i++) {
@@ -80,19 +74,16 @@ void web_server_threading_selection(void) {
74 static_threads[i].enabled = single_threaded;
75 }
76
83 - if(default_rrdpush_exclusive)
84 - return;
85 -
86 - web_client_timeout = (int) config_get_number("global", "disconnect idle web clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
77 + web_client_timeout = (int) config_get_number(CONFIG_SECTION_API, "disconnect idle clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
78
88 - respect_web_browser_do_not_track_policy = config_get_boolean("global", "respect web browser do not track policy", respect_web_browser_do_not_track_policy);
89 - web_x_frame_options = config_get("global", "web x-frame-options header", "");
79 + respect_web_browser_do_not_track_policy = config_get_boolean(CONFIG_SECTION_API, "respect do not track policy", respect_web_browser_do_not_track_policy);
80 + web_x_frame_options = config_get("web", "x-frame-options header", "");
81 if(!*web_x_frame_options) web_x_frame_options = NULL;
82
83 #ifdef NETDATA_WITH_ZLIB
93 - web_enable_gzip = config_get_boolean("global", "enable web responses gzip compression", web_enable_gzip);
84 + web_enable_gzip = config_get_boolean(CONFIG_SECTION_API, "gzip compression", web_enable_gzip);
85
95 - char *s = config_get("global", "web compression strategy", "default");
86 + char *s = config_get(CONFIG_SECTION_API, "compression strategy", "default");
87 if(!strcmp(s, "default"))
88 web_gzip_strategy = Z_DEFAULT_STRATEGY;
89 else if(!strcmp(s, "filtered"))
@@ -108,7 +99,7 @@ void web_server_threading_selection(void) {
99 web_gzip_strategy = Z_DEFAULT_STRATEGY;
100 }
101
111 - web_gzip_level = (int)config_get_number("global", "web compression level", 3);
102 + web_gzip_level = (int)config_get_number(CONFIG_SECTION_API, "compression level", 3);
103 if(web_gzip_level < 1) {
104 error("Invalid compression level %d. Valid levels are 1 (fastest) to 9 (best ratio). Proceeding with level 1 (fastest compression).", web_gzip_level);
105 web_gzip_level = 1;
@@ -348,18 +339,180 @@ static const char *verify_required_directory(const char *dir) {
339 return dir;
340 }
341
351 -static void get_netdata_configured_directories() {
352 - netdata_configured_config_dir = config_get("global", "config directory", CONFIG_DIR);
353 - netdata_configured_log_dir = config_get("global", "log directory", LOG_DIR);
354 - netdata_configured_plugins_dir = config_get("global", "plugins directory", PLUGINS_DIR);
355 - netdata_configured_web_dir = config_get("global", "web files directory", WEB_DIR);
356 - netdata_configured_cache_dir = config_get("global", "cache directory", CACHE_DIR);
357 - netdata_configured_varlib_dir = config_get("global", "lib directory", VARLIB_DIR);
358 - netdata_configured_home_dir = config_get("global", "home directory", CACHE_DIR);
342 +void log_init(void) {
343 + char filename[FILENAME_MAX + 1];
344 + snprintfz(filename, FILENAME_MAX, "%s/debug.log", netdata_configured_log_dir);
345 + stdout_filename = config_get(CONFIG_SECTION_GLOBAL, "debug log", filename);
346 +
347 + snprintfz(filename, FILENAME_MAX, "%s/error.log", netdata_configured_log_dir);
348 + stderr_filename = config_get(CONFIG_SECTION_GLOBAL, "error log", filename);
349 +
350 + snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
351 + stdaccess_filename = config_get(CONFIG_SECTION_GLOBAL, "access log", filename);
352 +
353 + error_log_throttle_period_backup =
354 + error_log_throttle_period = config_get_number(CONFIG_SECTION_GLOBAL, "errors flood protection period", error_log_throttle_period);
355 + 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);
356 +
357 + setenv("NETDATA_ERRORS_THROTTLE_PERIOD", config_get(CONFIG_SECTION_GLOBAL, "errors flood protection period" , ""), 1);
358 + setenv("NETDATA_ERRORS_PER_PERIOD", config_get(CONFIG_SECTION_GLOBAL, "errors to trigger flood protection", ""), 1);
359 +}
360 +
361 +static void backwards_compatible_config() {
362 + // allow existing configurations to work with the current version of netdata
363 +
364 + if(config_exists(CONFIG_SECTION_GLOBAL, "multi threaded web server")) {
365 + int mode = config_get_boolean(CONFIG_SECTION_GLOBAL, "multi threaded web server", 1);
366 + web_server_mode = (mode)?WEB_SERVER_MODE_MULTI_THREADED:WEB_SERVER_MODE_SINGLE_THREADED;
367 + }
368 +
369 + if(config_exists(CONFIG_SECTION_GLOBAL, "bind socket to IP") && !config_exists(CONFIG_SECTION_API, "bind to"))
370 + config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP", CONFIG_SECTION_API, "bind to");
371 +
372 + if(config_exists(CONFIG_SECTION_GLOBAL, "bind to") && !config_exists(CONFIG_SECTION_API, "bind to"))
373 + config_move(CONFIG_SECTION_GLOBAL, "bind to", CONFIG_SECTION_API, "bind to");
374 +
375 + if(config_exists(CONFIG_SECTION_GLOBAL, "port") && !config_exists(CONFIG_SECTION_API, "default port"))
376 + config_move(CONFIG_SECTION_GLOBAL, "port", CONFIG_SECTION_API, "default port");
377 +
378 + if(config_exists(CONFIG_SECTION_GLOBAL, "default port") && !config_exists(CONFIG_SECTION_API, "default port"))
379 + config_move(CONFIG_SECTION_GLOBAL, "default port", CONFIG_SECTION_API, "default port");
380 +
381 + if(config_exists(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds") && !config_exists(CONFIG_SECTION_API, "disconnect idle clients after seconds"))
382 + config_move(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds", CONFIG_SECTION_API, "disconnect idle clients after seconds");
383 +
384 + if(config_exists(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy") && !config_exists(CONFIG_SECTION_API, "respect do not track policy"))
385 + config_move(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy", CONFIG_SECTION_API, "respect do not track policy");
386 +
387 + if(config_exists(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression") && !config_exists(CONFIG_SECTION_API, "gzip compression"))
388 + config_move(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression", CONFIG_SECTION_API, "gzip compression");
389 +
390 + if(config_exists(CONFIG_SECTION_GLOBAL, "web compression strategy") && !config_exists(CONFIG_SECTION_API, "compression strategy"))
391 + config_move(CONFIG_SECTION_GLOBAL, "web compression strategy", CONFIG_SECTION_API, "compression strategy");
392 +
393 + if(config_exists(CONFIG_SECTION_GLOBAL, "web compression level") && !config_exists(CONFIG_SECTION_API, "compression level"))
394 + config_move(CONFIG_SECTION_GLOBAL, "web compression level", CONFIG_SECTION_API, "compression level");
395 +
396 + if(config_exists(CONFIG_SECTION_GLOBAL, "web files owner") && !config_exists(CONFIG_SECTION_API, "web files owner"))
397 + config_move(CONFIG_SECTION_GLOBAL, "web files owner", CONFIG_SECTION_API, "web files owner");
398 +
399 + if(config_exists(CONFIG_SECTION_GLOBAL, "web files group") && !config_exists(CONFIG_SECTION_API, "web files group"))
400 + config_move(CONFIG_SECTION_GLOBAL, "web files group", CONFIG_SECTION_API, "web files group");
401 +}
402 +
403 +static void get_netdata_configured_variables() {
404 + backwards_compatible_config();
405 +
406 + // ------------------------------------------------------------------------
407 + // get the hostname
408 +
409 + char buf[HOSTNAME_MAX + 1];
410 + if(gethostname(buf, HOSTNAME_MAX) == -1)
411 + error("WARNING: Cannot get machine hostname.");
412 +
413 + netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", buf);
414 + debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
415 +
416 + netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", CONFIG_DIR);
417 +
418 + // ------------------------------------------------------------------------
419 + // get default database size
420 +
421 + default_rrd_history_entries = (int) config_get_number(CONFIG_SECTION_GLOBAL, "history", align_entries_to_pagesize(default_rrd_memory_mode, RRD_DEFAULT_HISTORY_ENTRIES));
422 +
423 + long h = align_entries_to_pagesize(default_rrd_memory_mode, default_rrd_history_entries);
424 + if(h != default_rrd_history_entries) {
425 + config_set_number(CONFIG_SECTION_GLOBAL, "history", h);
426 + default_rrd_history_entries = (int)h;
427 + }
428 +
429 + if(default_rrd_history_entries < 5 || default_rrd_history_entries > RRD_HISTORY_ENTRIES_MAX) {
430 + error("Invalid history entries %d given. Defaulting to %d.", default_rrd_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
431 + default_rrd_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
432 + }
433 +
434 + // ------------------------------------------------------------------------
435 + // get default database update frequency
436 +
437 + default_rrd_update_every = (int) config_get_number(CONFIG_SECTION_GLOBAL, "update every", UPDATE_EVERY);
438 + if(default_rrd_update_every < 1 || default_rrd_update_every > 600) {
439 + error("Invalid data collection frequency (update every) %d given. Defaulting to %d.", default_rrd_update_every, UPDATE_EVERY_MAX);
440 + default_rrd_update_every = UPDATE_EVERY;
441 + }
442 +
443 + // ------------------------------------------------------------------------
444 + // let the plugins know the min update_every
445 +
446 + // get system paths
447 + netdata_configured_config_dir = config_get(CONFIG_SECTION_GLOBAL, "config directory", CONFIG_DIR);
448 + netdata_configured_log_dir = config_get(CONFIG_SECTION_GLOBAL, "log directory", LOG_DIR);
449 + netdata_configured_plugins_dir = config_get(CONFIG_SECTION_GLOBAL, "plugins directory", PLUGINS_DIR);
450 + netdata_configured_web_dir = config_get(CONFIG_SECTION_GLOBAL, "web files directory", WEB_DIR);
451 + netdata_configured_cache_dir = config_get(CONFIG_SECTION_GLOBAL, "cache directory", CACHE_DIR);
452 + netdata_configured_varlib_dir = config_get(CONFIG_SECTION_GLOBAL, "lib directory", VARLIB_DIR);
453 + netdata_configured_home_dir = config_get(CONFIG_SECTION_GLOBAL, "home directory", CACHE_DIR);
454 +
455 + // ------------------------------------------------------------------------
456 + // get default memory mode for the database
457 +
458 + default_rrd_memory_mode = rrd_memory_mode_id(config_get(CONFIG_SECTION_GLOBAL, "memory mode", rrd_memory_mode_name(default_rrd_memory_mode)));
459 +
460 + // ------------------------------------------------------------------------
461 +
462 + netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
463 +
464 + // --------------------------------------------------------------------
465 + // get KSM settings
466 +
467 +#ifdef MADV_MERGEABLE
468 + enable_ksm = config_get_boolean(CONFIG_SECTION_GLOBAL, "memory deduplication (ksm)", enable_ksm);
469 +#endif
470 +
471 + // --------------------------------------------------------------------
472 + // get various system parameters
473 +
474 + get_system_HZ();
475 + get_system_cpus();
476 + get_system_pid_max();
477 +}
478 +
479 +void set_global_environment() {
480 + {
481 + char b[16];
482 + snprintfz(b, 15, "%d", default_rrd_update_every);
483 + setenv("NETDATA_UPDATE_EVERY", b, 1);
484 + }
485 +
486 + setenv("NETDATA_HOSTNAME" , netdata_configured_hostname, 1);
487 + setenv("NETDATA_CONFIG_DIR" , verify_required_directory(netdata_configured_config_dir), 1);
488 + setenv("NETDATA_PLUGINS_DIR", verify_required_directory(netdata_configured_plugins_dir), 1);
489 + setenv("NETDATA_WEB_DIR" , verify_required_directory(netdata_configured_web_dir), 1);
490 + setenv("NETDATA_CACHE_DIR" , verify_required_directory(netdata_configured_cache_dir), 1);
491 + setenv("NETDATA_LIB_DIR" , verify_required_directory(netdata_configured_varlib_dir), 1);
492 + setenv("NETDATA_LOG_DIR" , verify_required_directory(netdata_configured_log_dir), 1);
493 + setenv("HOME" , verify_required_directory(netdata_configured_home_dir), 1);
494 + setenv("NETDATA_HOST_PREFIX", netdata_configured_host_prefix, 1);
495 +
496 + // avoid flood calls to stat(/etc/localtime)
497 + // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
498 + setenv("TZ", ":/etc/localtime", 0);
499 +
500 + // set the path we need
501 + char path[1024 + 1], *p = getenv("PATH");
502 + if(!p) p = "/bin:/usr/bin";
503 + snprintfz(path, 1024, "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
504 + setenv("PATH", config_get(CONFIG_SECTION_PLUGINS, "PATH environment variable", path), 1);
505 +
506 + // python options
507 + p = getenv("PYTHONPATH");
508 + if(!p) p = "";
509 + setenv("PYTHONPATH", config_get(CONFIG_SECTION_PLUGINS, "PYTHONPATH environment variable", p), 1);
510 +
511 + // disable buffering for python plugins
512 + setenv("PYTHONUNBUFFERED", "1", 1);
513 }
514
515 int main(int argc, char **argv) {
362 - char *hostname = "localhost";
516 int i, check_config = 0;
517 int config_loaded = 0;
518 int dont_fork = 0;
@@ -385,12 +538,12 @@ int main(int argc, char **argv) {
538 remove_option(i, &argc, argv);
539 }
540 else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) {
388 - config_set("global", "host access prefix", argv[i+1]);
541 + config_set(CONFIG_SECTION_GLOBAL, "host access prefix", argv[i+1]);
542 fprintf(stderr, "%s: deprecated option -- %s -- please use -s instead.\n", argv[0], argv[i]);
543 remove_option(i, &argc, argv);
544 }
545 else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) {
393 - config_set("global", "history", argv[i+1]);
546 + config_set(CONFIG_SECTION_GLOBAL, "history", argv[i+1]);
547 fprintf(stderr, "%s: deprecated option -- %s -- This option will be removed with V2.*.\n", argv[0], argv[i]);
548 remove_option(i, &argc, argv);
549 }
@@ -436,7 +589,7 @@ int main(int argc, char **argv) {
589 help(0);
590 break;
591 case 'i':
439 - config_set("global", "bind to", optarg);
592 + config_set(CONFIG_SECTION_API, "bind to", optarg);
593 break;
594 case 'k':
595 dont_fork = 1;
@@ -447,16 +600,16 @@ int main(int argc, char **argv) {
600 pidfile[FILENAME_MAX] = '\0';
601 break;
602 case 'p':
450 - config_set("global", "default port", optarg);
603 + config_set(CONFIG_SECTION_GLOBAL, "default port", optarg);
604 break;
605 case 's':
453 - config_set("global", "host access prefix", optarg);
606 + config_set(CONFIG_SECTION_GLOBAL, "host access prefix", optarg);
607 break;
608 case 't':
456 - config_set("global", "update every", optarg);
609 + config_set(CONFIG_SECTION_GLOBAL, "update every", optarg);
610 break;
611 case 'u':
459 - config_set("global", "run as user", optarg);
612 + config_set(CONFIG_SECTION_GLOBAL, "run as user", optarg);
613 break;
614 case 'v':
615 printf("%s %s\n", program_name, program_version);
@@ -468,7 +621,7 @@ int main(int argc, char **argv) {
621 if(strcmp(optarg, "unittest") == 0) {
622 default_rrd_update_every = 1;
623 if(!config_loaded) config_load(NULL, 0);
471 - get_netdata_configured_directories();
624 + get_netdata_configured_variables();
625 registry_init();
626 rrd_init("unittest");
627 if(run_all_mockup_tests()) exit(1);
@@ -520,11 +673,11 @@ int main(int argc, char **argv) {
673 }
674 else if(strncmp(optarg, stacksize_string, strlen(stacksize_string)) == 0) {
675 optarg += strlen(stacksize_string);
523 - config_set("global", "pthread stack size", optarg);
676 + config_set(CONFIG_SECTION_GLOBAL, "pthread stack size", optarg);
677 }
678 else if(strncmp(optarg, debug_flags_string, strlen(debug_flags_string)) == 0) {
679 optarg += strlen(debug_flags_string);
527 - config_set("global", "debug flags", optarg);
680 + config_set(CONFIG_SECTION_GLOBAL, "debug flags", optarg);
681 debug_flags = strtoull(optarg, NULL, 0);
682 }
683 }
@@ -550,52 +703,26 @@ int main(int argc, char **argv) {
703 config_load(NULL, 0);
704
705 {
553 - char *pmax = config_get("global", "glibc malloc arena max for plugins", "1");
706 + char *pmax = config_get(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for plugins", "1");
707 if(pmax && *pmax)
708 setenv("MALLOC_ARENA_MAX", pmax, 1);
709
710 #if defined(HAVE_C_MALLOPT)
558 - i = (int)config_get_number("global", "glibc malloc arena max for netdata", 1);
711 + i = (int)config_get_number(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for netdata", 1);
712 if(i > 0)
713 mallopt(M_ARENA_MAX, 1);
714 #endif
715
716 // prepare configuration environment variables for the plugins
717
565 - get_netdata_configured_directories();
566 -
567 - setenv("NETDATA_CONFIG_DIR" , verify_required_directory(netdata_configured_config_dir), 1);
568 - setenv("NETDATA_PLUGINS_DIR", verify_required_directory(netdata_configured_plugins_dir), 1);
569 - setenv("NETDATA_WEB_DIR" , verify_required_directory(netdata_configured_web_dir), 1);
570 - setenv("NETDATA_CACHE_DIR" , verify_required_directory(netdata_configured_cache_dir), 1);
571 - setenv("NETDATA_LIB_DIR" , verify_required_directory(netdata_configured_varlib_dir), 1);
572 - setenv("NETDATA_LOG_DIR" , verify_required_directory(netdata_configured_log_dir), 1);
573 - setenv("HOME" , verify_required_directory(netdata_configured_home_dir), 1);
574 -
575 - netdata_configured_host_prefix = config_get("global", "host access prefix", "");
576 - setenv("NETDATA_HOST_PREFIX", netdata_configured_host_prefix, 1);
577 -
578 - // disable buffering for python plugins
579 - setenv("PYTHONUNBUFFERED", "1", 1);
580 -
581 - // avoid flood calls to stat(/etc/localtime)
582 - // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
583 - setenv("TZ", ":/etc/localtime", 0);
718 + get_netdata_configured_variables();
719 + set_global_environment();
720
721 // work while we are cd into config_dir
722 // to allow the plugins refer to their config
723 // files using relative filenames
724 if(chdir(netdata_configured_config_dir) == -1)
725 fatal("Cannot cd to '%s'", netdata_configured_config_dir);
590 -
591 - char path[1024 + 1], *p = getenv("PATH");
592 - if(!p) p = "/bin:/usr/bin";
593 - snprintfz(path, 1024, "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
594 - setenv("PATH", config_get("plugins", "PATH environment variable", path), 1);
595 -
596 - p = getenv("PYTHONPATH");
597 - if(!p) p = "";
598 - setenv("PYTHONPATH", config_get("plugins", "PYTHONPATH environment variable", p), 1);
726 }
727
728 char *user = NULL;
@@ -604,7 +731,7 @@ int main(int argc, char **argv) {
731 // --------------------------------------------------------------------
732 // get the debugging flags from the configuration file
733
607 - char *flags = config_get("global", "debug flags", "0x0000000000000000");
734 + char *flags = config_get(CONFIG_SECTION_GLOBAL, "debug flags", "0x0000000000000000");
735 setenv("NETDATA_DEBUG_FLAGS", flags, 1);
736
737 debug_flags = strtoull(flags, NULL, 0);
@@ -624,26 +751,7 @@ int main(int argc, char **argv) {
751 // --------------------------------------------------------------------
752 // get log filenames and settings
753
627 - {
628 - char filename[FILENAME_MAX + 1];
629 - snprintfz(filename, FILENAME_MAX, "%s/debug.log", netdata_configured_log_dir);
630 - stdout_filename = config_get("global", "debug log", filename);
631 -
632 - snprintfz(filename, FILENAME_MAX, "%s/error.log", netdata_configured_log_dir);
633 - stderr_filename = config_get("global", "error log", filename);
634 -
635 - snprintfz(filename, FILENAME_MAX, "%s/access.log", netdata_configured_log_dir);
636 - stdaccess_filename = config_get("global", "access log", filename);
637 - }
638 -
639 - error_log_throttle_period_backup =
640 - error_log_throttle_period = config_get_number("global", "errors flood protection period", error_log_throttle_period);
641 -
642 - setenv("NETDATA_ERRORS_THROTTLE_PERIOD", config_get("global", "errors flood protection period" , ""), 1);
643 -
644 - error_log_errors_per_period = (unsigned long)config_get_number("global", "errors to trigger flood protection", (long long int)error_log_errors_per_period);
645 - setenv("NETDATA_ERRORS_PER_PERIOD", config_get("global", "errors to trigger flood protection", ""), 1);
646 -
754 + log_init();
755 if(check_config) {
756 stdout_filename = stderr_filename = stdaccess_filename = "system";
757 error_log_throttle_period = 0;
@@ -651,98 +759,6 @@ int main(int argc, char **argv) {
759 }
760 error_log_limit_unlimited();
761
654 -
655 - // --------------------------------------------------------------------
656 - // get KSM settings
657 -
658 -#ifdef MADV_MERGEABLE
659 - enable_ksm = config_get_boolean("global", "memory deduplication (ksm)", enable_ksm);
660 -#else
661 -#warning "Kernel memory deduplication (KSM) is not available"
662 -#endif
663 -
664 - // --------------------------------------------------------------------
665 - // get various system parameters
666 -
667 - get_system_HZ();
668 - get_system_cpus();
669 - get_system_pid_max();
670 -
671 -
672 - // --------------------------------------------------------------------
673 - // find the system hostname
674 -
675 - {
676 - char hostnamebuf[HOSTNAME_MAX + 1];
677 - if(gethostname(hostnamebuf, HOSTNAME_MAX) == -1)
678 - error("WARNING: Cannot get machine hostname.");
679 -
680 - hostname = config_get("global", "hostname", hostnamebuf);
681 - debug(D_OPTIONS, "hostname set to '%s'", hostname);
682 -
683 - setenv("NETDATA_HOSTNAME", hostname, 1);
684 - }
685 -
686 -
687 - // --------------------------------------------------------------------
688 - // find we need to send data to another netdata
689 -
690 - rrdpush_init();
691 -
692 -
693 - // --------------------------------------------------------------------
694 - // get default memory mode for the database
695 -
696 - if(default_rrdpush_exclusive) {
697 - default_rrd_memory_mode = RRD_MEMORY_MODE_NONE;
698 - config_set("global", "memory mode", rrd_memory_mode_name(default_rrd_memory_mode));
699 - }
700 - else
701 - default_rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(default_rrd_memory_mode)));
702 -
703 -
704 - // --------------------------------------------------------------------
705 - // get default database size
706 -
707 - if(default_rrdpush_exclusive) {
708 - default_rrd_history_entries = 10;
709 - config_set_number("global", "history", default_rrd_history_entries);
710 - }
711 - else
712 - default_rrd_history_entries = (int) config_get_number("global", "history", align_entries_to_pagesize(default_rrd_memory_mode, RRD_DEFAULT_HISTORY_ENTRIES));
713 -
714 - long h = align_entries_to_pagesize(default_rrd_memory_mode, default_rrd_history_entries);
715 - if(h != default_rrd_history_entries) {
716 - config_set_number("global", "history", h);
717 - default_rrd_history_entries = (int)h;
718 - }
719 -
720 - if(default_rrd_history_entries < 5 || default_rrd_history_entries > RRD_HISTORY_ENTRIES_MAX) {
721 - error("Invalid history entries %d given. Defaulting to %d.", default_rrd_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
722 - default_rrd_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
723 - }
724 - else
725 - debug(D_OPTIONS, "save lines set to %d.", default_rrd_history_entries);
726 -
727 -
728 - // --------------------------------------------------------------------
729 - // get default database update frequency
730 -
731 - default_rrd_update_every = (int) config_get_number("global", "update every", UPDATE_EVERY);
732 - if(default_rrd_update_every < 1 || default_rrd_update_every > 600) {
733 - error("Invalid data collection frequency (update every) %d given. Defaulting to %d.", default_rrd_update_every, UPDATE_EVERY_MAX);
734 - default_rrd_update_every = UPDATE_EVERY;
735 - }
736 - else debug(D_OPTIONS, "update timer set to %d.", default_rrd_update_every);
737 -
738 - // let the plugins know the min update_every
739 - {
740 - char buf[16];
741 - snprintfz(buf, 15, "%d", default_rrd_update_every);
742 - setenv("NETDATA_UPDATE_EVERY", buf, 1);
743 - }
744 -
745 -
762 // --------------------------------------------------------------------
763 // setup process signals
764
@@ -804,7 +820,7 @@ int main(int argc, char **argv) {
820 else
821 debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
822
807 - wanted_stacksize = (size_t)config_get_number("global", "pthread stack size", (long)stacksize);
823 + wanted_stacksize = (size_t)config_get_number(CONFIG_SECTION_GLOBAL, "pthread stack size", (long)stacksize);
824
825
826 // --------------------------------------------------------------------
@@ -825,7 +841,7 @@ int main(int argc, char **argv) {
841 // get the user we should run
842
843 // IMPORTANT: this is required before web_files_uid()
828 - user = config_get("global", "run as user" , (getuid() == 0)?NETDATA_USER:"");
844 + user = config_get(CONFIG_SECTION_GLOBAL, "run as user" , (getuid() == 0)?NETDATA_USER:"");
845
846 // IMPORTANT: these have to run once, while single threaded
847 web_files_uid(); // IMPORTANT: web_files_uid() before web_files_gid()
@@ -835,7 +851,7 @@ int main(int argc, char **argv) {
851 // --------------------------------------------------------------------
852 // create the listening sockets
853
838 - if(!check_config && !default_rrdpush_exclusive)
854 + if(!check_config && web_server_mode != WEB_SERVER_MODE_NONE)
855 create_listen_sockets();
856
857
@@ -882,6 +898,12 @@ int main(int argc, char **argv) {
898 }
899
900
901 + // --------------------------------------------------------------------
902 + // find we need to send data to another netdata
903 +
904 + rrdpush_init();
905 +
906 +
907 // ------------------------------------------------------------------------
908 // initialize health monitoring
909
@@ -897,7 +919,7 @@ int main(int argc, char **argv) {
919 // ------------------------------------------------------------------------
920 // initialize rrd host
921
900 - rrd_init(hostname);
922 + rrd_init(netdata_configured_hostname);
923
924
925 if(check_config)
src/plugins_d.c
+4 -4
@@ -455,14 +455,14 @@ void *pluginsd_main(void *ptr) {
455 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
456 error("Cannot set pthread cancel state to ENABLE.");
457
458 - int automatic_run = config_get_boolean("plugins", "enable running new plugins", 1);
459 - int scan_frequency = (int) config_get_number("plugins", "check for new plugins every", 60);
458 + int automatic_run = config_get_boolean(CONFIG_SECTION_PLUGINS, "enable running new plugins", 1);
459 + int scan_frequency = (int) config_get_number(CONFIG_SECTION_PLUGINS, "check for new plugins every", 60);
460 DIR *dir = NULL;
461 struct dirent *file = NULL;
462 struct plugind *cd;
463
464 // enable the apps plugin by default
465 - // config_get_boolean("plugins", "apps", 1);
465 + // config_get_boolean(CONFIG_SECTION_PLUGINS, "apps", 1);
466
467 if(scan_frequency < 1) scan_frequency = 1;
468
@@ -491,7 +491,7 @@ void *pluginsd_main(void *ptr) {
491
492 char pluginname[CONFIG_MAX_NAME + 1];
493 snprintfz(pluginname, CONFIG_MAX_NAME, "%.*s", (int)(len - PLUGINSD_FILE_SUFFIX_LEN), file->d_name);
494 - int enabled = config_get_boolean("plugins", pluginname, automatic_run);
494 + int enabled = config_get_boolean(CONFIG_SECTION_PLUGINS, pluginname, automatic_run);
495
496 if(unlikely(!enabled)) {
497 debug(D_PLUGINSD, "PLUGINSD: plugin '%s' is not enabled", file->d_name);
src/registry_init.c
+17 -17
@@ -4,52 +4,52 @@ int registry_init(void) {
4 char filename[FILENAME_MAX + 1];
5
6 // registry enabled?
7 - if(!default_rrdpush_exclusive) {
8 - registry.enabled = config_get_boolean("registry", "enabled", 0);
7 + if(web_server_mode != WEB_SERVER_MODE_NONE) {
8 + registry.enabled = config_get_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0);
9 }
10 else {
11 info("Registry is disabled - use the central netdata");
12 - config_set_boolean("registry", "enabled", 0);
12 + config_set_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0);
13 registry.enabled = 0;
14 }
15
16 // pathnames
17 snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir);
18 - registry.pathname = config_get("registry", "registry db directory", filename);
18 + registry.pathname = config_get(CONFIG_SECTION_REGISTRY, "registry db directory", filename);
19 if(mkdir(registry.pathname, 0770) == -1 && errno != EEXIST)
20 fatal("Cannot create directory '%s'.", registry.pathname);
21
22 // filenames
23 snprintfz(filename, FILENAME_MAX, "%s/netdata.public.unique.id", registry.pathname);
24 - registry.machine_guid_filename = config_get("registry", "netdata unique id file", filename);
24 + registry.machine_guid_filename = config_get(CONFIG_SECTION_REGISTRY, "netdata unique id file", filename);
25
26 snprintfz(filename, FILENAME_MAX, "%s/registry.db", registry.pathname);
27 - registry.db_filename = config_get("registry", "registry db file", filename);
27 + registry.db_filename = config_get(CONFIG_SECTION_REGISTRY, "registry db file", filename);
28
29 snprintfz(filename, FILENAME_MAX, "%s/registry-log.db", registry.pathname);
30 - registry.log_filename = config_get("registry", "registry log file", filename);
30 + registry.log_filename = config_get(CONFIG_SECTION_REGISTRY, "registry log file", filename);
31
32 // configuration options
33 - registry.save_registry_every_entries = (unsigned long long)config_get_number("registry", "registry save db every new entries", 1000000);
34 - registry.persons_expiration = config_get_number("registry", "registry expire idle persons days", 365) * 86400;
35 - registry.registry_domain = config_get("registry", "registry domain", "");
36 - registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io");
37 - registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", "localhost"));
38 - registry.verify_cookies_redirects = config_get_boolean("registry", "verify browser cookies support", 1);
33 + registry.save_registry_every_entries = (unsigned long long)config_get_number(CONFIG_SECTION_REGISTRY, "registry save db every new entries", 1000000);
34 + registry.persons_expiration = config_get_number(CONFIG_SECTION_REGISTRY, "registry expire idle persons days", 365) * 86400;
35 + registry.registry_domain = config_get(CONFIG_SECTION_REGISTRY, "registry domain", "");
36 + registry.registry_to_announce = config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io");
37 + registry.hostname = config_get(CONFIG_SECTION_REGISTRY, "registry hostname", config_get(CONFIG_SECTION_GLOBAL, "hostname", "localhost"));
38 + registry.verify_cookies_redirects = config_get_boolean(CONFIG_SECTION_REGISTRY, "verify browser cookies support", 1);
39
40 setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1);
41 setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1);
42
43 - registry.max_url_length = (size_t)config_get_number("registry", "max URL length", 1024);
43 + registry.max_url_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL length", 1024);
44 if(registry.max_url_length < 10) {
45 registry.max_url_length = 10;
46 - config_set_number("registry", "max URL length", (long long)registry.max_url_length);
46 + config_set_number(CONFIG_SECTION_REGISTRY, "max URL length", (long long)registry.max_url_length);
47 }
48
49 - registry.max_name_length = (size_t)config_get_number("registry", "max URL name length", 50);
49 + registry.max_name_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL name length", 50);
50 if(registry.max_name_length < 10) {
51 registry.max_name_length = 10;
52 - config_set_number("registry", "max URL name length", (long long)registry.max_name_length);
52 + config_set_number(CONFIG_SECTION_REGISTRY, "max URL name length", (long long)registry.max_name_length);
53 }
54
55 // initialize entries counters
src/rrd.h
-1
@@ -342,7 +342,6 @@ struct rrdhost {
342 int rrd_history_entries; // the number of history entries for the host's charts
343
344 int rrdpush_enabled; // 1 when this host sends metrics to another netdata
345 - int rrdpush_exclusive; // 1 when this host is exclusively sending metrics without a database
345 volatile int rrdpush_connected; // 1 when the sender is ready to push metrics
346 volatile int rrdpush_spawn; // 1 when the sender thread has been spawn
347 volatile int rrdpush_error_shown; // 1 when we have logged a communication error
src/rrd2json.c
+1 -1
@@ -154,7 +154,7 @@ void rrd_stats_api_v1_charts_allmetrics_prometheus(RRDHOST *host, BUFFER *wb) {
154 rrdhost_rdlock(host);
155
156 char hostname[PROMETHEUS_ELEMENT_MAX + 1];
157 - prometheus_name_copy(hostname, config_get("global", "hostname", "localhost"), PROMETHEUS_ELEMENT_MAX);
157 + prometheus_name_copy(hostname, host->hostname, PROMETHEUS_ELEMENT_MAX);
158
159 // for each chart
160 RRDSET *st;
src/rrdhost.c
+5 -6
@@ -75,7 +75,6 @@ RRDHOST *rrdhost_create(const char *hostname,
75 host->rrd_memory_mode = memory_mode;
76 host->health_enabled = (memory_mode == RRD_MEMORY_MODE_NONE)? 0 : health_enabled;
77 host->rrdpush_enabled = default_rrdpush_enabled;
78 - host->rrdpush_exclusive = default_rrdpush_exclusive;
78
79 host->rrdpush_pipe[0] = -1;
80 host->rrdpush_pipe[1] = -1;
@@ -102,10 +101,10 @@ RRDHOST *rrdhost_create(const char *hostname,
101 host->health_log.next_log_id =
102 host->health_log.next_alarm_id = (uint32_t)now_realtime_sec();
103
105 - long n = config_get_number("health", "in memory max health log entries", host->health_log.max);
104 + long n = config_get_number(CONFIG_SECTION_HEALTH, "in memory max health log entries", host->health_log.max);
105 if(n < 10) {
106 error("Host '%s': health configuration has invalid max log entries %ld. Using default %u", host->hostname, n, host->health_log.max);
108 - config_set_number("health", "in memory max health log entries", (long)host->health_log.max);
107 + config_set_number(CONFIG_SECTION_HEALTH, "in memory max health log entries", (long)host->health_log.max);
108 }
109 else
110 host->health_log.max = (unsigned int)n;
@@ -150,10 +149,10 @@ RRDHOST *rrdhost_create(const char *hostname,
149 }
150
151 snprintfz(filename, FILENAME_MAX, "%s/health/health-log.db", host->varlib_dir);
153 - host->health_log_filename = strdupz(config_get("health", "health db file", filename));
152 + host->health_log_filename = strdupz(config_get(CONFIG_SECTION_HEALTH, "health db file", filename));
153
154 snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_plugins_dir);
156 - host->health_default_exec = strdupz(config_get("health", "script to execute on alarm", filename));
155 + host->health_default_exec = strdupz(config_get(CONFIG_SECTION_HEALTH, "script to execute on alarm", filename));
156 host->health_default_recipient = strdup("root");
157
158
@@ -320,7 +319,7 @@ void rrdhost_free(RRDHOST *host) {
319
320 if(host->rrdpush_spawn) {
321 pthread_cancel(host->rrdpush_thread);
323 - rrdpush_sender_cleanup(host);
322 + rrdpush_sender_thread_cleanup(host);
323 }
324
325 freez(host->os);
src/rrdpush.c
+79 -58
@@ -1,11 +1,45 @@
1 #include "common.h"
2
3 -int default_rrdpush_enabled = 0;
4 -int default_rrdpush_exclusive = 1;
5 -
3 +/*
4 + * rrdpush
5 + *
6 + * 3 threads are involved for all stream operations
7 + *
8 + * 1. a random data collection thread, calling rrdset_done_push()
9 + * this is called for each chart.
10 + *
11 + * the output of this work is kept in a BUFFER in RRDHOST
12 + * the sender thread is signalled via a pipe (also in RRDHOST)
13 + *
14 + * 2. a sender thread running at the sending netdata
15 + * this is spawned automatically on the first chart to be pushed
16 + *
17 + * It tries to push the metrics to the remote netdata, as fast
18 + * as possible (i.e. immediately after they are collected).
19 + *
20 + * 3. a receiver thread, running at the receiving netdata
21 + * this is spawned automatically when the sender connects to
22 + * the receiver.
23 + *
24 + */
25 +
26 +int default_rrdpush_enabled = 0;
27 static char *remote_netdata_config = NULL;
28 static char *api_key = NULL;
29
30 +int rrdpush_init() {
31 + default_rrdpush_enabled = config_get_boolean(CONFIG_SECTION_STREAM, "enabled", default_rrdpush_enabled);
32 + remote_netdata_config = config_get(CONFIG_SECTION_STREAM, "stream metrics to", "");
33 + api_key = config_get(CONFIG_SECTION_STREAM, "api key", "");
34 +
35 + if(!default_rrdpush_enabled || !remote_netdata_config || !*remote_netdata_config || !api_key || !*api_key) {
36 + error("STREAM [send]: cannot enable sending thread - information is missing.");
37 + default_rrdpush_enabled = 0;
38 + }
39 +
40 + return default_rrdpush_enabled;
41 +}
42 +
43 #define CONNECTED_TO_SIZE 100
44
45 // data collection happens from multiple threads
@@ -80,30 +114,6 @@ static inline void send_chart_metrics(RRDSET *st) {
114 buffer_strcat(st->rrdhost->rrdpush_buffer, "END\n");
115 }
116
83 -// resets all the chart, so that their definitions
84 -// will be resent to the central netdata
85 -static void reset_all_charts(RRDHOST *host) {
86 - rrdhost_rdlock(host);
87 -
88 - RRDSET *st;
89 - rrdset_foreach_read(st, host) {
90 -
91 - // make it re-align the current time
92 - // on the remote host
93 - st->counter_done = 0;
94 -
95 - rrdset_rdlock(st);
96 -
97 - RRDDIM *rd;
98 - rrddim_foreach_read(rd, st)
99 - rrddim_flag_clear(rd, RRDDIM_FLAG_EXPOSED);
100 -
101 - rrdset_unlock(st);
102 - }
103 -
104 - rrdhost_unlock(host);
105 -}
106 -
117 void rrdpush_sender_thread_spawn(RRDHOST *host);
118
119 void rrdset_done_push(RRDSET *st) {
@@ -131,12 +141,10 @@ void rrdset_done_push(RRDSET *st) {
141 host->rrdpush_error_shown = 0;
142 }
143
134 - rrdset_rdlock(st);
144 if(need_to_send_chart_definition(st))
145 send_chart_definition(st);
146
147 send_chart_metrics(st);
139 - rrdset_unlock(st);
148
149 // signal the sender there are more data
150 if(write(host->rrdpush_pipe[PIPE_WRITE], " ", 1) == -1)
@@ -145,45 +153,58 @@ void rrdset_done_push(RRDSET *st) {
153 rrdpush_unlock(host);
154 }
155
148 -static inline void rrdpush_flush(RRDHOST *host) {
156 +// ----------------------------------------------------------------------------
157 +// rrdpush sender thread
158 +
159 +// resets all the chart, so that their definitions
160 +// will be resent to the central netdata
161 +static void rrdpush_sender_thread_reset_all_charts(RRDHOST *host) {
162 + rrdhost_rdlock(host);
163 +
164 + RRDSET *st;
165 + rrdset_foreach_read(st, host) {
166 +
167 + // make it re-align the current time
168 + // on the remote host
169 + st->counter_done = 0;
170 +
171 + rrdset_rdlock(st);
172 +
173 + RRDDIM *rd;
174 + rrddim_foreach_read(rd, st)
175 + rrddim_flag_clear(rd, RRDDIM_FLAG_EXPOSED);
176 +
177 + rrdset_unlock(st);
178 + }
179 +
180 + rrdhost_unlock(host);
181 +}
182 +
183 +static inline void rrdpush_sender_thread_data_flush(RRDHOST *host) {
184 rrdpush_lock(host);
185 if(buffer_strlen(host->rrdpush_buffer))
186 error("STREAM [send]: discarding %zu bytes of metrics already in the buffer.", buffer_strlen(host->rrdpush_buffer));
187
188 buffer_flush(host->rrdpush_buffer);
154 - reset_all_charts(host);
189 + rrdpush_sender_thread_reset_all_charts(host);
190 rrdpush_unlock(host);
191 }
192
158 -int rrdpush_init() {
159 - default_rrdpush_enabled = config_get_boolean("stream", "enabled", default_rrdpush_enabled);
160 - default_rrdpush_exclusive = config_get_boolean("stream", "exclusive", default_rrdpush_exclusive);
161 - remote_netdata_config = config_get("stream", "stream metrics to", "");
162 - api_key = config_get("stream", "api key", "");
163 -
164 - if(!default_rrdpush_enabled || !remote_netdata_config || !*remote_netdata_config || !api_key || !*api_key) {
165 - default_rrdpush_enabled = 0;
166 - default_rrdpush_exclusive = 0;
167 - }
168 -
169 - return default_rrdpush_enabled;
170 -}
171 -
172 -static inline void rrdpush_sender_lock(RRDHOST *host) {
193 +static inline void rrdpush_sender_thread_lock(RRDHOST *host) {
194 if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) != 0)
195 error("STREAM [send]: cannot set pthread cancel state to DISABLE.");
196
197 rrdpush_lock(host);
198 }
199
179 -static inline void rrdpush_sender_unlock(RRDHOST *host) {
200 +static inline void rrdpush_sender_thread_unlock(RRDHOST *host) {
201 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
202 error("STREAM [send]: cannot set pthread cancel state to DISABLE.");
203
204 rrdpush_unlock(host);
205 }
206
186 -void rrdpush_sender_cleanup(RRDHOST *host) {
207 +void rrdpush_sender_thread_cleanup(RRDHOST *host) {
208 rrdpush_lock(host);
209
210 host->rrdpush_connected = 0;
@@ -216,11 +237,11 @@ void *rrdpush_sender_thread(void *ptr) {
237 if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
238 error("STREAM [send]: cannot set pthread cancel state to ENABLE.");
239
219 - int timeout = (int)config_get_number("stream", "timeout seconds", 60);
220 - int default_port = (int)config_get_number("stream", "default port", 19999);
221 - size_t max_size = (size_t)config_get_number("stream", "buffer size bytes", 1024 * 1024);
222 - unsigned int reconnect_delay = (unsigned int)config_get_number("stream", "reconnect delay seconds", 5);
223 - remote_clock_resync_iterations = (unsigned int)config_get_number("stream", "initial clock resync iterations", remote_clock_resync_iterations);
240 + int timeout = (int)config_get_number(CONFIG_SECTION_STREAM, "timeout seconds", 60);
241 + int default_port = (int)config_get_number(CONFIG_SECTION_STREAM, "default port", 19999);
242 + size_t max_size = (size_t)config_get_number(CONFIG_SECTION_STREAM, "buffer size bytes", 1024 * 1024);
243 + unsigned int reconnect_delay = (unsigned int)config_get_number(CONFIG_SECTION_STREAM, "reconnect delay seconds", 5);
244 + remote_clock_resync_iterations = (unsigned int)config_get_number(CONFIG_SECTION_STREAM, "initial clock resync iterations", remote_clock_resync_iterations);
245 char connected_to[CONNECTED_TO_SIZE + 1] = "";
246
247 if(!host->rrdpush_enabled || !remote_netdata_config || !*remote_netdata_config || !api_key || !*api_key)
@@ -310,7 +331,7 @@ void *rrdpush_sender_thread(void *ptr) {
331 if(fcntl(host->rrdpush_socket, F_SETFL, O_NONBLOCK) < 0)
332 error("STREAM [send to %s]: cannot set non-blocking mode for socket.", connected_to);
333
313 - rrdpush_flush(host);
334 + rrdpush_sender_thread_data_flush(host);
335 sent_connection = 0;
336
337 // allow appending data into rrdpush_buffer
@@ -357,7 +378,7 @@ void *rrdpush_sender_thread(void *ptr) {
378 }
379
380 if(ofd->revents & POLLOUT && begin < buffer_strlen(host->rrdpush_buffer)) {
360 - rrdpush_sender_lock(host);
381 + rrdpush_sender_thread_lock(host);
382 ssize_t ret = send(host->rrdpush_socket, &host->rrdpush_buffer->buffer[begin], buffer_strlen(host->rrdpush_buffer) - begin, MSG_DONTWAIT);
383 if(ret == -1) {
384 if(errno != EAGAIN && errno != EINTR) {
@@ -375,7 +396,7 @@ void *rrdpush_sender_thread(void *ptr) {
396 begin = 0;
397 }
398 }
378 - rrdpush_sender_unlock(host);
399 + rrdpush_sender_thread_unlock(host);
400 }
401
402 // protection from overflow
@@ -392,7 +413,7 @@ void *rrdpush_sender_thread(void *ptr) {
413 cleanup:
414 debug(D_WEB_CLIENT, "STREAM [send]: sending thread exits.");
415
395 - rrdpush_sender_cleanup(host);
416 + rrdpush_sender_thread_cleanup(host);
417
418 pthread_exit(NULL);
419 return NULL;
@@ -400,7 +421,7 @@ cleanup:
421
422
423 // ----------------------------------------------------------------------------
403 -// STREAM receiver
424 +// rrdpush receiver thread
425
426 int rrdpush_receive(int fd, const char *key, const char *hostname, const char *machine_guid, const char *os, int update_every, char *client_ip, char *client_port) {
427 RRDHOST *host;
src/rrdpush.h
+1 -1
@@ -9,6 +9,6 @@ extern void rrdset_done_push(RRDSET *st);
9 extern void *rrdpush_sender_thread(void *ptr);
10
11 extern int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url);
12 -extern void rrdpush_sender_cleanup(RRDHOST *host);
12 +extern void rrdpush_sender_thread_cleanup(RRDHOST *host);
13
14 #endif //NETDATA_RRDPUSH_H
src/rrdset.c
+10 -8
@@ -607,7 +607,7 @@ static inline void rrdset_init_last_updated_time(RRDSET *st) {
607 st->last_updated.tv_usec = 0;
608 }
609
610 -static inline void rrdset_done_push_int(RRDSET *st) {
610 +static inline void rrdset_done_push_exclusive(RRDSET *st) {
611 if(unlikely(!st->last_collected_time.tv_sec)) {
612 // it is the first entry
613 // set the last_collected_time to now
@@ -619,17 +619,20 @@ static inline void rrdset_done_push_int(RRDSET *st) {
619 rrdset_update_last_collected_time(st);
620 }
621
622 - st->counter++;
622 st->counter_done++;
623
624 + rrdset_rdlock(st);
625 rrdset_done_push(st);
626 + rrdset_unlock(st);
627 }
628
629 void rrdset_done(RRDSET *st) {
630 if(unlikely(netdata_exit)) return;
631
631 - if(unlikely(st->rrdhost->rrdpush_exclusive)) {
632 - rrdset_done_push_int(st);
632 + if(unlikely(st->rrd_memory_mode == RRD_MEMORY_MODE_NONE)) {
633 + if(unlikely(st->rrdhost->rrdpush_enabled))
634 + rrdset_done_push_exclusive(st);
635 +
636 return;
637 }
638
@@ -748,6 +751,9 @@ void rrdset_done(RRDSET *st) {
751 }
752 st->counter_done++;
753
754 + if(unlikely(st->rrdhost->rrdpush_enabled))
755 + rrdset_done_push(st);
756 +
757 // calculate totals and count the dimensions
758 int dimensions = 0;
759 st->collected_total = 0;
@@ -1217,8 +1223,4 @@ void rrdset_done(RRDSET *st) {
1223
1224 if(unlikely(pthread_setcancelstate(pthreadoldcancelstate, NULL) != 0))
1225 error("Cannot set pthread cancel state to RESTORE (%d).", pthreadoldcancelstate);
1220 -
1221 - if(unlikely(st->rrdhost->rrdpush_enabled))
1222 - rrdset_done_push_int(st);
1226 }
1224 -
src/web_client.c
+2 -2
@@ -239,7 +239,7 @@ uid_t web_files_uid(void) {
239 static uid_t owner_uid = 0;
240
241 if(unlikely(!web_owner)) {
242 - web_owner = config_get("global", "web files owner", config_get("global", "run as user", ""));
242 + web_owner = config_get(CONFIG_SECTION_API, "web files owner", config_get(CONFIG_SECTION_GLOBAL, "run as user", ""));
243 if(!web_owner || !*web_owner)
244 owner_uid = geteuid();
245 else {
@@ -266,7 +266,7 @@ gid_t web_files_gid(void) {
266 static gid_t owner_gid = 0;
267
268 if(unlikely(!web_group)) {
269 - web_group = config_get("global", "web files group", config_get("global", "web files owner", ""));
269 + web_group = config_get(CONFIG_SECTION_API, "web files group", config_get(CONFIG_SECTION_API, "web files owner", ""));
270 if(!web_group || !*web_group)
271 owner_gid = getegid();
272 else {
src/web_server.c
+29 -11
@@ -5,7 +5,8 @@ size_t listen_fds_count = 0;
5 int listen_fds[MAX_LISTEN_FDS] = { [0 ... 99] = -1 };
6 char *listen_fds_names[MAX_LISTEN_FDS] = { [0 ... 99] = NULL };
7 int listen_port = LISTEN_PORT;
8 -int web_server_mode = WEB_SERVER_MODE_MULTI_THREADED;
8 +
9 +WEB_SERVER_MODE web_server_mode = WEB_SERVER_MODE_MULTI_THREADED;
10
11 static int shown_server_socket_error = 0;
12
@@ -83,6 +84,29 @@ int accept4(int sock, struct sockaddr *addr, socklen_t *addrlen, int flags) {
84 }
85 #endif
86
87 +WEB_SERVER_MODE web_server_mode_id(const char *mode) {
88 + if(!strcmp(mode, "none"))
89 + return WEB_SERVER_MODE_NONE;
90 + else if(!strcmp(mode, "single") || !strcmp(mode, "single-threaded"))
91 + return WEB_SERVER_MODE_SINGLE_THREADED;
92 + else // if(!strcmp(mode, "multi") || !strcmp(mode, "multi-threaded"))
93 + return WEB_SERVER_MODE_MULTI_THREADED;
94 +}
95 +
96 +const char *web_server_mode_name(WEB_SERVER_MODE id) {
97 + switch(id) {
98 + case WEB_SERVER_MODE_NONE:
99 + return "none";
100 +
101 + case WEB_SERVER_MODE_SINGLE_THREADED:
102 + return "single-threaded";
103 +
104 + default:
105 + case WEB_SERVER_MODE_MULTI_THREADED:
106 + return "multi-threaded";
107 + }
108 +}
109 +
110 int create_listen_socket4(const char *ip, int port, int listen_backlog) {
111 int sock;
112 int sockopt = 1;
@@ -316,22 +340,16 @@ static inline int bind_to_one(const char *definition, int default_port, int list
340 int create_listen_sockets(void) {
341 shown_server_socket_error = 0;
342
319 - listen_backlog = (int) config_get_number("global", "http port listen backlog", LISTEN_BACKLOG);
320 -
321 - if(config_exists("global", "bind socket to IP") && !config_exists("global", "bind to"))
322 - config_rename("global", "bind socket to IP", "bind to");
323 -
324 - if(config_exists("global", "port") && !config_exists("global", "default port"))
325 - config_rename("global", "port", "default port");
343 + listen_backlog = (int) config_get_number(CONFIG_SECTION_API, "listen backlog", LISTEN_BACKLOG);
344
327 - listen_port = (int) config_get_number("global", "default port", LISTEN_PORT);
345 + listen_port = (int) config_get_number(CONFIG_SECTION_API, "default port", LISTEN_PORT);
346 if(listen_port < 1 || listen_port > 65535) {
347 error("Invalid listen port %d given. Defaulting to %d.", listen_port, LISTEN_PORT);
330 - listen_port = (int) config_set_number("global", "default port", LISTEN_PORT);
348 + listen_port = (int) config_set_number(CONFIG_SECTION_API, "default port", LISTEN_PORT);
349 }
350 debug(D_OPTIONS, "Default listen port set to %d.", listen_port);
351
334 - char *s = config_get("global", "bind to", "*");
352 + char *s = config_get(CONFIG_SECTION_API, "bind to", "*");
353 while(*s) {
354 char *e = s;
355
src/web_server.h
+11 -3
@@ -13,9 +13,17 @@
13 #define MAX_LISTEN_FDS 100
14 #endif
15
16 -#define WEB_SERVER_MODE_MULTI_THREADED 0
17 -#define WEB_SERVER_MODE_SINGLE_THREADED 1
18 -extern int web_server_mode;
16 +typedef enum web_server_mode {
17 + WEB_SERVER_MODE_SINGLE_THREADED,
18 + WEB_SERVER_MODE_MULTI_THREADED,
19 + WEB_SERVER_MODE_NONE
20 +} WEB_SERVER_MODE;
21 +
22 +extern WEB_SERVER_MODE web_server_mode;
23 +
24 +extern WEB_SERVER_MODE web_server_mode_id(const char *mode);
25 +extern const char *web_server_mode_name(WEB_SERVER_MODE id);
26 +
27
28 extern void *socket_listen_main_multi_threaded(void *ptr);
29 extern void *socket_listen_main_single_threaded(void *ptr);