sqlite_aclk_node.c 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. now_realtime_timeval(&node_info.updated_at);
  22. RRDHOST *host = wc->host;
  23. char *host_version = NULL;
  24. if (host != localhost) {
  25. netdata_mutex_lock(&host->receiver_lock);
  26. host_version =
  27. strdupz(host->receiver && host->receiver->program_version ? host->receiver->program_version : "unknown");
  28. netdata_mutex_unlock(&host->receiver_lock);
  29. }
  30. node_info.data.name = host->hostname;
  31. node_info.data.os = (char *) host->os;
  32. node_info.data.os_name = host->system_info->host_os_name;
  33. node_info.data.os_version = host->system_info->host_os_version;
  34. node_info.data.kernel_name = host->system_info->kernel_name;
  35. node_info.data.kernel_version = host->system_info->kernel_version;
  36. node_info.data.architecture = host->system_info->architecture;
  37. node_info.data.cpus = host->system_info->host_cores ? str2uint32_t(host->system_info->host_cores) : 0;
  38. node_info.data.cpu_frequency = host->system_info->host_cpu_freq ? host->system_info->host_cpu_freq : "0";
  39. node_info.data.memory = host->system_info->host_ram_total ? host->system_info->host_ram_total : "0";
  40. node_info.data.disk_space = host->system_info->host_disk_space ? host->system_info->host_disk_space : "0";
  41. node_info.data.version = host_version ? host_version : VERSION;
  42. node_info.data.release_channel = "nightly";
  43. node_info.data.timezone = (char *) host->abbrev_timezone;
  44. node_info.data.virtualization_type = host->system_info->virtualization ? host->system_info->virtualization : "unknown";
  45. node_info.data.container_type = host->system_info->container ? host->system_info->container : "unknown";
  46. node_info.data.custom_info = config_get(CONFIG_SECTION_WEB, "custom dashboard_info.js", "");
  47. node_info.data.services = NULL; // char **
  48. node_info.data.service_count = 0;
  49. node_info.data.machine_guid = wc->host_guid;
  50. node_info.data.ml_info.ml_capable = host->system_info->ml_capable;
  51. node_info.data.ml_info.ml_enabled = host->system_info->ml_enabled;
  52. struct label_index *labels = &host->labels;
  53. netdata_rwlock_wrlock(&labels->labels_rwlock);
  54. node_info.data.host_labels_head = labels->head;
  55. aclk_update_node_info(&node_info);
  56. 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");
  57. netdata_rwlock_unlock(&labels->labels_rwlock);
  58. rrd_unlock();
  59. freez(node_info.claim_id);
  60. freez(host_version);
  61. #else
  62. UNUSED(wc);
  63. #endif
  64. return;
  65. }