]> arthur.barton.de Git - netdata.git/blobdiff - src/main.c
properly name the expectations chart
[netdata.git] / src / main.c
index e117e53b2f1649a646b005f541f03bb4122d9f7b..a72585e28377a1157bcae85459bc73176b14d8d3 100644 (file)
@@ -60,7 +60,7 @@ struct netdata_static_thread static_threads[] = {
 };
 
 void web_server_threading_selection(void) {
-    web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_API, "mode", web_server_mode_name(web_server_mode)));
+    web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_WEB, "mode", web_server_mode_name(web_server_mode)));
 
     int multi_threaded = (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED);
     int single_threaded = (web_server_mode == WEB_SERVER_MODE_SINGLE_THREADED);
@@ -74,16 +74,16 @@ void web_server_threading_selection(void) {
             static_threads[i].enabled = single_threaded;
     }
 
-    web_client_timeout = (int) config_get_number(CONFIG_SECTION_API, "disconnect idle clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
+    web_client_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "disconnect idle clients after seconds", DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS);
 
-    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);
-    web_x_frame_options = config_get(CONFIG_SECTION_API, "x-frame-options header", "");
+    respect_web_browser_do_not_track_policy = config_get_boolean(CONFIG_SECTION_WEB, "respect do not track policy", respect_web_browser_do_not_track_policy);
+    web_x_frame_options = config_get(CONFIG_SECTION_WEB, "x-frame-options response header", "");
     if(!*web_x_frame_options) web_x_frame_options = NULL;
 
 #ifdef NETDATA_WITH_ZLIB
-    web_enable_gzip = config_get_boolean(CONFIG_SECTION_API, "gzip compression", web_enable_gzip);
+    web_enable_gzip = config_get_boolean(CONFIG_SECTION_WEB, "enable gzip compression", web_enable_gzip);
 
-    char *s = config_get(CONFIG_SECTION_API, "compression strategy", "default");
+    char *s = config_get(CONFIG_SECTION_WEB, "gzip compression strategy", "default");
     if(!strcmp(s, "default"))
         web_gzip_strategy = Z_DEFAULT_STRATEGY;
     else if(!strcmp(s, "filtered"))
@@ -99,7 +99,7 @@ void web_server_threading_selection(void) {
         web_gzip_strategy = Z_DEFAULT_STRATEGY;
     }
 
