sqlite_aclk_node.c 4.9 KB

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