]> arthur.barton.de Git - netdata.git/blobdiff - src/main.c
less INFO messages - they are now DEBUG; fixes #459
[netdata.git] / src / main.c
index 192d2d31e5ed6ef04fe68e1f06c62c3e34882fe1..1a81993873f9092590cc2c38ba6b73f8182d5a4c 100644 (file)
@@ -7,7 +7,7 @@ void netdata_cleanup_and_exit(int ret) {
 
     error_log_limit_unlimited();
 
-    info("Called: netdata_cleanup_and_exit()");
+    debug(D_EXIT, "Called: netdata_cleanup_and_exit()");
 #ifdef NETDATA_INTERNAL_CHECKS
     rrdset_free_all();
 #else
@@ -169,7 +169,7 @@ void kill_childs()
     }
 
     if(tc_child_pid) {
-        info("Killing tc-qos-helper procees");
+        debug(D_EXIT, "Killing tc-qos-helper procees");
         if(killpid(tc_child_pid, SIGTERM) != -1)
             waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED);
     }
@@ -209,7 +209,7 @@ struct option_def options[] = {
 Same as 'update every' config file option.",                                 "seconds",                              "1"},
     {'u', "System username to run as.",                                      "username",                             "netdata"},
     {'v', "Version of the program",                                          NULL,                                   NULL},
-    {'W', "vendor options.",                                                 "stacksize=<size>|unittest|debug_flag", NULL},
+    {'W', "vendor options.",                                                 "stacksize=N|unittest|debug_flags=N",   NULL},
 };
 
 void help(int exitcode) {
@@ -276,20 +276,16 @@ static const char *verify_required_directory(const char *dir) {
 
 int main(int argc, char **argv)
 {
+    char *hostname = "localhost";
     int i, check_config = 0;
     int config_loaded = 0;
     int dont_fork = 0;
     size_t wanted_stacksize = 0, stacksize = 0;
     pthread_attr_t attr;
 
-    // global initialization
-    get_HZ();
-
     // set the name for logging
     program_name = "netdata";
 
-    // parse command line.
-
     // parse depercated options
     // TODO: Remove this block with the next major release.
     {
@@ -378,7 +374,7 @@ int main(int argc, char **argv)
                     break;
                 case 'v':
                     // TODO: Outsource version to makefile which can compute version from git.
-                    printf("netdata 1.2.1_master\n");
+                    printf("netdata %s\n", VERSION);
                     return 0;
                 case 'W':
                     {
@@ -411,6 +407,16 @@ int main(int argc, char **argv)
         load_config(NULL, 0);
 
     {
+        char *pmax = config_get("global", "glibc malloc arena max for plugins", "1");
+        if(pmax && *pmax)
+            setenv("MALLOC_ARENA_MAX", pmax, 1);
+
+#if defined(HAVE_C_MALLOPT)
+        int i = config_get_number("global", "glibc malloc arena max for netdata", 1);
+        if(i > 0)
+            mallopt(M_ARENA_MAX, 1);
+#endif
+
         char *config_dir = config_get("global", "config directory", CONFIG_DIR);
 
         // prepare configuration environment variables for the plugins
@@ -454,7 +460,8 @@ int main(int argc, char **argv)
         if(debug_flags != 0) {
             struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
             if(setrlimit(RLIMIT_CORE, &rl) != 0)
-                info("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
+                error("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
+
             prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
         }
 
@@ -471,13 +478,18 @@ int main(int argc, char **argv)
         global_host_prefix = config_get("global", "host access prefix", "");
         setenv("NETDATA_HOST_PREFIX", global_host_prefix, 1);
 
+        get_system_HZ();
+        get_system_cpus();
+        get_system_pid_max();
+        
         // --------------------------------------------------------------------
 
         stdout_filename    = config_get("global", "debug log",  LOG_DIR "/debug.log");
         stderr_filename    = config_get("global", "error log",  LOG_DIR "/error.log");
         stdaccess_filename = config_get("global", "access log", LOG_DIR "/access.log");
 
-        error_log_throttle_period = config_get_number("global", "errors flood protection period", error_log_throttle_period);
+        error_log_throttle_period_backup =
+            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 = (unsigned long)config_get_number("global", "errors to trigger flood protection", error_log_errors_per_period);
@@ -488,6 +500,7 @@ int main(int argc, char **argv)
             error_log_throttle_period = 0;
             error_log_errors_per_period = 0;
         }
+        error_log_limit_unlimited();
 
         // --------------------------------------------------------------------
 
@@ -501,13 +514,14 @@ int main(int argc, char **argv)
                 error("WARNING: Cannot get machine hostname.");
             hostname = config_get("global", "hostname", hostnamebuf);
             debug(D_OPTIONS, "hostname set to '%s'", hostname);
+            setenv("NETDATA_HOSTNAME", hostname, 1);
         }
 
         // --------------------------------------------------------------------
 
         rrd_default_history_entries = (int) config_get_number("global", "history", RRD_DEFAULT_HISTORY_ENTRIES);
         if(rrd_default_history_entries < 5 || rrd_default_history_entries > RRD_HISTORY_ENTRIES_MAX) {
-            info("Invalid save lines %d given. Defaulting to %d.", rrd_default_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
+            error("Invalid history entries %d given. Defaulting to %d.", rrd_default_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
             rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
         }
         else {
@@ -518,7 +532,7 @@ int main(int argc, char **argv)
 
         rrd_update_every = (int) config_get_number("global", "update every", UPDATE_EVERY);
         if(rrd_update_every < 1 || rrd_update_every > 600) {
-            info("Invalid update timer %d given. Defaulting to %d.", rrd_update_every, UPDATE_EVERY_MAX);
+            error("Invalid data collection frequency (update every) %d given. Defaulting to %d.", rrd_update_every, UPDATE_EVERY_MAX);
             rrd_update_every = UPDATE_EVERY;
         }
         else debug(D_OPTIONS, "update timer set to %d.", rrd_update_every);
@@ -622,7 +636,7 @@ int main(int argc, char **argv)
     if(debug_flags != 0) {
         struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
         if(setrlimit(RLIMIT_CORE, &rl) != 0)
-            info("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
+            error("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
         prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
     }
 #endif /* NETDATA_INTERNAL_CHECKS */
@@ -642,9 +656,14 @@ int main(int argc, char **argv)
         if(i != 0)
             fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
         else
-            info("Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
+            debug(D_SYSTEM, "Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
     }
 
+    // ------------------------------------------------------------------------
+    // initialize rrd host
+
+    rrdhost_init(hostname);
+
     // ------------------------------------------------------------------------
     // initialize the registry
 
@@ -658,6 +677,11 @@ int main(int argc, char **argv)
     if(check_config)
         exit(1);
 
+    // ------------------------------------------------------------------------
+    // enable log flood protection
+
+    error_log_limit_reset();
+
     // ------------------------------------------------------------------------
     // spawn the threads
 
@@ -669,7 +693,7 @@ int main(int argc, char **argv)
         if(st->enabled) {
             st->thread = mallocz(sizeof(pthread_t));
 
-            info("Starting thread %s.", st->name);
+            debug(D_SYSTEM, "Starting thread %s.", st->name);
 
             if(pthread_create(st->thread, &attr, st->start_routine, NULL))
                 error("failed to create new thread for %s.", st->name);
@@ -677,7 +701,7 @@ int main(int argc, char **argv)
             else if(pthread_detach(*st->thread))
                 error("Cannot request detach of newly created %s thread.", st->name);
         }
-        else info("Not starting thread %s.", st->name);
+        else debug(D_SYSTEM, "Not starting thread %s.", st->name);
     }
 
     // ------------------------------------------------------------------------
@@ -693,7 +717,7 @@ int main(int argc, char **argv)
     while(1) {
         pause();
         if(netdata_exit) {
-            info("Exit main loop of netdata.");
+            debug(D_EXIT, "Exit main loop of netdata.");
             netdata_cleanup_and_exit(0);
             exit(0);
         }