-    web_gzip_level = (int)config_get_number(CONFIG_SECTION_API, "compression level", 3);
+    web_gzip_level = (int)config_get_number(CONFIG_SECTION_WEB, "gzip 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);
         web_gzip_level = 1;
@@ -225,12 +225,12 @@ struct option_def options[] = {
     { 'h', "Display this help message.",                  NULL,          NULL},
     { 'P', "File to save a pid while running.",           "filename",    "do not save pid to a file"},
     { 'i', "The IP address to listen to.",                "IP",          "all IP addresses IPv4 and IPv6"},
-    { 'k', "Check health configuration and exit.",        NULL,          NULL},
     { 'p', "API/Web port to use.",                        "port",        "19999"},
     { 's', "Prefix for /proc and /sys (for containers).", "path",        "no prefix"},
     { 't', "The internal clock of netdata.",              "seconds",     "1"},
     { 'u', "Run as user.",                                "username",    "netdata"},
     { 'v', "Print netdata version and exit.",             NULL,          NULL},
+    { 'V', "Print netdata version and exit.",             NULL,          NULL},
     { 'W', "See Advanced options below.",                 "options",     NULL},
 };
 
@@ -366,41 +366,45 @@ static void backwards_compatible_config() {
         web_server_mode = (mode)?WEB_SERVER_MODE_MULTI_THREADED:WEB_SERVER_MODE_SINGLE_THREADED;
     }
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "bind socket to IP") && !config_exists(CONFIG_SECTION_API, "bind to"))
-        config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP", CONFIG_SECTION_API, "bind to");
+    // move [global] options to the [web] section
+    config_move(CONFIG_SECTION_GLOBAL, "http port listen backlog",
+                CONFIG_SECTION_WEB,    "listen backlog");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "bind to") && !config_exists(CONFIG_SECTION_API, "bind to"))
-        config_move(CONFIG_SECTION_GLOBAL, "bind to", CONFIG_SECTION_API, "bind to");
+    config_move(CONFIG_SECTION_GLOBAL, "bind socket to IP",
+                CONFIG_SECTION_WEB,    "bind to");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "port") && !config_exists(CONFIG_SECTION_API, "default port"))
-        config_move(CONFIG_SECTION_GLOBAL, "port", CONFIG_SECTION_API, "default port");
+    config_move(CONFIG_SECTION_GLOBAL, "bind to",
+                CONFIG_SECTION_WEB,    "bind to");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "default port") && !config_exists(CONFIG_SECTION_API, "default port"))
-        config_move(CONFIG_SECTION_GLOBAL, "default port", CONFIG_SECTION_API, "default port");
+    config_move(CONFIG_SECTION_GLOBAL, "port",
+                CONFIG_SECTION_WEB,    "default port");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds") && !config_exists(CONFIG_SECTION_API, "disconnect idle clients after seconds"))
-        config_move(CONFIG_SECTION_GLOBAL, "disconnect idle clients after seconds", CONFIG_SECTION_API, "disconnect idle clients after seconds");
+    config_move(CONFIG_SECTION_GLOBAL, "default port",
+                CONFIG_SECTION_WEB,    "default port");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy") && !config_exists(CONFIG_SECTION_API, "respect do not track policy"))
-        config_move(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy", CONFIG_SECTION_API, "respect do not track policy");
+    config_move(CONFIG_SECTION_GLOBAL, "disconnect idle web clients after seconds",
+                CONFIG_SECTION_WEB,    "disconnect idle clients after seconds");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web x-frame-options header") && !config_exists(CONFIG_SECTION_API, "x-frame-options header"))
-        config_move(CONFIG_SECTION_GLOBAL, "web x-frame-options header", CONFIG_SECTION_API, "x-frame-options header");
+    config_move(CONFIG_SECTION_GLOBAL, "respect web browser do not track policy",
+                CONFIG_SECTION_WEB,    "respect do not track policy");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression") && !config_exists(CONFIG_SECTION_API, "gzip compression"))
-        config_move(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression", CONFIG_SECTION_API, "gzip compression");
+    config_move(CONFIG_SECTION_GLOBAL, "web x-frame-options header",
+                CONFIG_SECTION_WEB,    "x-frame-options response header");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web compression strategy") && !config_exists(CONFIG_SECTION_API, "compression strategy"))
-        config_move(CONFIG_SECTION_GLOBAL, "web compression strategy", CONFIG_SECTION_API, "compression strategy");
+    config_move(CONFIG_SECTION_GLOBAL, "enable web responses gzip compression",
+                CONFIG_SECTION_WEB,    "enable gzip compression");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web compression level") && !config_exists(CONFIG_SECTION_API, "compression level"))
-        config_move(CONFIG_SECTION_GLOBAL, "web compression level", CONFIG_SECTION_API, "compression level");
+    config_move(CONFIG_SECTION_GLOBAL, "web compression strategy",
+                CONFIG_SECTION_WEB,    "gzip compression strategy");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web files owner") && !config_exists(CONFIG_SECTION_API, "web files owner"))
-        config_move(CONFIG_SECTION_GLOBAL, "web files owner", CONFIG_SECTION_API, "web files owner");
+    config_move(CONFIG_SECTION_GLOBAL, "web compression level",
+                CONFIG_SECTION_WEB,    "gzip compression level");
 
-    if(config_exists(CONFIG_SECTION_GLOBAL, "web files group") && !config_exists(CONFIG_SECTION_API, "web files group"))
-        config_move(CONFIG_SECTION_GLOBAL, "web files group", CONFIG_SECTION_API, "web files group");
+    config_move(CONFIG_SECTION_GLOBAL, "web files owner",
+                CONFIG_SECTION_WEB,    "web files owner");
+
+    config_move(CONFIG_SECTION_GLOBAL, "web files group",
+                CONFIG_SECTION_WEB,    "web files group");
 }
 
 static void get_netdata_configured_variables() {
@@ -411,7 +415,7 @@ static void get_netdata_configured_variables() {
 
     char buf[HOSTNAME_MAX + 1];
     if(gethostname(buf, HOSTNAME_MAX) == -1)
-        error("WARNING: Cannot get machine hostname.");
+        error("Cannot get machine hostname.");
 
     netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", buf);
     debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
@@ -513,10 +517,13 @@ void set_global_environment() {
 
     // disable buffering for python plugins
     setenv("PYTHONUNBUFFERED", "1", 1);
+
+    // switch to standard locale for plugins
+    setenv("LC_ALL", "C", 1);
 }
 
 int main(int argc, char **argv) {
-    int i, check_config = 0;
+    int i;
     int config_loaded = 0;
     int dont_fork = 0;
     size_t wanted_stacksize = 0, stacksize = 0;
@@ -592,11 +599,7 @@ int main(int argc, char **argv) {
                     help(0);
                     break;
                 case 'i':
-                    config_set(CONFIG_SECTION_API, "bind to", optarg);
-                    break;
-                case 'k':
-                    dont_fork = 1;
-                    check_config = 1;
+                    config_set(CONFIG_SECTION_WEB, "bind to", optarg);
                     break;
                 case 'P':
                     strncpy(pidfile, optarg, FILENAME_MAX);
@@ -615,6 +618,7 @@ int main(int argc, char **argv) {
                     config_set(CONFIG_SECTION_GLOBAL, "run as user", optarg);
                     break;
                 case 'v':
+                case 'V':
                     printf("%s %s\n", program_name, program_version);
                     return 0;
                 case 'W':
@@ -623,10 +627,14 @@ int main(int argc, char **argv) {
                         char* debug_flags_string = "debug_flags=";
                         if(strcmp(optarg, "unittest") == 0) {
                             default_rrd_update_every = 1;
+                            default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
                             if(!config_loaded) config_load(NULL, 0);
                             get_netdata_configured_variables();
-                            registry_init();
+                            default_rrd_update_every = 1;
+                            default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
+                            default_health_enabled = 0;
                             rrd_init("unittest");
+                            default_rrdpush_enabled = 0;
                             if(run_all_mockup_tests()) exit(1);
                             if(unit_test_storage()) exit(1);
                             fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
@@ -705,6 +713,8 @@ int main(int argc, char **argv) {
     if(!config_loaded)
         config_load(NULL, 0);
 
+    // ------------------------------------------------------------------------
+    // initialize netdata
     {
         char *pmax = config_get(CONFIG_SECTION_GLOBAL, "glibc malloc arena max for plugins", "1");
         if(pmax && *pmax)
@@ -755,13 +765,18 @@ int main(int argc, char **argv) {
         // get log filenames and settings
 
         log_init();
-        if(check_config) {
-            stdout_filename = stderr_filename = stdaccess_filename = "system";
-            error_log_throttle_period = 0;
-            error_log_errors_per_period = 0;
-        }
         error_log_limit_unlimited();
 
+
+        // --------------------------------------------------------------------
+        // load stream.conf
+        {
+            char filename[FILENAME_MAX + 1];
+            snprintfz(filename, FILENAME_MAX, "%s/stream.conf", netdata_configured_config_dir);
+            appconfig_load(&stream_config, filename, 0);
+        }
+
+
         // --------------------------------------------------------------------
         // setup process signals
 
@@ -844,7 +859,13 @@ int main(int argc, char **argv) {
         // get the user we should run
 
         // IMPORTANT: this is required before web_files_uid()
-        user = config_get(CONFIG_SECTION_GLOBAL, "run as user"    , (getuid() == 0)?NETDATA_USER:"");
+        if(getuid() == 0) {
+            user = config_get(CONFIG_SECTION_GLOBAL, "run as user", NETDATA_USER);
+        }
+        else {
+            struct passwd *passwd = getpwuid(getuid());
+            user = config_get(CONFIG_SECTION_GLOBAL, "run as user", (passwd && passwd->pw_name)?passwd->pw_name:"");
+        }
 
         // IMPORTANT: these have to run once, while single threaded
         web_files_uid(); // IMPORTANT: web_files_uid() before web_files_gid()
@@ -854,17 +875,8 @@ int main(int argc, char **argv) {
         // --------------------------------------------------------------------
         // create the listening sockets
 
-        if(!check_config && web_server_mode != WEB_SERVER_MODE_NONE)
+        if(web_server_mode != WEB_SERVER_MODE_NONE)
             create_listen_sockets();
-
-
-        // --------------------------------------------------------------------
-        // load the aggregated host configuration file
-        {
-            char filename[FILENAME_MAX + 1];
-            snprintfz(filename, FILENAME_MAX, "%s/aggregated_hosts.conf", netdata_configured_config_dir);
-            appconfig_load(&stream_config, filename, 0);
-        }
     }
 
     // initialize the log files
@@ -901,34 +913,12 @@ int main(int argc, char **argv) {
     }
 
 
-    // --------------------------------------------------------------------
-    // find we need to send data to another netdata
-
-    rrdpush_init();
-
-
     // ------------------------------------------------------------------------
-    // initialize health monitoring
-
-    health_init();
-
-
-    // ------------------------------------------------------------------------
-    // initialize the registry
-
-    registry_init();
-
-
-    // ------------------------------------------------------------------------
-    // initialize rrd host
+    // initialize rrd, registry, health, rrdpush, etc.
 
     rrd_init(netdata_configured_hostname);
 
 
-    if(check_config)
-        exit(1);
-
-
     // ------------------------------------------------------------------------
     // enable log flood protection