// let it log a few more error messages
error_log_limit_reset();
- if(pidfd != -1) {
- if(ftruncate(pidfd, 0) != 0)
- error("Cannot truncate pidfile '%s'.", pidfile);
-
- close(pidfd);
- pidfd = -1;
- }
-
if(pidfile[0]) {
if(unlink(pidfile) != 0)
error("Cannot unlink pidfile '%s'.", pidfile);
void (*init_routine) (void);
void *(*start_routine) (void *);
-};
-
-struct netdata_static_thread static_threads[] = {
- {"tc", "plugins", "tc", 1, NULL, NULL, tc_main},
- {"idlejitter", "plugins", "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
- {"proc", "plugins", "proc", 1, NULL, NULL, proc_main},
- {"cgroups", "plugins", "cgroups", 1, NULL, NULL, cgroups_main},
-
+} static_threads[] = {
#ifdef INTERNAL_PLUGIN_NFACCT
- // nfacct requires root access
+// nfacct requires root access
// so, we build it as an external plugin with setuid to root
- {"nfacct", "plugins", "nfacct", 1, NULL, NULL, nfacct_main},
+ {"nfacct", "plugins", "nfacct", 1, NULL, NULL, nfacct_main},
#endif
- {"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
- {"check", "plugins", "checks", 0, NULL, NULL, checks_main},
- {"web", NULL, NULL, 1, NULL, NULL, socket_listen_main},
- {NULL, NULL, NULL, 0, NULL, NULL, NULL}
+ {"tc", "plugins", "tc", 1, NULL, NULL, tc_main},
+ {"idlejitter", "plugins", "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
+ {"proc", "plugins", "proc", 1, NULL, NULL, proc_main},
+ {"cgroups", "plugins", "cgroups", 1, NULL, NULL, cgroups_main},
+ {"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
+ {"check", "plugins", "checks", 0, NULL, NULL, checks_main},
+ {"web", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
+ {"web-single-threaded", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
+ {NULL, NULL, NULL, 0, NULL, NULL, NULL}
};
+void web_server_threading_selection(void) {
+ int threaded = config_get_boolean("global", "multi threaded web server", 1);
+
+ int i;
+ for(i = 0; static_threads[i].name ; i++) {
+ if(static_threads[i].start_routine == socket_listen_main_multi_threaded)
+ static_threads[i].enabled = threaded?1:0;
+
+ if(static_threads[i].start_routine == socket_listen_main_single_threaded)
+ static_threads[i].enabled = threaded?0:1;
+ }
+
+ web_client_timeout = (int) config_get_number("global", "disconnect idle web clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
+
+#ifdef NETDATA_WITH_ZLIB
+ web_enable_gzip = config_get_boolean("global", "enable web responses gzip compression", web_enable_gzip);
+
+ char *s = config_get("global", "web compression strategy", "default");
+ if(!strcmp(s, "default"))
+ web_gzip_strategy = Z_DEFAULT_STRATEGY;
+ else if(!strcmp(s, "filtered"))
+ web_gzip_strategy = Z_FILTERED;
+ else if(!strcmp(s, "huffman only"))
+ web_gzip_strategy = Z_HUFFMAN_ONLY;
+ else if(!strcmp(s, "rle"))
+ web_gzip_strategy = Z_RLE;
+ else if(!strcmp(s, "fixed"))
+ web_gzip_strategy = Z_FIXED;
+ else {
+ error("Invalid compression strategy '%s'. Valid strategies are 'default', 'filtered', 'huffman only', 'rle' and 'fixed'. Proceeding with 'default'.");
+ web_gzip_strategy = Z_DEFAULT_STRATEGY;
+ }
+
+ web_gzip_level = (int)config_get_number("global", "web compression level", 3);
+ if(web_gzip_level < 1) {
+ error("Invalid compression level %d. Valid levels are 1 (fastest) to 9 (best ratio). Proceeding with level 1 (fastest compression).");
+ web_gzip_level = 1;
+ }
+ else if(web_gzip_level > 9) {
+ error("Invalid compression level %d. Valid levels are 1 (fastest) to 9 (best ratio). Proceeding with level 9 (best compression).");
+ web_gzip_level = 9;
+ }
+#endif /* NETDATA_WITH_ZLIB */
+}
+
+
int killpid(pid_t pid, int sig)
{
int ret = -1;
{'s', "Path to access host /proc and /sys when running in a container.", "PATH", NULL},
{'t', "The frequency in seconds, for data collection. \
Same as 'update every' config file option.", "seconds", "1"},
- {'l', "The number of entries the netdata daemon will keep in memory \
-for each chart dimension. Same as 'history config file option.", "lines_to_save", NULL},
{'u', "System username to run as.", "username", "netdata"},
{'v', "Version of the program", NULL, NULL},
{'W', "vendor options.", "stacksize=<size>|unittest|debug_flag", NULL},
fprintf(stderr, "%s: deprecate option -- %s -- please use -s instead.\n", argv[0], argv[i]);
remove_option(i, &argc, argv);
}
+ else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) {
+ config_set("global", "history", argv[i+1]);
+ fprintf(stderr, "%s: deprecate option -- %s -- This option will be rmoved with V2.*.\n", argv[0], argv[i]);
+ remove_option(i, &argc, argv);
+ }
else i++;
}
}
printf("netdata 1.1.0\n");
return 0;
break;
- case 'l':
- config_set("global", "history", optarg);
- break;
case 'W':
{
char* stacksize = "stacksize=";
error_log_throttle_period = config_get_number("global", "errors flood protection period", error_log_throttle_period);
setenv("NETDATA_ERRORS_THROTTLE_PERIOD", config_get("global", "errors flood protection period" , ""), 1);
- error_log_errors_per_period = config_get_number("global", "errors to trigger flood protection", error_log_errors_per_period);
+ error_log_errors_per_period = (unsigned long)config_get_number("global", "errors to trigger flood protection", error_log_errors_per_period);
setenv("NETDATA_ERRORS_PER_PERIOD" , config_get("global", "errors to trigger flood protection", ""), 1);
// --------------------------------------------------------------------
// --------------------------------------------------------------------
- listen_backlog = (int) config_get_number("global", "http port listen backlog", LISTEN_BACKLOG);
-
- listen_port = (int) config_get_number("global", "port", LISTEN_PORT);
- if(listen_port < 1 || listen_port > 65535) {
- info("Invalid listen port %d given. Defaulting to %d.", listen_port, LISTEN_PORT);
- listen_port = LISTEN_PORT;
- }
- else debug(D_OPTIONS, "Listen port set to %d.", listen_port);
-
- int ip = 0;
- char *ipv = config_get("global", "ip version", "any");
- if(!strcmp(ipv, "any") || !strcmp(ipv, "both") || !strcmp(ipv, "all")) ip = 0;
- else if(!strcmp(ipv, "ipv4") || !strcmp(ipv, "IPV4") || !strcmp(ipv, "IPv4") || !strcmp(ipv, "4")) ip = 4;
- else if(!strcmp(ipv, "ipv6") || !strcmp(ipv, "IPV6") || !strcmp(ipv, "IPv6") || !strcmp(ipv, "6")) ip = 6;
- else info("Cannot understand ip version '%s'. Assuming 'any'.", ipv);
-
- if(ip == 0 || ip == 6) listen_fd = create_listen_socket6(config_get("global", "bind socket to IP", "*"), listen_port, listen_backlog);
- if(listen_fd < 0) {
- listen_fd = create_listen_socket4(config_get("global", "bind socket to IP", "*"), listen_port, listen_backlog);
- if(listen_fd >= 0 && ip != 4) info("Managed to open an IPv4 socket on port %d.", listen_port);
- }
-
+ listen_fd = create_listen_socket();
if(listen_fd < 0) fatal("Cannot listen socket.");
}
// ------------------------------------------------------------------------
// spawn the threads
+ web_server_threading_selection();
+
for (i = 0; static_threads[i].name != NULL ; i++) {
struct netdata_static_thread *st = &static_threads[i];