From 7ac912b5baad5da2a2ff3374fe897a5a2593daa9 Mon Sep 17 00:00:00 2001 From: Vladimir Kobal Date: Fri, 24 May 2019 17:18:00 +0300 Subject: Remove system_info copying (#6113) * Remove system_info copying * Return res flag --- daemon/main.c | 15 +++++++------ database/rrd.h | 3 +-- database/rrdhost.c | 62 +++++++++++++++++++++-------------------------------- streaming/rrdpush.c | 3 +-- 4 files changed, 34 insertions(+), 49 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index a1577fb937..9b905a3d6d 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -670,7 +670,7 @@ static int load_netdata_conf(char *filename, char overwrite_used) { return ret; } -int get_system_info(struct rrdhost_system_info *system_info) { +int get_system_info(RRDHOST* host, 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"); @@ -701,7 +701,7 @@ int get_system_info(struct rrdhost_system_info *system_info) { 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))) { + if(unlikely(rrdhost_set_system_info_variable(host, system_info, n, v))) { info("Unexpected environment variable %s=%s", n, v); } else { @@ -1134,10 +1134,6 @@ int main(int argc, char **argv) { // initialize the log files open_all_log_files(); - netdata_anonymous_statistics_enabled=-1; - 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) { struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY }; @@ -1171,8 +1167,11 @@ int main(int argc, char **argv) { // ------------------------------------------------------------------------ // initialize rrd, registry, health, rrdpush, etc. + netdata_anonymous_statistics_enabled=-1; + struct rrdhost_system_info *system_info = calloc(1, sizeof(struct rrdhost_system_info)); + get_system_info(NULL, system_info); + rrd_init(netdata_configured_hostname, system_info); - rrdhost_system_info_free(system_info); // ------------------------------------------------------------------------ // enable log flood protection @@ -1196,6 +1195,8 @@ int main(int argc, char **argv) { info("netdata initialization completed. Enjoy real-time performance monitoring!"); netdata_ready = 1; + + if (get_system_info(localhost, system_info) == 0) send_statistics("START","-", "-"); // ------------------------------------------------------------------------ // unblock signals diff --git a/database/rrd.h b/database/rrd.h index 3f57b90370..7e63e08327 100644 --- a/database/rrd.h +++ b/database/rrd.h @@ -780,8 +780,7 @@ extern RRDHOST *rrdhost_find_or_create( , struct rrdhost_system_info *system_info ); -extern int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value); -extern struct rrdhost_system_info *rrdhost_system_info_dup(struct rrdhost_system_info *system_info); +extern int rrdhost_set_system_info_variable(RRDHOST *host, struct rrdhost_system_info *system_info, char *name, char *value); #if defined(NETDATA_INTERNAL_CHECKS) && defined(NETDATA_VERIFY_LOCKS) extern void __rrdhost_check_wrlock(RRDHOST *host, const char *file, const char *function, const unsigned long line); diff --git a/database/rrdhost.c b/database/rrdhost.c index c552c6c390..51e24e587e 100644 --- a/database/rrdhost.c +++ b/database/rrdhost.c @@ -162,7 +162,7 @@ RRDHOST *rrdhost_create(const char *hostname, host->program_version = strdupz((program_version && *program_version)?program_version:"unknown"); host->registry_hostname = strdupz((registry_hostname && *registry_hostname)?registry_hostname:hostname); - host->system_info = rrdhost_system_info_dup(system_info); + host->system_info = system_info; avl_init_lock(&(host->rrdset_root_index), rrdset_compare); avl_init_lock(&(host->rrdset_root_index_name), rrdset_compare_name); @@ -811,82 +811,68 @@ restart_after_removal: // ---------------------------------------------------------------------------- // RRDHOST - set system info from environment variables -int rrdhost_set_system_info_variable(struct rrdhost_system_info *system_info, char *name, char *value) { +int rrdhost_set_system_info_variable(RRDHOST *host, struct rrdhost_system_info *system_info, char *name, char *value) { + int res = 0; + + if(host) rrdhost_wrlock(host); + if(!strcmp(name, "NETDATA_SYSTEM_OS_NAME")){ + freez(system_info->os_name); system_info->os_name = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_OS_ID")){ + freez(system_info->os_id); system_info->os_id = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_OS_ID_LIKE")){ + freez(system_info->os_id_like); system_info->os_id_like = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_OS_VERSION")){ + freez(system_info->os_version); system_info->os_version = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_OS_VERSION_ID")){ + freez(system_info->os_version_id); system_info->os_version_id = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_OS_DETECTION")){ + freez(system_info->os_detection); system_info->os_detection = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_NAME")){ + freez(system_info->kernel_name); system_info->kernel_name = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_KERNEL_VERSION")){ + freez(system_info->kernel_version); system_info->kernel_version = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_ARCHITECTURE")){ + freez(system_info->architecture); system_info->architecture = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_VIRTUALIZATION")){ + freez(system_info->virtualization); system_info->virtualization = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_VIRT_DETECTION")){ + freez(system_info->virt_detection); system_info->virt_detection = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER")){ + freez(system_info->container); system_info->container = strdupz(value); } else if(!strcmp(name, "NETDATA_SYSTEM_CONTAINER_DETECTION")){ + freez(system_info->container_detection); system_info->container_detection = strdupz(value); } - else return 1; - - return 0; -} + else { + res = 1; + } -struct rrdhost_system_info *rrdhost_system_info_dup(struct rrdhost_system_info *system_info) { - struct rrdhost_system_info *ret = callocz(1, sizeof(struct rrdhost_system_info)); + if(host) rrdhost_unlock(host); - if(likely(system_info)) { - if(system_info->os_name) - ret->os_name = strdupz(system_info->os_name); - if(system_info->os_id) - ret->os_id = strdupz(system_info->os_id); - if(system_info->os_id_like) - ret->os_id_like = strdupz(system_info->os_id_like); - if(system_info->os_version) - ret->os_version = strdupz(system_info->os_version); - if(system_info->os_version_id) - ret->os_version_id = strdupz(system_info->os_version_id); - if(system_info->os_detection) - ret->os_detection = strdupz(system_info->os_detection); - if(system_info->kernel_name) - ret->kernel_name = strdupz(system_info->kernel_name); - if(system_info->kernel_version) - ret->kernel_version = strdupz(system_info->kernel_version); - if(system_info->architecture) - ret->architecture = strdupz(system_info->architecture); - if(system_info->virtualization) - ret->virtualization = strdupz(system_info->virtualization); - if(system_info->virt_detection) - ret->virt_detection = strdupz(system_info->virt_detection); - if(system_info->container) - ret->container = strdupz(system_info->container); - if(system_info->container_detection) - ret->container_detection = strdupz(system_info->container_detection); - } - - return ret; + return res; } diff --git a/streaming/rrdpush.c b/streaming/rrdpush.c index 2e9050ff28..cdf541e371 100644 --- a/streaming/rrdpush.c +++ b/streaming/rrdpush.c @@ -1079,7 +1079,6 @@ static void rrdpush_receiver_thread_cleanup(void *ptr) { freez(rpt->client_port); freez(rpt->program_name); freez(rpt->program_version); - rrdhost_system_info_free(rpt->system_info); freez(rpt); } } @@ -1179,7 +1178,7 @@ int rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url else if(!strcmp(name, "tags")) tags = value; else - if(unlikely(rrdhost_set_system_info_variable(system_info, name, value))) { + if(unlikely(rrdhost_set_system_info_variable(NULL, system_info, name, value))) { info("STREAM [receive from [%s]:%s]: request has parameter '%s' = '%s', which is not used.", w->client_ip, w->client_port, key, value); } } -- cgit v1.2.3