summaryrefslogtreecommitdiffstats
path: root/src/daemon/analytics.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/daemon/analytics.c (renamed from daemon/analytics.c)59
1 files changed, 35 insertions, 24 deletions
diff --git a/daemon/analytics.c b/src/daemon/analytics.c
index 353ebd136..33f6f357f 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;
@@ -224,7 +223,7 @@ void analytics_mirrored_hosts(void)
count++;
}
- rrd_unlock();
+ rrd_rdunlock();
snprintfz(b, sizeof(b) - 1, "%zu", count);
analytics_set_data(&analytics_data.netdata_mirrored_host_count, b);
@@ -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 ?
@@ -563,9 +562,11 @@ void analytics_gather_mutable_meta_data(void)
}
}
-void analytics_main_cleanup(void *ptr)
+void analytics_main_cleanup(void *pptr)
{
- struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
+ struct netdata_static_thread *static_thread = CLEANUP_FUNCTION_GET_PTR(pptr);
+ if(!static_thread) return;
+
static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
netdata_log_debug(D_ANALYTICS, "Cleaning up...");
@@ -582,7 +583,7 @@ void analytics_main_cleanup(void *ptr)
*/
void *analytics_main(void *ptr)
{
- netdata_thread_cleanup_push(analytics_main_cleanup, ptr);
+ CLEANUP_FUNCTION_REGISTER(analytics_main_cleanup) cleanup_ptr = ptr;
unsigned int sec = 0;
heartbeat_t hb;
heartbeat_init(&hb);
@@ -601,7 +602,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,13 +619,15 @@ 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;
}
cleanup:
- netdata_thread_cleanup_pop(1);
return NULL;
}
@@ -720,7 +725,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");
}
@@ -773,7 +778,7 @@ void get_system_timezone(void)
*d = '\0';
while (*timezone) {
- if (isalnum(*timezone) || *timezone == '_' || *timezone == '/')
+ if (isalnum((uint8_t)*timezone) || *timezone == '_' || *timezone == '/')
*d++ = *timezone++;
else
timezone++;
@@ -812,11 +817,11 @@ void get_system_timezone(void)
} else {
sign[0] = zone[0] == '-' || zone[0] == '+' ? zone[0] : '0';
sign[1] = '\0';
- hh[0] = isdigit(zone[1]) ? zone[1] : '0';
- hh[1] = isdigit(zone[2]) ? zone[2] : '0';
+ hh[0] = isdigit((uint8_t)zone[1]) ? zone[1] : '0';
+ hh[1] = isdigit((uint8_t)zone[2]) ? zone[2] : '0';
hh[2] = '\0';
- mm[0] = isdigit(zone[3]) ? zone[3] : '0';
- mm[1] = isdigit(zone[4]) ? zone[4] : '0';
+ mm[0] = isdigit((uint8_t)zone[3]) ? zone[3] : '0';
+ mm[1] = isdigit((uint8_t)zone[4]) ? zone[4] : '0';
mm[2] = '\0';
netdata_configured_utc_offset = (str2i(hh) * 3600) + (str2i(mm) * 60);
@@ -837,7 +842,7 @@ void set_global_environment() {
setenv("NETDATA_UPDATE_EVERY", b, 1);
}
- setenv("NETDATA_VERSION", program_version, 1);
+ setenv("NETDATA_VERSION", NETDATA_VERSION, 1);
setenv("NETDATA_HOSTNAME", netdata_configured_hostname, 1);
setenv("NETDATA_CONFIG_DIR", verify_required_directory(netdata_configured_user_config_dir), 1);
setenv("NETDATA_USER_CONFIG_DIR", verify_required_directory(netdata_configured_user_config_dir), 1);
@@ -943,7 +948,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 +988,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 +1008,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 +1054,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);