sqlite_aclk_node.c 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "sqlite_functions.h"
  3. #include "sqlite_aclk_node.h"
  4. #ifdef ENABLE_NEW_CLOUD_PROTOCOL
  5. #include "../../aclk/aclk_charts_api.h"
  6. #endif
  7. void sql_build_node_info(struct aclk_database_worker_config *wc, struct aclk_database_cmd cmd)
  8. {
  9. UNUSED(cmd);
  10. #ifdef ENABLE_NEW_CLOUD_PROTOCOL
  11. struct update_node_info node_info;
  12. if (!wc->host)
  13. return;
  14. rrd_rdlock();
  15. node_info.node_id = wc->node_id;
  16. node_info.claim_id = is_agent_claimed();
  17. node_info.machine_guid = wc->host_guid;
  18. node_info.child = (wc->host != localhost);
  19. node_info.ml_info.ml_capable = ml_capable(localhost);
  20. node_info.ml_info.ml_enabled = ml_enabled(wc->host);
  21. struct capability instance_caps[] = {
  22. { .name = "proto", .version = 1, .enabled = 1 },
  23. { .name = "ml", .version = ml_capable(localhost), .enabled = ml_enabled(wc->host) },
  24. { .name = "mc", .version = enable_metric_correlations ? metric_correlations_version : 0, .enabled = enable_metric_correlations },
  25. { .name = NULL, .version = 0, .enabled = 0 }
  26. };
  27. node_info.node_instance_capabilities = instance_caps;
  28. now_realtime_timeval(&node_info.updated_at);
  29. RRDHOST *host = wc->host;
  30. char *host_version = NULL;
  31. if (host != localhost) {
  32. netdata_mutex_lock(&host->receiver_lock);
  33. host_version =
  34. strdupz(host->receiver && host->receiver->program_version ? host->receiver->program_version : "unknown");
  35. netdata_mutex_unlock(&host->receiver_lock);
  36. }
  37. node_info.data.name = host->hostname;
  38. node_info.data.os = (char *) host->os;
  39. node_info.data.os_name = host->system_info->host_os_name;
  40. node_info.data.os_version = host->system_info->host_os_version;
  41. node_info.data.kernel_name = host->system_info->kernel_name;
  42. node_info.data.kernel_version = host->system_info->kernel_version;
  43. node_info.data.architecture = host->system_info->architecture;
  44. node_info.data.cpus = host->system_info->host_cores ? str2uint32_t(host->system_info->host_cores) : 0;
  45. node_info.data.cpu_frequency = host->system_info->host_cpu_freq ? host->system_info->host_cpu_freq : "0";
  46. node_info.data.memory = host->system_info->host_ram_total ? host->system_info->host_ram_total : "0";
  47. node_info.data.disk_space = host->system_info->host_disk_space ? host->system_info->host_disk_space : "0";
  48. node_info.data.version = host_version ? host_version : VERSION;
  49. node_info.data.release_channel = (char *) get_release_channel();
  50. node_info.data.timezone = (char *) host->abbrev_timezone;
  51. node_info.data.virtualization_type = host->system_info->virtualization ? host->system_info->virtualization : "unknown";
  52. node_info.data.container_type = host->system_info->container ? host->system_info->container : "unknown";
  53. node_info.data.custom_info = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
  54. node_info.data.services = NULL; // char **
  55. node_info.data.service_count = 0;
  56. node_info.data.machine_guid = wc->host_guid;
  57. struct capability node_caps[] = {
  58. { .name = "ml", .version = host->system_info->ml_capable, .enabled = host->system_info->ml_enabled },
  59. { .name = "mc", .version = host->system_info->mc_version ? host->system_info->mc_version : 0, .enabled = host->system_info->mc_version ? 1 : 0 },
  60. { .name = NULL, .version = 0, .enabled = 0 }
  61. };
  62. node_info.node_capabilities = node_caps;
  63. node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
  64. node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled;
  65. struct label_index *labels = &host->labels;
  66. netdata_rwlock_rdlock(&labels->labels_rwlock);
  67. node_info.data.host_labels_head = labels->head;
  68. aclk_update_node_info(&node_info);
  69. 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");
  70. netdata_rwlock_unlock(&labels->labels_rwlock);
  71. rrd_unlock();
  72. freez(node_info.claim_id);
  73. freez(host_version);
  74. #else
  75. UNUSED(wc);
  76. #endif
  77. return;
  78. }