Enable analytics data collection (#20221)
* Ensure analytics data collection irrespective of enabled state. The analytics thread is now started even when disabled to support data population for the `/api/v1/info` endpoint. Data is collected locally but not sent when analytics is disabled. * Reduce initial analytics delay to 10 seconds. * Gather immutable data in 10 seconds, continue with the initial delay of 120 seconds
Stelios Fragkakis committed
May 2, 2025 at 13:20 UTC
5a642184cdf4c492f9aa868a368b78cb0976a9c4
3 files changed
+10
-4
src/daemon/analytics.c
+2
-1
@@ -652,12 +652,13 @@ void *analytics_main(void *ptr)
652
while (service_running(SERVICE_ANALYTICS) && likely(sec <= ANALYTICS_INIT_SLEEP_SEC)) {
653
heartbeat_next(&hb);
654
sec++;
655
+ if (sec == ANALYTICS_INIT_IMMUTABLE_DATA_SEC)
656
+ analytics_gather_immutable_meta_data();
657
}
658
659
if (unlikely(!service_running(SERVICE_ANALYTICS)))
660
goto cleanup;
661
660
- analytics_gather_immutable_meta_data();
662
analytics_gather_mutable_meta_data();
663
664
analytics_statistic_t statistic = { "META_START", "-", "-" };
src/daemon/analytics.h
+3
-1
@@ -7,7 +7,9 @@
7
#include "database/rrdhost-system-info.h"
8
9
/* Max number of seconds before the first META analytics is sent */
10
-#define ANALYTICS_INIT_SLEEP_SEC 120
10
+#define ANALYTICS_INIT_SLEEP_SEC (120)
11
+#define ANALYTICS_INIT_IMMUTABLE_DATA_SEC (10)
12
+
13
14
/* Send a META event every X seconds */
15
#define ANALYTICS_HEARTBEAT (6 * 3600)
src/daemon/main.c
+5
-2
@@ -1097,8 +1097,11 @@ int netdata_main(int argc, char **argv) {
1097
1098
// ----------------------------------------------------------------------------------------------------------------
1099
1100
- if(analytics_check_enabled()) {
1101
- delta_startup_time("anonymous analytics");
1100
+ {
1101
+ if(analytics_check_enabled())
1102
+ delta_startup_time("anonymous analytics");
1103
+ else // collect data but do not send it (needed in /api/v1/info)
1104
+ delta_startup_time("anonymous analytics (disabled)");
1105
1106
analytics_statistic_t start_statistic = {"START", "-", "-"};
1107
analytics_statistic_send(&start_statistic);