diff options
Diffstat (limited to '')
-rw-r--r-- | src/daemon/analytics.c (renamed from daemon/analytics.c) | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/daemon/analytics.c b/src/daemon/analytics.c index 353ebd136..015b8b2e8 100644 --- a/daemon/analytics.c +++ b/src/daemon/analytics.c @@ -7,7 +7,6 @@ struct analytics_data analytics_data; extern void analytics_exporting_connectors (BUFFER *b); extern void analytics_exporting_connectors_ssl (BUFFER *b); extern void analytics_build_info (BUFFER *b); -extern int aclk_connected; struct collector { const char *plugin; @@ -471,7 +470,7 @@ void analytics_alarms(void) */ void analytics_misc(void) { - analytics_data.spinlock.locked = false; + spinlock_init(&analytics_data.spinlock); #ifdef ENABLE_ACLK analytics_set_data(&analytics_data.netdata_host_cloud_available, "true"); @@ -489,7 +488,7 @@ void analytics_misc(void) if (strcmp( config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io"), - "https://registry.my-netdata.io")) + "https://registry.my-netdata.io") != 0) analytics_set_data(&analytics_data.netdata_config_use_private_registry, "true"); //do we need both registry to announce and enabled to indicate that this is a private registry ? @@ -601,7 +600,9 @@ void *analytics_main(void *ptr) analytics_gather_immutable_meta_data(); analytics_gather_mutable_meta_data(); - send_statistics("META_START", "-", "-"); + + analytics_statistic_t statistic = { "META_START", "-", "-" }; + analytics_statistic_send(&statistic); analytics_log_data(); sec = 0; @@ -616,8 +617,11 @@ void *analytics_main(void *ptr) continue; analytics_gather_mutable_meta_data(); - send_statistics("META", "-", "-"); + + analytics_statistic_t stt = { "META", "-", "-" }; + analytics_statistic_send(&stt); analytics_log_data(); + sec = 0; } @@ -720,7 +724,7 @@ void get_system_timezone(void) } // use the contents of /etc/timezone - if (!timezone && !read_file("/etc/timezone", buffer, FILENAME_MAX)) { + if (!timezone && !read_txt_file("/etc/timezone", buffer, sizeof(buffer))) { timezone = buffer; netdata_log_info("TIMEZONE: using the contents of /etc/timezone"); } @@ -943,7 +947,10 @@ void set_global_environment() { setenv("LC_ALL", "C", 1); } -void send_statistics(const char *action, const char *action_result, const char *action_data) { +void analytics_statistic_send(const analytics_statistic_t *statistic) { + if (!statistic) + return; + static char *as_script; if (netdata_anonymous_statistics_enabled == -1) { @@ -980,16 +987,19 @@ void send_statistics(const char *action, const char *action_result, const char * freez(optout_file); } - if (!netdata_anonymous_statistics_enabled || !action) + if (!netdata_anonymous_statistics_enabled || !statistic->action) return; - if (!action_result) + const char *action_result = statistic->result; + const char *action_data = statistic->data; + + if (!statistic->result) action_result = ""; - if (!action_data) + if (!statistic->data) action_data = ""; char *command_to_run = mallocz( - sizeof(char) * (strlen(action) + strlen(action_result) + strlen(action_data) + strlen(as_script) + + sizeof(char) * (strlen(statistic->action) + strlen(action_result) + strlen(action_data) + strlen(as_script) + analytics_data.data_length + (ANALYTICS_NO_OF_ITEMS * 3) + 15)); pid_t command_pid; @@ -997,7 +1007,7 @@ void send_statistics(const char *action, const char *action_result, const char * command_to_run, "%s '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' '%s' ", as_script, - action, + statistic->action, action_result, action_data, analytics_data.netdata_config_stream_enabled, @@ -1043,7 +1053,7 @@ void send_statistics(const char *action, const char *action_result, const char * nd_log(NDLS_DAEMON, NDLP_DEBUG, "%s '%s' '%s' '%s'", - as_script, action, action_result, action_data); + as_script, statistic->action, action_result, action_data); FILE *fp_child_input; FILE *fp_child_output = netdata_popen(command_to_run, &command_pid, &fp_child_input); |