summaryrefslogtreecommitdiffstats
path: root/daemon/main.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--daemon/main.c94
1 files changed, 88 insertions, 6 deletions
diff --git a/daemon/main.c b/daemon/main.c
index ba8d4b4ef..a1577fb93 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -301,6 +301,7 @@ int help(int exitcode) {
" -W stacksize=N Set the stacksize (in bytes).\n\n"
" -W debug_flags=N Set runtime tracing to debug.log.\n\n"
" -W unittest Run internal unittests and exit.\n\n"
+ " -W createdataset=N Create a DB engine dataset of N seconds and exit.\n\n"
" -W set section option value\n"
" set netdata.conf option from the command line.\n\n"
" -W simple-pattern pattern string\n"
@@ -471,6 +472,25 @@ static void get_netdata_configured_variables() {
default_rrd_memory_mode = rrd_memory_mode_id(config_get(CONFIG_SECTION_GLOBAL, "memory mode", rrd_memory_mode_name(default_rrd_memory_mode)));
+#ifdef ENABLE_DBENGINE
+ // ------------------------------------------------------------------------
+ // get default Database Engine page cache size in MiB
+
+ default_rrdeng_page_cache_mb = (int) config_get_number(CONFIG_SECTION_GLOBAL, "page cache size", default_rrdeng_page_cache_mb);
+ if(default_rrdeng_page_cache_mb < RRDENG_MIN_PAGE_CACHE_SIZE_MB) {
+ error("Invalid page cache size %d given. Defaulting to %d.", default_rrdeng_page_cache_mb, RRDENG_MIN_PAGE_CACHE_SIZE_MB);
+ default_rrdeng_page_cache_mb = RRDENG_MIN_PAGE_CACHE_SIZE_MB;
+ }
+
+ // ------------------------------------------------------------------------
+ // get default Database Engine disk space quota in MiB
+
+ default_rrdeng_disk_quota_mb = (int) config_get_number(CONFIG_SECTION_GLOBAL, "dbengine disk space", default_rrdeng_disk_quota_mb);
+ if(default_rrdeng_disk_quota_mb < RRDENG_MIN_DISK_SPACE_MB) {
+ error("Invalid dbengine disk space %d given. Defaulting to %d.", default_rrdeng_disk_quota_mb, RRDENG_MIN_DISK_SPACE_MB);
+ default_rrdeng_disk_quota_mb = RRDENG_MIN_DISK_SPACE_MB;
+ }
+#endif
// ------------------------------------------------------------------------
netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
@@ -650,6 +670,51 @@ static int load_netdata_conf(char *filename, char overwrite_used) {
return ret;
}
+int get_system_info(struct rrdhost_system_info *system_info) {
+ char *script;
+ script = mallocz(sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("system-info.sh") + 2));
+ sprintf(script, "%s/%s", netdata_configured_primary_plugins_dir, "system-info.sh");
+ if (unlikely(access(script, R_OK) != 0)) {
+ info("System info script %s not found.",script);
+ freez(script);
+ return 1;
+ }
+
+ pid_t command_pid;
+
+ info("Executing %s", script);
+
+ FILE *fp = mypopen(script, &command_pid);
+ if(fp) {
+ char buffer[200 + 1];
+ while (fgets(buffer, 200, fp) != NULL) {
+ char *name=buffer;
+ char *value=buffer;
+ while (*value && *value != '=') value++;
+ if (*value=='=') {
+ *value='\0';
+ value++;
+ if (strlen(value)>1) {
+ char *newline = value + strlen(value) - 1;
+ (*newline) = '\0';
+ }
+ char n[51], v[101];
+ snprintfz(n, 50,"%s",name);
+ snprintfz(v, 101,"%s",value);
+ if(unlikely(rrdhost_set_system_info_variable(system_info, n, v))) {
+ info("Unexpected environment variable %s=%s", n, v);
+ }
+ else {
+ info("%s=%s", n, v);
+ setenv(n, v, 1);
+ }
+ }
+ }
+ mypclose(fp, command_pid);
+ }
+ freez(script);
+ return 0;
+}
void send_statistics( const char *action, const char *action_result, const char *action_data) {
static char *as_script;
@@ -697,6 +762,7 @@ int main(int argc, char **argv) {
int dont_fork = 0;
size_t default_stacksize;
+ netdata_ready=0;
// set the name for logging
program_name = "netdata";
@@ -795,6 +861,7 @@ int main(int argc, char **argv) {
{
char* stacksize_string = "stacksize=";
char* debug_flags_string = "debug_flags=";
+ char* createdataset_string = "createdataset=";
if(strcmp(optarg, "unittest") == 0) {
if(unit_test_buffer()) return 1;
@@ -803,13 +870,27 @@ int main(int argc, char **argv) {
default_rrd_update_every = 1;
default_rrd_memory_mode = RRD_MEMORY_MODE_RAM;
default_health_enabled = 0;
- rrd_init("unittest");
+ rrd_init("unittest", NULL);
default_rrdpush_enabled = 0;
if(run_all_mockup_tests()) return 1;
if(unit_test_storage()) return 1;
+#ifdef ENABLE_DBENGINE
+ if(test_dbengine()) return 1;
+#endif
fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
return 0;
}
+ else if(strncmp(optarg, createdataset_string, strlen(createdataset_string)) == 0) {
+ unsigned history_seconds;
+
+ optarg += strlen(createdataset_string);
+ history_seconds = (unsigned )strtoull(optarg, NULL, 0);
+
+#ifdef ENABLE_DBENGINE
+ generate_dbengine_dataset(history_seconds);
+#endif
+ return 0;
+ }
else if(strcmp(optarg, "simple-pattern") == 0) {
if(optind + 2 > argc) {
fprintf(stderr, "%s", "\nUSAGE: -W simple-pattern 'pattern' 'string'\n\n"
@@ -1052,8 +1133,10 @@ int main(int argc, char **argv) {
// initialize the log files
open_all_log_files();
+
netdata_anonymous_statistics_enabled=-1;
- send_statistics("START","-", "-");
+ struct rrdhost_system_info *system_info = calloc(1, sizeof(struct rrdhost_system_info));
+ if (get_system_info(system_info) == 0) send_statistics("START","-", "-");
#ifdef NETDATA_INTERNAL_CHECKS
if(debug_flags != 0) {
@@ -1088,14 +1171,13 @@ int main(int argc, char **argv) {
// ------------------------------------------------------------------------
// initialize rrd, registry, health, rrdpush, etc.
- rrd_init(netdata_configured_hostname);
-
+ rrd_init(netdata_configured_hostname, system_info);
+ rrdhost_system_info_free(system_info);
// ------------------------------------------------------------------------
// enable log flood protection
error_log_limit_reset();
-
// ------------------------------------------------------------------------
// spawn the threads
@@ -1113,7 +1195,7 @@ int main(int argc, char **argv) {
}
info("netdata initialization completed. Enjoy real-time performance monitoring!");
-
+ netdata_ready = 1;
// ------------------------------------------------------------------------
// unblock signals