sqlite_aclk_node.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "sqlite_functions.h"
  3. #include "sqlite_aclk_node.h"
  4. #ifdef ENABLE_ACLK
  5. #include "../../aclk/aclk_charts_api.h"
  6. #endif
  7. #ifdef ENABLE_ACLK
  8. DICTIONARY *collectors_from_charts(RRDHOST *host, DICTIONARY *dict) {
  9. RRDSET *st;
  10. char name[500];
  11. rrdhost_rdlock(host);
  12. rrdset_foreach_read(st, host) {
  13. if (rrdset_is_available_for_viewers(st)) {
  14. struct collector_info col = {
  15. .plugin = st->plugin_name ? st->plugin_name : "",
  16. .module = st->module_name ? st->module_name : ""
  17. };
  18. snprintfz(name, 499, "%s:%s", col.plugin, col.module);
  19. dictionary_set(dict, name, &col, sizeof(struct collector_info));
  20. }
  21. }
  22. rrdhost_unlock(host);
  23. return dict;
  24. }
  25. #endif
  26. void sql_build_node_collectors(struct aclk_database_worker_config *wc)
  27. {
  28. #ifdef ENABLE_ACLK
  29. if (!wc->host)
  30. return;
  31. struct update_node_collectors upd_node_collectors;
  32. DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED);
  33. upd_node_collectors.node_id = wc->node_id;
  34. upd_node_collectors.claim_id = get_agent_claimid();
  35. upd_node_collectors.node_collectors = collectors_from_charts(wc->host, dict);
  36. aclk_update_node_collectors(&upd_node_collectors);
  37. dictionary_destroy(dict);
  38. freez(upd_node_collectors.claim_id);
  39. log_access("ACLK RES [%s (%s)]: NODE COLLECTORS SENT", wc->node_id, wc->host->hostname);
  40. #else
  41. UNUSED(wc);
  42. #endif
  43. return;
  44. }
  45. void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd)
  46. {
  47. UNUSED(cmd);
  48. #ifdef ENABLE_ACLK
  49. struct update_node_info node_info;
  50. if (!wc->host) {
  51. wc->node_info_send = 1;
  52. return;
  53. }
  54. rrd_rdlock();
  55. node_info.node_id = wc->node_id;
  56. node_info.claim_id = get_agent_claimid();
  57. node_info.machine_guid = wc->host_guid;
  58. node_info.child = (wc->host != localhost);
  59. node_info.ml_info.ml_capable = ml_capable(localhost);
  60. node_info.ml_info.ml_enabled = ml_enabled(wc->host);
  61. struct capability instance_caps[] = {
  62. { .name = "proto", .version = 1, .enabled = 1 },
  63. { .name = "ml", .version = ml_capable(localhost), .enabled = ml_enabled(wc->host) },
  64. { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
  65. { .name = "ctx", .version = 1, .enabled = rrdcontext_enabled},
  66. { .name = NULL, .version = 0, .enabled = 0 }
  67. };
  68. node_info.node_instance_capabilities = instance_caps;
  69. now_realtime_timeval(&node_info.updated_at);
  70. RRDHOST *host = wc->host;
  71. char *host_version = NULL;
  72. if (host != localhost) {
  73. netdata_mutex_lock(&host->receiver_lock);
  74. host_version =
  75. strdupz(host->receiver && host->receiver->program_version ? host->receiver->program_version : "unknown");
  76. netdata_mutex_unlock(&host->receiver_lock);
  77. }
  78. node_info.data.name = host->hostname;
  79. node_info.data.os = (char *) host->os;
  80. node_info.data.os_name = host->system_info->host_os_name;
  81. node_info.data.os_version = host->system_info->host_os_version;
  82. node_info.data.kernel_name = host->system_info->kernel_name;
  83. node_info.data.kernel_version = host->system_info->kernel_version;
  84. node_info.data.architecture = host->system_info->architecture;
  85. node_info.data.cpus = host->system_info->host_cores ? str2uint32_t(host->system_info->host_cores) : 0;
  86. node_info.data.cpu_frequency = host->system_info->host_cpu_freq ? host->system_info->host_cpu_freq : "0";
  87. node_info.data.memory = host->system_info->host_ram_total ? host->system_info->host_ram_total : "0";
  88. node_info.data.disk_space = host->system_info->host_disk_space ? host->system_info->host_disk_space : "0";
  89. node_info.data.version = host_version ? host_version : VERSION;
  90. node_info.data.release_channel = (char *) get_release_channel();
  91. node_info.data.timezone = (char *) host->abbrev_timezone;
  92. node_info.data.virtualization_type = host->system_info->virtualization ? host->system_info->virtualization : "unknown";
  93. node_info.data.container_type = host->system_info->container ? host->system_info->container : "unknown";
  94. node_info.data.custom_info = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
  95. node_info.data.machine_guid = wc->host_guid;
  96. struct capability node_caps[] = {
  97. { .name = "ml", .version = host->system_info->ml_capable, .enabled = host->system_info->ml_enabled },
  98. { .name = "mc", .version = host->system_info->mc_version ? host->system_info->mc_version : 0, .enabled = host->system_info->mc_version ? 1 : 0 },
  99. { .name = NULL, .version = 0, .enabled = 0 }
  100. };
  101. node_info.node_capabilities = node_caps;
  102. node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
  103. node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled;
  104. node_info.data.host_labels_ptr = host->host_labels;
  105. aclk_update_node_info(&node_info);
  106. log_access("ACLK RES [%s (%s)]: NODE INFO SENT for guid [%s] (%s)", wc->node_id, wc->host->hostname, wc->host_guid, wc->host == localhost ? "parent" : "child");
  107. rrd_unlock();
  108. freez(node_info.claim_id);
  109. freez(host_version);
  110. wc->node_collectors_send = now_realtime_sec();
  111. #else
  112. UNUSED(wc);
  113. #endif
  114. return;
  115. }