common.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "common.h"
  3. char *netdata_configured_hostname = NULL;
  4. char *netdata_configured_user_config_dir = CONFIG_DIR;
  5. char *netdata_configured_stock_config_dir = LIBCONFIG_DIR;
  6. char *netdata_configured_log_dir = LOG_DIR;
  7. char *netdata_configured_primary_plugins_dir = NULL;
  8. char *netdata_configured_web_dir = WEB_DIR;
  9. char *netdata_configured_cache_dir = CACHE_DIR;
  10. char *netdata_configured_varlib_dir = VARLIB_DIR;
  11. char *netdata_configured_lock_dir = NULL;
  12. char *netdata_configured_home_dir = VARLIB_DIR;
  13. char *netdata_configured_host_prefix = NULL;
  14. char *netdata_configured_timezone = NULL;
  15. char *netdata_configured_abbrev_timezone = NULL;
  16. int32_t netdata_configured_utc_offset = 0;
  17. bool netdata_ready = false;
  18. #if defined( DISABLE_CLOUD ) || !defined( ENABLE_ACLK )
  19. bool netdata_cloud_enabled = false;
  20. #else
  21. bool netdata_cloud_enabled = true;
  22. #endif
  23. long get_netdata_cpus(void) {
  24. static long processors = 0;
  25. if(processors)
  26. return processors;
  27. long cores_proc_stat = get_system_cpus_with_cache(false, true);
  28. long cores_cpuset_v1 = (long)read_cpuset_cpus("/sys/fs/cgroup/cpuset/cpuset.cpus", cores_proc_stat);
  29. long cores_cpuset_v2 = (long)read_cpuset_cpus("/sys/fs/cgroup/cpuset.cpus", cores_proc_stat);
  30. if(cores_cpuset_v2)
  31. processors = cores_cpuset_v2;
  32. else if(cores_cpuset_v1)
  33. processors = cores_cpuset_v1;
  34. else
  35. processors = cores_proc_stat;
  36. long cores_user_configured = config_get_number(CONFIG_SECTION_GLOBAL, "cpu cores", processors);
  37. errno = 0;
  38. internal_error(true,
  39. "System CPUs: %ld, ("
  40. "system: %ld, cgroups cpuset v1: %ld, cgroups cpuset v2: %ld, netdata.conf: %ld"
  41. ")"
  42. , processors
  43. , cores_proc_stat
  44. , cores_cpuset_v1
  45. , cores_cpuset_v2
  46. , cores_user_configured
  47. );
  48. processors = cores_user_configured;
  49. return processors;
  50. }
  51. const char *cloud_status_to_string(CLOUD_STATUS status) {
  52. switch(status) {
  53. default:
  54. case CLOUD_STATUS_DISABLED:
  55. return "disabled";
  56. case CLOUD_STATUS_BANNED:
  57. return "banned";
  58. case CLOUD_STATUS_OFFLINE:
  59. return "offline";
  60. case CLOUD_STATUS_ONLINE:
  61. return "online";
  62. }
  63. }
  64. CLOUD_STATUS cloud_status(void) {
  65. #ifdef ENABLE_ACLK
  66. if(aclk_disable_runtime)
  67. return CLOUD_STATUS_BANNED;
  68. if(aclk_connected)
  69. return CLOUD_STATUS_ONLINE;
  70. if(netdata_cloud_enabled)
  71. return CLOUD_STATUS_OFFLINE;
  72. return CLOUD_STATUS_DISABLED;
  73. #else
  74. return CLOUD_STATUS_DISABLED;
  75. #endif
  76. }
  77. time_t cloud_last_change(void) {
  78. #ifdef ENABLE_ACLK
  79. time_t ret = MAX(last_conn_time_mqtt, last_disconnect_time);
  80. if(!ret) ret = netdata_start_time;
  81. return ret;
  82. #else
  83. return netdata_start_time;
  84. #endif
  85. }
  86. time_t cloud_next_connection_attempt(void) {
  87. #ifdef ENABLE_ACLK
  88. return next_connection_attempt;
  89. #else
  90. return 0;
  91. #endif
  92. }
  93. size_t cloud_connection_id(void) {
  94. #ifdef ENABLE_ACLK
  95. return aclk_connection_counter;
  96. #else
  97. return 0;
  98. #endif
  99. }
  100. const char *cloud_offline_reason() {
  101. #ifdef ENABLE_ACLK
  102. if(!netdata_cloud_enabled)
  103. return "disabled";
  104. if(aclk_disable_runtime)
  105. return "banned";
  106. return aclk_status_to_string();
  107. #else
  108. return "disabled";
  109. #endif
  110. }
  111. const char *cloud_base_url() {
  112. #ifdef ENABLE_ACLK
  113. return aclk_cloud_base_url;
  114. #else
  115. return NULL;
  116. #endif
  117. }