analytics.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "common.h"
  3. #include "buildinfo.h"
  4. struct analytics_data analytics_data;
  5. extern void analytics_exporting_connectors (BUFFER *b);
  6. extern void analytics_exporting_connectors_ssl (BUFFER *b);
  7. extern void analytics_build_info (BUFFER *b);
  8. extern int aclk_connected;
  9. struct collector {
  10. const char *plugin;
  11. const char *module;
  12. };
  13. struct array_printer {
  14. int c;
  15. BUFFER *both;
  16. };
  17. /*
  18. * Debug logging
  19. */
  20. void analytics_log_data(void)
  21. {
  22. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_STREAM_ENABLED : [%s]", analytics_data.netdata_config_stream_enabled);
  23. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_MEMORY_MODE : [%s]", analytics_data.netdata_config_memory_mode);
  24. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_EXPORTING_ENABLED : [%s]", analytics_data.netdata_config_exporting_enabled);
  25. netdata_log_debug(D_ANALYTICS, "NETDATA_EXPORTING_CONNECTORS : [%s]", analytics_data.netdata_exporting_connectors);
  26. netdata_log_debug(D_ANALYTICS, "NETDATA_ALLMETRICS_PROMETHEUS_USED : [%s]", analytics_data.netdata_allmetrics_prometheus_used);
  27. netdata_log_debug(D_ANALYTICS, "NETDATA_ALLMETRICS_SHELL_USED : [%s]", analytics_data.netdata_allmetrics_shell_used);
  28. netdata_log_debug(D_ANALYTICS, "NETDATA_ALLMETRICS_JSON_USED : [%s]", analytics_data.netdata_allmetrics_json_used);
  29. netdata_log_debug(D_ANALYTICS, "NETDATA_DASHBOARD_USED : [%s]", analytics_data.netdata_dashboard_used);
  30. netdata_log_debug(D_ANALYTICS, "NETDATA_COLLECTORS : [%s]", analytics_data.netdata_collectors);
  31. netdata_log_debug(D_ANALYTICS, "NETDATA_COLLECTORS_COUNT : [%s]", analytics_data.netdata_collectors_count);
  32. netdata_log_debug(D_ANALYTICS, "NETDATA_BUILDINFO : [%s]", analytics_data.netdata_buildinfo);
  33. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_PAGE_CACHE_SIZE : [%s]", analytics_data.netdata_config_page_cache_size);
  34. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_MULTIDB_DISK_QUOTA : [%s]", analytics_data.netdata_config_multidb_disk_quota);
  35. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_HTTPS_ENABLED : [%s]", analytics_data.netdata_config_https_enabled);
  36. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_WEB_ENABLED : [%s]", analytics_data.netdata_config_web_enabled);
  37. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_RELEASE_CHANNEL : [%s]", analytics_data.netdata_config_release_channel);
  38. netdata_log_debug(D_ANALYTICS, "NETDATA_MIRRORED_HOST_COUNT : [%s]", analytics_data.netdata_mirrored_host_count);
  39. netdata_log_debug(D_ANALYTICS, "NETDATA_MIRRORED_HOSTS_REACHABLE : [%s]", analytics_data.netdata_mirrored_hosts_reachable);
  40. netdata_log_debug(D_ANALYTICS, "NETDATA_MIRRORED_HOSTS_UNREACHABLE : [%s]", analytics_data.netdata_mirrored_hosts_unreachable);
  41. netdata_log_debug(D_ANALYTICS, "NETDATA_NOTIFICATION_METHODS : [%s]", analytics_data.netdata_notification_methods);
  42. netdata_log_debug(D_ANALYTICS, "NETDATA_ALARMS_NORMAL : [%s]", analytics_data.netdata_alarms_normal);
  43. netdata_log_debug(D_ANALYTICS, "NETDATA_ALARMS_WARNING : [%s]", analytics_data.netdata_alarms_warning);
  44. netdata_log_debug(D_ANALYTICS, "NETDATA_ALARMS_CRITICAL : [%s]", analytics_data.netdata_alarms_critical);
  45. netdata_log_debug(D_ANALYTICS, "NETDATA_CHARTS_COUNT : [%s]", analytics_data.netdata_charts_count);
  46. netdata_log_debug(D_ANALYTICS, "NETDATA_METRICS_COUNT : [%s]", analytics_data.netdata_metrics_count);
  47. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_IS_PARENT : [%s]", analytics_data.netdata_config_is_parent);
  48. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_HOSTS_AVAILABLE : [%s]", analytics_data.netdata_config_hosts_available);
  49. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_CLOUD_AVAILABLE : [%s]", analytics_data.netdata_host_cloud_available);
  50. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_ACLK_AVAILABLE : [%s]", analytics_data.netdata_host_aclk_available);
  51. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_ACLK_PROTOCOL : [%s]", analytics_data.netdata_host_aclk_protocol);
  52. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_ACLK_IMPLEMENTATION : [%s]", analytics_data.netdata_host_aclk_implementation);
  53. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_AGENT_CLAIMED : [%s]", analytics_data.netdata_host_agent_claimed);
  54. netdata_log_debug(D_ANALYTICS, "NETDATA_HOST_CLOUD_ENABLED : [%s]", analytics_data.netdata_host_cloud_enabled);
  55. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_HTTPS_AVAILABLE : [%s]", analytics_data.netdata_config_https_available);
  56. netdata_log_debug(D_ANALYTICS, "NETDATA_INSTALL_TYPE : [%s]", analytics_data.netdata_install_type);
  57. netdata_log_debug(D_ANALYTICS, "NETDATA_PREBUILT_DISTRO : [%s]", analytics_data.netdata_prebuilt_distro);
  58. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_IS_PRIVATE_REGISTRY : [%s]", analytics_data.netdata_config_is_private_registry);
  59. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_USE_PRIVATE_REGISTRY: [%s]", analytics_data.netdata_config_use_private_registry);
  60. netdata_log_debug(D_ANALYTICS, "NETDATA_CONFIG_OOM_SCORE : [%s]", analytics_data.netdata_config_oom_score);
  61. }
  62. /*
  63. * Free data
  64. */
  65. void analytics_free_data(void)
  66. {
  67. freez(analytics_data.netdata_config_stream_enabled);
  68. freez(analytics_data.netdata_config_memory_mode);
  69. freez(analytics_data.netdata_config_exporting_enabled);
  70. freez(analytics_data.netdata_exporting_connectors);
  71. freez(analytics_data.netdata_allmetrics_prometheus_used);
  72. freez(analytics_data.netdata_allmetrics_shell_used);
  73. freez(analytics_data.netdata_allmetrics_json_used);
  74. freez(analytics_data.netdata_dashboard_used);
  75. freez(analytics_data.netdata_collectors);
  76. freez(analytics_data.netdata_collectors_count);
  77. freez(analytics_data.netdata_buildinfo);
  78. freez(analytics_data.netdata_config_page_cache_size);
  79. freez(analytics_data.netdata_config_multidb_disk_quota);
  80. freez(analytics_data.netdata_config_https_enabled);
  81. freez(analytics_data.netdata_config_web_enabled);
  82. freez(analytics_data.netdata_config_release_channel);
  83. freez(analytics_data.netdata_mirrored_host_count);
  84. freez(analytics_data.netdata_mirrored_hosts_reachable);
  85. freez(analytics_data.netdata_mirrored_hosts_unreachable);
  86. freez(analytics_data.netdata_notification_methods);
  87. freez(analytics_data.netdata_alarms_normal);
  88. freez(analytics_data.netdata_alarms_warning);
  89. freez(analytics_data.netdata_alarms_critical);
  90. freez(analytics_data.netdata_charts_count);
  91. freez(analytics_data.netdata_metrics_count);
  92. freez(analytics_data.netdata_config_is_parent);
  93. freez(analytics_data.netdata_config_hosts_available);
  94. freez(analytics_data.netdata_host_cloud_available);
  95. freez(analytics_data.netdata_host_aclk_available);
  96. freez(analytics_data.netdata_host_aclk_protocol);
  97. freez(analytics_data.netdata_host_aclk_implementation);
  98. freez(analytics_data.netdata_host_agent_claimed);
  99. freez(analytics_data.netdata_host_cloud_enabled);
  100. freez(analytics_data.netdata_config_https_available);
  101. freez(analytics_data.netdata_install_type);
  102. freez(analytics_data.netdata_config_is_private_registry);
  103. freez(analytics_data.netdata_config_use_private_registry);
  104. freez(analytics_data.netdata_config_oom_score);
  105. freez(analytics_data.netdata_prebuilt_distro);
  106. }
  107. /*
  108. * Set a numeric/boolean data with a value
  109. */
  110. void analytics_set_data(char **name, char *value)
  111. {
  112. if (*name) {
  113. analytics_data.data_length -= strlen(*name);
  114. freez(*name);
  115. }
  116. *name = strdupz(value);
  117. analytics_data.data_length += strlen(*name);
  118. }
  119. /*
  120. * Set a string data with a value
  121. */
  122. void analytics_set_data_str(char **name, char *value)
  123. {
  124. size_t value_string_len;
  125. if (*name) {
  126. analytics_data.data_length -= strlen(*name);
  127. freez(*name);
  128. }
  129. value_string_len = strlen(value) + 4;
  130. *name = mallocz(sizeof(char) * value_string_len);
  131. snprintfz(*name, value_string_len - 1, "\"%s\"", value);
  132. analytics_data.data_length += strlen(*name);
  133. }
  134. /*
  135. * Log hits on the allmetrics page, with prometheus parameter
  136. */
  137. void analytics_log_prometheus(void)
  138. {
  139. if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.prometheus_hits < ANALYTICS_MAX_PROMETHEUS_HITS)) {
  140. analytics_data.prometheus_hits++;
  141. char b[21];
  142. snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
  143. analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
  144. }
  145. }
  146. /*
  147. * Log hits on the allmetrics page, with shell parameter (or default)
  148. */
  149. void analytics_log_shell(void)
  150. {
  151. if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.shell_hits < ANALYTICS_MAX_SHELL_HITS)) {
  152. analytics_data.shell_hits++;
  153. char b[21];
  154. snprintfz(b, 20, "%zu", analytics_data.shell_hits);
  155. analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
  156. }
  157. }
  158. /*
  159. * Log hits on the allmetrics page, with json parameter
  160. */
  161. void analytics_log_json(void)
  162. {
  163. if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.json_hits < ANALYTICS_MAX_JSON_HITS)) {
  164. analytics_data.json_hits++;
  165. char b[21];
  166. snprintfz(b, 20, "%zu", analytics_data.json_hits);
  167. analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
  168. }
  169. }
  170. /*
  171. * Log hits on the dashboard, (when calling HELLO).
  172. */
  173. void analytics_log_dashboard(void)
  174. {
  175. if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.dashboard_hits < ANALYTICS_MAX_DASHBOARD_HITS)) {
  176. analytics_data.dashboard_hits++;
  177. char b[21];
  178. snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
  179. analytics_set_data(&analytics_data.netdata_dashboard_used, b);
  180. }
  181. }
  182. /*
  183. * Called when setting the oom score
  184. */
  185. void analytics_report_oom_score(long long int score){
  186. char b[21];
  187. snprintfz(b, 20, "%lld", score);
  188. analytics_set_data(&analytics_data.netdata_config_oom_score, b);
  189. }
  190. void analytics_mirrored_hosts(void)
  191. {
  192. RRDHOST *host;
  193. size_t count = 0;
  194. size_t reachable = 0;
  195. size_t unreachable = 0;
  196. char b[21];
  197. rrd_rdlock();
  198. rrdhost_foreach_read(host)
  199. {
  200. if (rrdhost_flag_check(host, RRDHOST_FLAG_ARCHIVED))
  201. continue;
  202. ((host == localhost || !rrdhost_flag_check(host, RRDHOST_FLAG_ORPHAN)) ? reachable++ : unreachable++);
  203. count++;
  204. }
  205. rrd_unlock();
  206. snprintfz(b, 20, "%zu", count);
  207. analytics_set_data(&analytics_data.netdata_mirrored_host_count, b);
  208. snprintfz(b, 20, "%zu", reachable);
  209. analytics_set_data(&analytics_data.netdata_mirrored_hosts_reachable, b);
  210. snprintfz(b, 20, "%zu", unreachable);
  211. analytics_set_data(&analytics_data.netdata_mirrored_hosts_unreachable, b);
  212. }
  213. void analytics_exporters(void)
  214. {
  215. //when no exporters are available, an empty string will be sent
  216. //decide if something else is more suitable (but probably not null)
  217. BUFFER *bi = buffer_create(1000, NULL);
  218. analytics_exporting_connectors(bi);
  219. analytics_set_data_str(&analytics_data.netdata_exporting_connectors, (char *)buffer_tostring(bi));
  220. buffer_free(bi);
  221. }
  222. int collector_counter_callb(const DICTIONARY_ITEM *item __maybe_unused, void *entry, void *data) {
  223. struct array_printer *ap = (struct array_printer *)data;
  224. struct collector *col = (struct collector *)entry;
  225. BUFFER *bt = ap->both;
  226. if (likely(ap->c)) {
  227. buffer_strcat(bt, ",");
  228. }
  229. buffer_strcat(bt, "{");
  230. buffer_strcat(bt, " \"plugin\": \"");
  231. buffer_strcat(bt, col->plugin);
  232. buffer_strcat(bt, "\", \"module\":\"");
  233. buffer_strcat(bt, col->module);
  234. buffer_strcat(bt, "\" }");
  235. (ap->c)++;
  236. return 0;
  237. }
  238. /*
  239. * Create a JSON array of available collectors, same as in api/v1/info
  240. */
  241. void analytics_collectors(void)
  242. {
  243. RRDSET *st;
  244. DICTIONARY *dict = dictionary_create(DICT_OPTION_SINGLE_THREADED);
  245. char name[500];
  246. BUFFER *bt = buffer_create(1000, NULL);
  247. rrdset_foreach_read(st, localhost) {
  248. if(!rrdset_is_available_for_viewers(st))
  249. continue;
  250. struct collector col = {
  251. .plugin = rrdset_plugin_name(st),
  252. .module = rrdset_module_name(st)
  253. };
  254. snprintfz(name, 499, "%s:%s", col.plugin, col.module);
  255. dictionary_set(dict, name, &col, sizeof(struct collector));
  256. }
  257. rrdset_foreach_done(st);
  258. struct array_printer ap;
  259. ap.c = 0;
  260. ap.both = bt;
  261. dictionary_walkthrough_read(dict, collector_counter_callb, &ap);
  262. dictionary_destroy(dict);
  263. analytics_set_data(&analytics_data.netdata_collectors, (char *)buffer_tostring(ap.both));
  264. {
  265. char b[21];
  266. snprintfz(b, 20, "%d", ap.c);
  267. analytics_set_data(&analytics_data.netdata_collectors_count, b);
  268. }
  269. buffer_free(bt);
  270. }
  271. /*
  272. * Run alarm-notify.sh script using the dump_methods parameter
  273. * SEND_CUSTOM is always available
  274. */
  275. void analytics_alarms_notifications(void)
  276. {
  277. char *script;
  278. script = mallocz(
  279. sizeof(char) * (strlen(netdata_configured_primary_plugins_dir) + strlen("alarm-notify.sh dump_methods") + 2));
  280. sprintf(script, "%s/%s", netdata_configured_primary_plugins_dir, "alarm-notify.sh");
  281. if (unlikely(access(script, R_OK) != 0)) {
  282. netdata_log_info("Alarm notify script %s not found.", script);
  283. freez(script);
  284. return;
  285. }
  286. strcat(script, " dump_methods");
  287. pid_t command_pid;
  288. netdata_log_debug(D_ANALYTICS, "Executing %s", script);
  289. BUFFER *b = buffer_create(1000, NULL);
  290. int cnt = 0;
  291. FILE *fp_child_input;
  292. FILE *fp_child_output = netdata_popen(script, &command_pid, &fp_child_input);
  293. if (fp_child_output) {
  294. char line[200 + 1];
  295. while (fgets(line, 200, fp_child_output) != NULL) {
  296. char *end = line;
  297. while (*end && *end != '\n')
  298. end++;
  299. *end = '\0';
  300. if (likely(cnt))
  301. buffer_strcat(b, "|");
  302. buffer_strcat(b, line);
  303. cnt++;
  304. }
  305. netdata_pclose(fp_child_input, fp_child_output, command_pid);
  306. }
  307. freez(script);
  308. analytics_set_data_str(&analytics_data.netdata_notification_methods, (char *)buffer_tostring(b));
  309. buffer_free(b);
  310. }
  311. static void analytics_get_install_type(struct rrdhost_system_info *system_info)
  312. {
  313. if (system_info->install_type == NULL) {
  314. analytics_set_data_str(&analytics_data.netdata_install_type, "unknown");
  315. } else {
  316. analytics_set_data_str(&analytics_data.netdata_install_type, system_info->install_type);
  317. }
  318. if (system_info->prebuilt_dist != NULL) {
  319. analytics_set_data_str(&analytics_data.netdata_prebuilt_distro, system_info->prebuilt_dist);
  320. }
  321. }
  322. /*
  323. * Pick up if https is actually used
  324. */
  325. void analytics_https(void)
  326. {
  327. BUFFER *b = buffer_create(30, NULL);
  328. #ifdef ENABLE_HTTPS
  329. analytics_exporting_connectors_ssl(b);
  330. buffer_strcat(b, netdata_ssl_streaming_sender_ctx &&
  331. rrdhost_flag_check(localhost, RRDHOST_FLAG_RRDPUSH_SENDER_CONNECTED) &&
  332. SSL_connection(&localhost->sender->ssl) ? "streaming|" : "|");
  333. buffer_strcat(b, netdata_ssl_web_server_ctx ? "web" : "");
  334. #else
  335. buffer_strcat(b, "||");
  336. #endif
  337. analytics_set_data_str(&analytics_data.netdata_config_https_available, (char *)buffer_tostring(b));
  338. buffer_free(b);
  339. }
  340. void analytics_charts(void)
  341. {
  342. RRDSET *st;
  343. size_t c = 0;
  344. rrdset_foreach_read(st, localhost)
  345. if(rrdset_is_available_for_viewers(st)) c++;
  346. rrdset_foreach_done(st);
  347. analytics_data.charts_count = c;
  348. {
  349. char b[21];
  350. snprintfz(b, 20, "%zu", c);
  351. analytics_set_data(&analytics_data.netdata_charts_count, b);
  352. }
  353. }
  354. void analytics_metrics(void)
  355. {
  356. RRDSET *st;
  357. size_t dimensions = 0;
  358. rrdset_foreach_read(st, localhost) {
  359. if (rrdset_is_available_for_viewers(st)) {
  360. RRDDIM *rd;
  361. rrddim_foreach_read(rd, st) {
  362. if (rrddim_option_check(rd, RRDDIM_OPTION_HIDDEN) || rrddim_flag_check(rd, RRDDIM_FLAG_OBSOLETE))
  363. continue;
  364. dimensions++;
  365. }
  366. rrddim_foreach_done(rd);
  367. }
  368. }
  369. rrdset_foreach_done(st);
  370. analytics_data.metrics_count = dimensions;
  371. {
  372. char b[21];
  373. snprintfz(b, 20, "%zu", dimensions);
  374. analytics_set_data(&analytics_data.netdata_metrics_count, b);
  375. }
  376. }
  377. void analytics_alarms(void)
  378. {
  379. size_t alarm_warn = 0, alarm_crit = 0, alarm_normal = 0;
  380. char b[21];
  381. RRDCALC *rc;
  382. foreach_rrdcalc_in_rrdhost_read(localhost, rc) {
  383. if (unlikely(!rc->rrdset || !rc->rrdset->last_collected_time.tv_sec))
  384. continue;
  385. switch (rc->status) {
  386. case RRDCALC_STATUS_WARNING:
  387. alarm_warn++;
  388. break;
  389. case RRDCALC_STATUS_CRITICAL:
  390. alarm_crit++;
  391. break;
  392. default:
  393. alarm_normal++;
  394. }
  395. }
  396. foreach_rrdcalc_in_rrdhost_done(rc);
  397. snprintfz(b, 20, "%zu", alarm_normal);
  398. analytics_set_data(&analytics_data.netdata_alarms_normal, b);
  399. snprintfz(b, 20, "%zu", alarm_warn);
  400. analytics_set_data(&analytics_data.netdata_alarms_warning, b);
  401. snprintfz(b, 20, "%zu", alarm_crit);
  402. analytics_set_data(&analytics_data.netdata_alarms_critical, b);
  403. }
  404. /*
  405. * Misc attributes to get (run from start)
  406. */
  407. void analytics_misc(void)
  408. {
  409. #ifdef ENABLE_ACLK
  410. analytics_set_data(&analytics_data.netdata_host_cloud_available, "true");
  411. analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "Next Generation");
  412. #else
  413. analytics_set_data(&analytics_data.netdata_host_cloud_available, "false");
  414. analytics_set_data_str(&analytics_data.netdata_host_aclk_implementation, "");
  415. #endif
  416. analytics_data.exporting_enabled = appconfig_get_boolean(&exporting_config, CONFIG_SECTION_EXPORTING, "enabled", CONFIG_BOOLEAN_NO);
  417. analytics_set_data(&analytics_data.netdata_config_exporting_enabled, analytics_data.exporting_enabled ? "true" : "false");
  418. analytics_set_data(&analytics_data.netdata_config_is_private_registry, "false");
  419. analytics_set_data(&analytics_data.netdata_config_use_private_registry, "false");
  420. if (strcmp(
  421. config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io"),
  422. "https://registry.my-netdata.io"))
  423. analytics_set_data(&analytics_data.netdata_config_use_private_registry, "true");
  424. //do we need both registry to announce and enabled to indicate that this is a private registry ?
  425. if (config_get_boolean(CONFIG_SECTION_REGISTRY, "enabled", CONFIG_BOOLEAN_NO) &&
  426. web_server_mode != WEB_SERVER_MODE_NONE)
  427. analytics_set_data(&analytics_data.netdata_config_is_private_registry, "true");
  428. }
  429. void analytics_aclk(void)
  430. {
  431. #ifdef ENABLE_ACLK
  432. if (aclk_connected) {
  433. analytics_set_data(&analytics_data.netdata_host_aclk_available, "true");
  434. analytics_set_data_str(&analytics_data.netdata_host_aclk_protocol, "New");
  435. }
  436. else
  437. #endif
  438. analytics_set_data(&analytics_data.netdata_host_aclk_available, "false");
  439. }
  440. /*
  441. * Get the meta data, called from the thread once after the original delay
  442. * These are values that won't change during agent runtime, and therefore
  443. * don't try to read them on each META event send
  444. */
  445. void analytics_gather_immutable_meta_data(void)
  446. {
  447. analytics_misc();
  448. analytics_exporters();
  449. analytics_https();
  450. }
  451. /*
  452. * Get the meta data, called from the thread on every heartbeat, and right before the EXIT event
  453. * These are values that can change between agent restarts, and therefore
  454. * try to read them on each META event send
  455. */
  456. void analytics_gather_mutable_meta_data(void)
  457. {
  458. analytics_collectors();
  459. analytics_alarms();
  460. analytics_charts();
  461. analytics_metrics();
  462. analytics_aclk();
  463. analytics_mirrored_hosts();
  464. analytics_alarms_notifications();
  465. analytics_set_data(
  466. &analytics_data.netdata_config_is_parent, (rrdhost_hosts_available() > 1 || configured_as_parent()) ? "true" : "false");
  467. char *claim_id = get_agent_claimid();
  468. analytics_set_data(&analytics_data.netdata_host_agent_claimed, claim_id ? "true" : "false");
  469. freez(claim_id);
  470. {
  471. char b[21];
  472. snprintfz(b, 20, "%zu", analytics_data.prometheus_hits);
  473. analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b);
  474. snprintfz(b, 20, "%zu", analytics_data.shell_hits);
  475. analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b);
  476. snprintfz(b, 20, "%zu", analytics_data.json_hits);
  477. analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b);
  478. snprintfz(b, 20, "%zu", analytics_data.dashboard_hits);
  479. analytics_set_data(&analytics_data.netdata_dashboard_used, b);
  480. snprintfz(b, 20, "%zu", rrdhost_hosts_available());
  481. analytics_set_data(&analytics_data.netdata_config_hosts_available, b);
  482. }
  483. }
  484. void analytics_main_cleanup(void *ptr)
  485. {
  486. struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
  487. static_thread->enabled = NETDATA_MAIN_THREAD_EXITING;
  488. netdata_log_debug(D_ANALYTICS, "Cleaning up...");
  489. analytics_free_data();
  490. static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
  491. }
  492. /*
  493. * The analytics thread. Sleep for ANALYTICS_INIT_SLEEP_SEC,
  494. * gather the data, and then go to a loop where every ANALYTICS_HEARTBEAT
  495. * it will send a new META event after gathering data that could be changed
  496. * while the agent is running
  497. */
  498. void *analytics_main(void *ptr)
  499. {
  500. netdata_thread_cleanup_push(analytics_main_cleanup, ptr);
  501. unsigned int sec = 0;
  502. heartbeat_t hb;
  503. heartbeat_init(&hb);
  504. usec_t step_ut = USEC_PER_SEC;
  505. netdata_log_debug(D_ANALYTICS, "Analytics thread starts");
  506. //first delay after agent start
  507. while (service_running(SERVICE_ANALYTICS) && likely(sec <= ANALYTICS_INIT_SLEEP_SEC)) {
  508. heartbeat_next(&hb, step_ut);
  509. sec++;
  510. }
  511. if (unlikely(!service_running(SERVICE_ANALYTICS)))
  512. goto cleanup;
  513. analytics_gather_immutable_meta_data();
  514. analytics_gather_mutable_meta_data();
  515. send_statistics("META_START", "-", "-");
  516. analytics_log_data();
  517. sec = 0;
  518. while (1) {
  519. heartbeat_next(&hb, step_ut * 2);
  520. sec += 2;
  521. if (unlikely(!service_running(SERVICE_ANALYTICS)))
  522. break;
  523. if (likely(sec < ANALYTICS_HEARTBEAT))
  524. continue;
  525. analytics_gather_mutable_meta_data();
  526. send_statistics("META", "-", "-");
  527. analytics_log_data();
  528. sec = 0;
  529. }
  530. cleanup:
  531. netdata_thread_cleanup_pop(1);
  532. return NULL;
  533. }
  534. static const char *verify_required_directory(const char *dir)
  535. {
  536. if (chdir(dir) == -1)
  537. fatal("Cannot change directory to '%s'", dir);
  538. DIR *d = opendir(dir);
  539. if (!d)
  540. fatal("Cannot examine the contents of directory '%s'", dir);
  541. closedir(d);
  542. return dir;
  543. }
  544. static const char *verify_or_create_required_directory(const char *dir) {
  545. int result;
  546. result = mkdir(dir, 0755);
  547. if (result != 0 && errno != EEXIST)
  548. fatal("Cannot create required directory '%s'", dir);
  549. return verify_required_directory(dir);
  550. }
  551. /*
  552. * This is called after the rrdinit
  553. * These values will be sent on the START event
  554. */
  555. void set_late_global_environment(struct rrdhost_system_info *system_info)
  556. {
  557. analytics_set_data(&analytics_data.netdata_config_stream_enabled, default_rrdpush_enabled ? "true" : "false");
  558. analytics_set_data_str(&analytics_data.netdata_config_memory_mode, (char *)rrd_memory_mode_name(default_rrd_memory_mode));
  559. #ifdef DISABLE_CLOUD
  560. analytics_set_data(&analytics_data.netdata_host_cloud_enabled, "false");
  561. #else
  562. analytics_set_data(
  563. &analytics_data.netdata_host_cloud_enabled,
  564. appconfig_get_boolean_ondemand(&cloud_config, CONFIG_SECTION_GLOBAL, "enabled", netdata_cloud_enabled) ? "true" : "false");
  565. #endif
  566. #ifdef ENABLE_DBENGINE
  567. {
  568. char b[16];
  569. snprintfz(b, 15, "%d", default_rrdeng_page_cache_mb);
  570. analytics_set_data(&analytics_data.netdata_config_page_cache_size, b);
  571. snprintfz(b, 15, "%d", default_multidb_disk_quota_mb);
  572. analytics_set_data(&analytics_data.netdata_config_multidb_disk_quota, b);
  573. }
  574. #endif
  575. #ifdef ENABLE_HTTPS
  576. analytics_set_data(&analytics_data.netdata_config_https_enabled, "true");
  577. #else
  578. analytics_set_data(&analytics_data.netdata_config_https_enabled, "false");
  579. #endif
  580. if (web_server_mode == WEB_SERVER_MODE_NONE)
  581. analytics_set_data(&analytics_data.netdata_config_web_enabled, "false");
  582. else
  583. analytics_set_data(&analytics_data.netdata_config_web_enabled, "true");
  584. analytics_set_data_str(&analytics_data.netdata_config_release_channel, (char *)get_release_channel());
  585. {
  586. BUFFER *bi = buffer_create(1000, NULL);
  587. analytics_build_info(bi);
  588. analytics_set_data_str(&analytics_data.netdata_buildinfo, (char *)buffer_tostring(bi));
  589. buffer_free(bi);
  590. }
  591. analytics_get_install_type(system_info);
  592. }
  593. void get_system_timezone(void)
  594. {
  595. // avoid flood calls to stat(/etc/localtime)
  596. // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
  597. const char *tz = getenv("TZ");
  598. if (!tz || !*tz)
  599. setenv("TZ", config_get(CONFIG_SECTION_ENV_VARS, "TZ", ":/etc/localtime"), 0);
  600. char buffer[FILENAME_MAX + 1] = "";
  601. const char *timezone = NULL;
  602. ssize_t ret;
  603. // use the TZ variable
  604. if (tz && *tz && *tz != ':') {
  605. timezone = tz;
  606. netdata_log_info("TIMEZONE: using TZ variable '%s'", timezone);
  607. }
  608. // use the contents of /etc/timezone
  609. if (!timezone && !read_file("/etc/timezone", buffer, FILENAME_MAX)) {
  610. timezone = buffer;
  611. netdata_log_info("TIMEZONE: using the contents of /etc/timezone");
  612. }
  613. // read the link /etc/localtime
  614. if (!timezone) {
  615. ret = readlink("/etc/localtime", buffer, FILENAME_MAX);
  616. if (ret > 0) {
  617. buffer[ret] = '\0';
  618. char *cmp = "/usr/share/zoneinfo/";
  619. size_t cmp_len = strlen(cmp);
  620. char *s = strstr(buffer, cmp);
  621. if (s && s[cmp_len]) {
  622. timezone = &s[cmp_len];
  623. netdata_log_info("TIMEZONE: using the link of /etc/localtime: '%s'", timezone);
  624. }
  625. } else
  626. buffer[0] = '\0';
  627. }
  628. // find the timezone from strftime()
  629. if (!timezone) {
  630. time_t t;
  631. struct tm *tmp, tmbuf;
  632. t = now_realtime_sec();
  633. tmp = localtime_r(&t, &tmbuf);
  634. if (tmp != NULL) {
  635. if (strftime(buffer, FILENAME_MAX, "%Z", tmp) == 0)
  636. buffer[0] = '\0';
  637. else {
  638. buffer[FILENAME_MAX] = '\0';
  639. timezone = buffer;
  640. netdata_log_info("TIMEZONE: using strftime(): '%s'", timezone);
  641. }
  642. }
  643. }
  644. if (timezone && *timezone) {
  645. // make sure it does not have illegal characters
  646. // netdata_log_info("TIMEZONE: fixing '%s'", timezone);
  647. size_t len = strlen(timezone);
  648. char tmp[len + 1];
  649. char *d = tmp;
  650. *d = '\0';
  651. while (*timezone) {
  652. if (isalnum(*timezone) || *timezone == '_' || *timezone == '/')
  653. *d++ = *timezone++;
  654. else
  655. timezone++;
  656. }
  657. *d = '\0';
  658. strncpyz(buffer, tmp, len);
  659. timezone = buffer;
  660. netdata_log_info("TIMEZONE: fixed as '%s'", timezone);
  661. }
  662. if (!timezone || !*timezone)
  663. timezone = "unknown";
  664. netdata_configured_timezone = config_get(CONFIG_SECTION_GLOBAL, "timezone", timezone);
  665. //get the utc offset, and the timezone as returned by strftime
  666. //will be sent to the cloud
  667. //Note: This will need an agent restart to get new offset on time change (dst, etc).
  668. {
  669. time_t t;
  670. struct tm *tmp, tmbuf;
  671. char zone[FILENAME_MAX + 1];
  672. char sign[2], hh[3], mm[3];
  673. t = now_realtime_sec();
  674. tmp = localtime_r(&t, &tmbuf);
  675. if (tmp != NULL) {
  676. if (strftime(zone, FILENAME_MAX, "%Z", tmp) == 0) {
  677. netdata_configured_abbrev_timezone = strdupz("UTC");
  678. } else
  679. netdata_configured_abbrev_timezone = strdupz(zone);
  680. if (strftime(zone, FILENAME_MAX, "%z", tmp) == 0) {
  681. netdata_configured_utc_offset = 0;
  682. } else {
  683. sign[0] = zone[0] == '-' || zone[0] == '+' ? zone[0] : '0';
  684. sign[1] = '\0';
  685. hh[0] = isdigit(zone[1]) ? zone[1] : '0';
  686. hh[1] = isdigit(zone[2]) ? zone[2] : '0';
  687. hh[2] = '\0';
  688. mm[0] = isdigit(zone[3]) ? zone[3] : '0';
  689. mm[1] = isdigit(zone[4]) ? zone[4] : '0';
  690. mm[2] = '\0';
  691. netdata_configured_utc_offset = (str2i(hh) * 3600) + (str2i(mm) * 60);
  692. netdata_configured_utc_offset =
  693. sign[0] == '-' ? -netdata_configured_utc_offset : netdata_configured_utc_offset;
  694. }
  695. } else {
  696. netdata_configured_abbrev_timezone = strdupz("UTC");
  697. netdata_configured_utc_offset = 0;
  698. }
  699. }
  700. }
  701. void set_global_environment()
  702. {
  703. {
  704. char b[16];
  705. snprintfz(b, 15, "%d", default_rrd_update_every);
  706. setenv("NETDATA_UPDATE_EVERY", b, 1);
  707. }
  708. setenv("NETDATA_VERSION", program_version, 1);
  709. setenv("NETDATA_HOSTNAME", netdata_configured_hostname, 1);
  710. setenv("NETDATA_CONFIG_DIR", verify_required_directory(netdata_configured_user_config_dir), 1);
  711. setenv("NETDATA_USER_CONFIG_DIR", verify_required_directory(netdata_configured_user_config_dir), 1);
  712. setenv("NETDATA_STOCK_CONFIG_DIR", verify_required_directory(netdata_configured_stock_config_dir), 1);
  713. setenv("NETDATA_PLUGINS_DIR", verify_required_directory(netdata_configured_primary_plugins_dir), 1);
  714. setenv("NETDATA_WEB_DIR", verify_required_directory(netdata_configured_web_dir), 1);
  715. setenv("NETDATA_CACHE_DIR", verify_or_create_required_directory(netdata_configured_cache_dir), 1);
  716. setenv("NETDATA_LIB_DIR", verify_or_create_required_directory(netdata_configured_varlib_dir), 1);
  717. setenv("NETDATA_LOCK_DIR", verify_or_create_required_directory(netdata_configured_lock_dir), 1);
  718. setenv("NETDATA_LOG_DIR", verify_or_create_required_directory(netdata_configured_log_dir), 1);
  719. setenv("HOME", verify_or_create_required_directory(netdata_configured_home_dir), 1);
  720. setenv("NETDATA_HOST_PREFIX", netdata_configured_host_prefix, 1);
  721. {
  722. BUFFER *user_plugins_dirs = buffer_create(FILENAME_MAX, NULL);
  723. for (size_t i = 1; i < PLUGINSD_MAX_DIRECTORIES && plugin_directories[i]; i++) {
  724. if (i > 1)
  725. buffer_strcat(user_plugins_dirs, " ");
  726. buffer_strcat(user_plugins_dirs, plugin_directories[i]);
  727. }
  728. setenv("NETDATA_USER_PLUGINS_DIRS", buffer_tostring(user_plugins_dirs), 1);
  729. buffer_free(user_plugins_dirs);
  730. }
  731. analytics_data.data_length = 0;
  732. analytics_set_data(&analytics_data.netdata_config_stream_enabled, "null");
  733. analytics_set_data(&analytics_data.netdata_config_memory_mode, "null");
  734. analytics_set_data(&analytics_data.netdata_config_exporting_enabled, "null");
  735. analytics_set_data(&analytics_data.netdata_exporting_connectors, "null");
  736. analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, "null");
  737. analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, "null");
  738. analytics_set_data(&analytics_data.netdata_allmetrics_json_used, "null");
  739. analytics_set_data(&analytics_data.netdata_dashboard_used, "null");
  740. analytics_set_data(&analytics_data.netdata_collectors, "null");
  741. analytics_set_data(&analytics_data.netdata_collectors_count, "null");
  742. analytics_set_data(&analytics_data.netdata_buildinfo, "null");
  743. analytics_set_data(&analytics_data.netdata_config_page_cache_size, "null");
  744. analytics_set_data(&analytics_data.netdata_config_multidb_disk_quota, "null");
  745. analytics_set_data(&analytics_data.netdata_config_https_enabled, "null");
  746. analytics_set_data(&analytics_data.netdata_config_web_enabled, "null");
  747. analytics_set_data(&analytics_data.netdata_config_release_channel, "null");
  748. analytics_set_data(&analytics_data.netdata_mirrored_host_count, "null");
  749. analytics_set_data(&analytics_data.netdata_mirrored_hosts_reachable, "null");
  750. analytics_set_data(&analytics_data.netdata_mirrored_hosts_unreachable, "null");
  751. analytics_set_data(&analytics_data.netdata_notification_methods, "null");
  752. analytics_set_data(&analytics_data.netdata_alarms_normal, "null");
  753. analytics_set_data(&analytics_data.netdata_alarms_warning, "null");
  754. analytics_set_data(&analytics_data.netdata_alarms_critical, "null");
  755. analytics_set_data(&analytics_data.netdata_charts_count, "null");
  756. analytics_set_data(&analytics_data.netdata_metrics_count, "null");
  757. analytics_set_data(&analytics_data.netdata_config_is_parent, "null");
  758. analytics_set_data(&analytics_data.netdata_config_hosts_available, "null");
  759. analytics_set_data(&analytics_data.netdata_host_cloud_available, "null");
  760. analytics_set_data(&analytics_data.netdata_host_aclk_implementation, "null");
  761. analytics_set_data(&analytics_data.netdata_host_aclk_available, "null");
  762. analytics_set_data(&analytics_data.netdata_host_aclk_protocol, "null");
  763. analytics_set_data(&analytics_data.netdata_host_agent_claimed, "null");
  764. analytics_set_data(&analytics_data.netdata_host_cloud_enabled, "null");
  765. analytics_set_data(&analytics_data.netdata_config_https_available, "null");
  766. analytics_set_data(&analytics_data.netdata_install_type, "null");
  767. analytics_set_data(&analytics_data.netdata_config_is_private_registry, "null");
  768. analytics_set_data(&analytics_data.netdata_config_use_private_registry, "null");
  769. analytics_set_data(&analytics_data.netdata_config_oom_score, "null");
  770. analytics_set_data(&analytics_data.netdata_prebuilt_distro, "null");
  771. analytics_data.prometheus_hits = 0;
  772. analytics_data.shell_hits = 0;
  773. analytics_data.json_hits = 0;
  774. analytics_data.dashboard_hits = 0;
  775. analytics_data.charts_count = 0;
  776. analytics_data.metrics_count = 0;
  777. analytics_data.exporting_enabled = false;
  778. char *default_port = appconfig_get(&netdata_config, CONFIG_SECTION_WEB, "default port", NULL);
  779. int clean = 0;
  780. if (!default_port) {
  781. default_port = strdupz("19999");
  782. clean = 1;
  783. }
  784. setenv("NETDATA_LISTEN_PORT", default_port, 1);
  785. if (clean)
  786. freez(default_port);
  787. // set the path we need
  788. char path[1024 + 1], *p = getenv("PATH");
  789. if (!p)
  790. p = "/bin:/usr/bin";
  791. snprintfz(path, 1024, "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
  792. setenv("PATH", config_get(CONFIG_SECTION_ENV_VARS, "PATH", path), 1);
  793. // python options
  794. p = getenv("PYTHONPATH");
  795. if (!p)
  796. p = "";
  797. setenv("PYTHONPATH", config_get(CONFIG_SECTION_ENV_VARS, "PYTHONPATH", p), 1);
  798. // disable buffering for python plugins
  799. setenv("PYTHONUNBUFFERED", "1", 1);
  800. // switch to standard locale for plugins
  801. setenv("LC_ALL", "C", 1);
  802. }
  803. void send_statistics(const char *action, const char *action_result, const char *action_data)
  804. {
  805. static char *as_script;
  806. if (netdata_anonymous_statistics_enabled == -1) {
  807. char *optout_file = mallocz(
  808. sizeof(char) *
  809. (strlen(netdata_configured_user_config_dir) + strlen(".opt-out-from-anonymous-statistics") + 2));
  810. sprintf(optout_file, "%s/%s", netdata_configured_user_config_dir, ".opt-out-from-anonymous-statistics");
  811. if (likely(access(optout_file, R_OK) != 0)) {
  812. as_script = mallocz(
  813. sizeof(char) *
  814. (strlen(netdata_configured_primary_plugins_dir) + strlen("anonymous-statistics.sh") + 2));
  815. sprintf(as_script, "%s/%s", netdata_configured_primary_plugins_dir, "anonymous-statistics.sh");
  816. if (unlikely(access(as_script, R_OK) != 0)) {
  817. netdata_anonymous_statistics_enabled = 0;
  818. netdata_log_info("Anonymous statistics script %s not found.", as_script);
  819. freez(as_script);
  820. } else {
  821. netdata_anonymous_statistics_enabled = 1;
  822. }
  823. } else {
  824. netdata_anonymous_statistics_enabled = 0;
  825. as_script = NULL;
  826. }
  827. freez(optout_file);
  828. }
  829. if (!netdata_anonymous_statistics_enabled)
  830. return;
  831. if (!action)
  832. return;
  833. if (!action_result)
  834. action_result = "";
  835. if (!action_data)
  836. action_data = "";
  837. char *command_to_run = mallocz(
  838. sizeof(char) * (strlen(action) + strlen(action_result) + strlen(action_data) + strlen(as_script) +
  839. analytics_data.data_length + (ANALYTICS_NO_OF_ITEMS * 3) + 15));
  840. pid_t command_pid;
  841. sprintf(
  842. command_to_run,
  843. "%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' ",
  844. as_script,
  845. action,
  846. action_result,
  847. action_data,
  848. analytics_data.netdata_config_stream_enabled,
  849. analytics_data.netdata_config_memory_mode,
  850. analytics_data.netdata_config_exporting_enabled,
  851. analytics_data.netdata_exporting_connectors,
  852. analytics_data.netdata_allmetrics_prometheus_used,
  853. analytics_data.netdata_allmetrics_shell_used,
  854. analytics_data.netdata_allmetrics_json_used,
  855. analytics_data.netdata_dashboard_used,
  856. analytics_data.netdata_collectors,
  857. analytics_data.netdata_collectors_count,
  858. analytics_data.netdata_buildinfo,
  859. analytics_data.netdata_config_page_cache_size,
  860. analytics_data.netdata_config_multidb_disk_quota,
  861. analytics_data.netdata_config_https_enabled,
  862. analytics_data.netdata_config_web_enabled,
  863. analytics_data.netdata_config_release_channel,
  864. analytics_data.netdata_mirrored_host_count,
  865. analytics_data.netdata_mirrored_hosts_reachable,
  866. analytics_data.netdata_mirrored_hosts_unreachable,
  867. analytics_data.netdata_notification_methods,
  868. analytics_data.netdata_alarms_normal,
  869. analytics_data.netdata_alarms_warning,
  870. analytics_data.netdata_alarms_critical,
  871. analytics_data.netdata_charts_count,
  872. analytics_data.netdata_metrics_count,
  873. analytics_data.netdata_config_is_parent,
  874. analytics_data.netdata_config_hosts_available,
  875. analytics_data.netdata_host_cloud_available,
  876. analytics_data.netdata_host_aclk_available,
  877. analytics_data.netdata_host_aclk_protocol,
  878. analytics_data.netdata_host_aclk_implementation,
  879. analytics_data.netdata_host_agent_claimed,
  880. analytics_data.netdata_host_cloud_enabled,
  881. analytics_data.netdata_config_https_available,
  882. analytics_data.netdata_install_type,
  883. analytics_data.netdata_config_is_private_registry,
  884. analytics_data.netdata_config_use_private_registry,
  885. analytics_data.netdata_config_oom_score,
  886. analytics_data.netdata_prebuilt_distro);
  887. netdata_log_info("%s '%s' '%s' '%s'", as_script, action, action_result, action_data);
  888. FILE *fp_child_input;
  889. FILE *fp_child_output = netdata_popen(command_to_run, &command_pid, &fp_child_input);
  890. if (fp_child_output) {
  891. char buffer[4 + 1];
  892. char *s = fgets(buffer, 4, fp_child_output);
  893. int exit_code = netdata_pclose(fp_child_input, fp_child_output, command_pid);
  894. if (exit_code)
  895. netdata_log_error("Execution of anonymous statistics script returned %d.", exit_code);
  896. if (s && strncmp(buffer, "200", 3))
  897. netdata_log_error("Execution of anonymous statistics script returned http code %s.", buffer);
  898. } else {
  899. netdata_log_error("Failed to run anonymous statistics script %s.", as_script);
  900. }
  901. freez(command_to_run);
  902. }