buildinfo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include <stdio.h>
  3. #include "./config.h"
  4. #include "common.h"
  5. #include "buildinfo.h"
  6. // Optional features
  7. #ifdef ENABLE_ACLK
  8. #define FEAT_CLOUD 1
  9. #define FEAT_CLOUD_MSG ""
  10. #else
  11. #ifdef DISABLE_CLOUD
  12. #define FEAT_CLOUD 0
  13. #define FEAT_CLOUD_MSG "(by user request)"
  14. #else
  15. #define FEAT_CLOUD 0
  16. #define FEAT_CLOUD_MSG ""
  17. #endif
  18. #endif
  19. #ifdef ENABLE_DBENGINE
  20. #define FEAT_DBENGINE 1
  21. #else
  22. #define FEAT_DBENGINE 0
  23. #endif
  24. #if defined(HAVE_X509_VERIFY_PARAM_set1_host) && HAVE_X509_VERIFY_PARAM_set1_host == 1
  25. #define FEAT_TLS_HOST_VERIFY 1
  26. #else
  27. #define FEAT_TLS_HOST_VERIFY 0
  28. #endif
  29. #ifdef ENABLE_HTTPS
  30. #define FEAT_NATIVE_HTTPS 1
  31. #else
  32. #define FEAT_NATIVE_HTTPS 0
  33. #endif
  34. #ifdef ENABLE_ML
  35. #define FEAT_ML 1
  36. #else
  37. #define FEAT_ML 0
  38. #endif
  39. #ifdef ENABLE_COMPRESSION
  40. #define FEAT_STREAM_COMPRESSION 1
  41. #else
  42. #define FEAT_STREAM_COMPRESSION 0
  43. #endif //ENABLE_COMPRESSION
  44. // Optional libraries
  45. #ifdef HAVE_PROTOBUF
  46. #define FEAT_PROTOBUF 1
  47. #ifdef BUNDLED_PROTOBUF
  48. #define FEAT_PROTOBUF_BUNDLED " (bundled)"
  49. #else
  50. #define FEAT_PROTOBUF_BUNDLED " (system)"
  51. #endif
  52. #else
  53. #define FEAT_PROTOBUF 0
  54. #define FEAT_PROTOBUF_BUNDLED ""
  55. #endif
  56. #ifdef ENABLE_JSONC
  57. #define FEAT_JSONC 1
  58. #else
  59. #define FEAT_JSONC 0
  60. #endif
  61. #ifdef ENABLE_JEMALLOC
  62. #define FEAT_JEMALLOC 1
  63. #else
  64. #define FEAT_JEMALLOC 0
  65. #endif
  66. #ifdef ENABLE_TCMALLOC
  67. #define FEAT_TCMALLOC 1
  68. #else
  69. #define FEAT_TCMALLOC 0
  70. #endif
  71. #ifdef HAVE_CAPABILITY
  72. #define FEAT_LIBCAP 1
  73. #else
  74. #define FEAT_LIBCAP 0
  75. #endif
  76. #ifdef NETDATA_WITH_ZLIB
  77. #define FEAT_ZLIB 1
  78. #else
  79. #define FEAT_ZLIB 0
  80. #endif
  81. #ifdef STORAGE_WITH_MATH
  82. #define FEAT_LIBM 1
  83. #else
  84. #define FEAT_LIBM 0
  85. #endif
  86. #ifdef HAVE_CRYPTO
  87. #define FEAT_CRYPTO 1
  88. #else
  89. #define FEAT_CRYPTO 0
  90. #endif
  91. // Optional plugins
  92. #ifdef ENABLE_APPS_PLUGIN
  93. #define FEAT_APPS_PLUGIN 1
  94. #else
  95. #define FEAT_APPS_PLUGIN 0
  96. #endif
  97. #ifdef HAVE_FREEIPMI
  98. #define FEAT_IPMI 1
  99. #else
  100. #define FEAT_IPMI 0
  101. #endif
  102. #ifdef HAVE_CUPS
  103. #define FEAT_CUPS 1
  104. #else
  105. #define FEAT_CUPS 0
  106. #endif
  107. #ifdef HAVE_NFACCT
  108. #define FEAT_NFACCT 1
  109. #else
  110. #define FEAT_NFACCT 0
  111. #endif
  112. #ifdef HAVE_LIBXENSTAT
  113. #define FEAT_XEN 1
  114. #else
  115. #define FEAT_XEN 0
  116. #endif
  117. #ifdef HAVE_XENSTAT_VBD_ERROR
  118. #define FEAT_XEN_VBD_ERROR 1
  119. #else
  120. #define FEAT_XEN_VBD_ERROR 0
  121. #endif
  122. #ifdef HAVE_LIBBPF
  123. #define FEAT_EBPF 1
  124. #else
  125. #define FEAT_EBPF 0
  126. #endif
  127. #ifdef HAVE_SETNS
  128. #define FEAT_CGROUP_NET 1
  129. #else
  130. #define FEAT_CGROUP_NET 0
  131. #endif
  132. #ifdef ENABLE_PERF_PLUGIN
  133. #define FEAT_PERF 1
  134. #else
  135. #define FEAT_PERF 0
  136. #endif
  137. #ifdef ENABLE_SLABINFO
  138. #define FEAT_SLABINFO 1
  139. #else
  140. #define FEAT_SLABINFO 0
  141. #endif
  142. // Optional Exporters
  143. #ifdef HAVE_KINESIS
  144. #define FEAT_KINESIS 1
  145. #else
  146. #define FEAT_KINESIS 0
  147. #endif
  148. #ifdef ENABLE_EXPORTING_PUBSUB
  149. #define FEAT_PUBSUB 1
  150. #else
  151. #define FEAT_PUBSUB 0
  152. #endif
  153. #ifdef HAVE_MONGOC
  154. #define FEAT_MONGO 1
  155. #else
  156. #define FEAT_MONGO 0
  157. #endif
  158. #ifdef ENABLE_PROMETHEUS_REMOTE_WRITE
  159. #define FEAT_REMOTE_WRITE 1
  160. #else
  161. #define FEAT_REMOTE_WRITE 0
  162. #endif
  163. #define FEAT_YES_NO(x) ((x) ? "YES" : "NO")
  164. char *get_value_from_key(char *buffer, char *key) {
  165. char *s = NULL, *t = NULL;
  166. s = t = buffer + strlen(key) + 2;
  167. if (s) {
  168. while (*s == '\'')
  169. s++;
  170. while (*++t != '\0');
  171. while (--t > s && *t == '\'')
  172. *t = '\0';
  173. }
  174. return s;
  175. }
  176. void get_install_type(char **install_type, char **prebuilt_arch, char **prebuilt_dist) {
  177. char *install_type_filename;
  178. int install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
  179. install_type_filename = mallocz(sizeof(char) * install_type_filename_len);
  180. snprintfz(install_type_filename, install_type_filename_len - 1, "%s/%s", netdata_configured_user_config_dir, ".install-type");
  181. FILE *fp = fopen(install_type_filename, "r");
  182. if (fp) {
  183. char *s, buf[256 + 1];
  184. size_t len = 0;
  185. while ((s = fgets_trim_len(buf, 256, fp, &len))) {
  186. if (!strncmp(buf, "INSTALL_TYPE='", 14))
  187. *install_type = strdupz((char *)get_value_from_key(buf, "INSTALL_TYPE"));
  188. else if (!strncmp(buf, "PREBUILT_ARCH='", 15))
  189. *prebuilt_arch = strdupz((char *)get_value_from_key(buf, "PREBUILT_ARCH"));
  190. else if (!strncmp(buf, "PREBUILT_DISTRO='", 17))
  191. *prebuilt_dist = strdupz((char *)get_value_from_key(buf, "PREBUILT_DISTRO"));
  192. }
  193. fclose(fp);
  194. }
  195. freez(install_type_filename);
  196. }
  197. void print_build_info(void) {
  198. char *install_type = NULL;
  199. char *prebuilt_arch = NULL;
  200. char *prebuilt_distro = NULL;
  201. get_install_type(&install_type, &prebuilt_arch, &prebuilt_distro);
  202. printf("Configure options: %s\n", CONFIGURE_COMMAND);
  203. if (install_type == NULL) {
  204. printf("Install type: unknown\n");
  205. } else {
  206. printf("Install type: %s\n", install_type);
  207. }
  208. if (prebuilt_arch != NULL) {
  209. printf(" Binary architecture: %s\n", prebuilt_arch);
  210. }
  211. if (prebuilt_distro != NULL) {
  212. printf(" Packaging distro: %s\n", prebuilt_distro);
  213. }
  214. freez(install_type);
  215. freez(prebuilt_arch);
  216. freez(prebuilt_distro);
  217. printf("Features:\n");
  218. printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
  219. printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
  220. printf(" Netdata Cloud: %s %s\n", FEAT_YES_NO(FEAT_CLOUD), FEAT_CLOUD_MSG);
  221. printf(" ACLK Next Generation: %s\n", FEAT_YES_NO(FEAT_CLOUD));
  222. printf(" ACLK-NG New Cloud Protocol: %s\n", FEAT_YES_NO(1));
  223. printf(" ACLK Legacy: %s\n", FEAT_YES_NO(0));
  224. printf(" TLS Host Verification: %s\n", FEAT_YES_NO(FEAT_TLS_HOST_VERIFY));
  225. printf(" Machine Learning: %s\n", FEAT_YES_NO(FEAT_ML));
  226. printf(" Stream Compression: %s\n", FEAT_YES_NO(FEAT_STREAM_COMPRESSION));
  227. printf("Libraries:\n");
  228. printf(" protobuf: %s%s\n", FEAT_YES_NO(FEAT_PROTOBUF), FEAT_PROTOBUF_BUNDLED);
  229. printf(" jemalloc: %s\n", FEAT_YES_NO(FEAT_JEMALLOC));
  230. printf(" JSON-C: %s\n", FEAT_YES_NO(FEAT_JSONC));
  231. printf(" libcap: %s\n", FEAT_YES_NO(FEAT_LIBCAP));
  232. printf(" libcrypto: %s\n", FEAT_YES_NO(FEAT_CRYPTO));
  233. printf(" libm: %s\n", FEAT_YES_NO(FEAT_LIBM));
  234. printf(" tcalloc: %s\n", FEAT_YES_NO(FEAT_TCMALLOC));
  235. printf(" zlib: %s\n", FEAT_YES_NO(FEAT_ZLIB));
  236. printf("Plugins:\n");
  237. printf(" apps: %s\n", FEAT_YES_NO(FEAT_APPS_PLUGIN));
  238. printf(" cgroup Network Tracking: %s\n", FEAT_YES_NO(FEAT_CGROUP_NET));
  239. printf(" CUPS: %s\n", FEAT_YES_NO(FEAT_CUPS));
  240. printf(" EBPF: %s\n", FEAT_YES_NO(FEAT_EBPF));
  241. printf(" IPMI: %s\n", FEAT_YES_NO(FEAT_IPMI));
  242. printf(" NFACCT: %s\n", FEAT_YES_NO(FEAT_NFACCT));
  243. printf(" perf: %s\n", FEAT_YES_NO(FEAT_PERF));
  244. printf(" slabinfo: %s\n", FEAT_YES_NO(FEAT_SLABINFO));
  245. printf(" Xen: %s\n", FEAT_YES_NO(FEAT_XEN));
  246. printf(" Xen VBD Error Tracking: %s\n", FEAT_YES_NO(FEAT_XEN_VBD_ERROR));
  247. printf("Exporters:\n");
  248. printf(" AWS Kinesis: %s\n", FEAT_YES_NO(FEAT_KINESIS));
  249. printf(" GCP PubSub: %s\n", FEAT_YES_NO(FEAT_PUBSUB));
  250. printf(" MongoDB: %s\n", FEAT_YES_NO(FEAT_MONGO));
  251. printf(" Prometheus Remote Write: %s\n", FEAT_YES_NO(FEAT_REMOTE_WRITE));
  252. };
  253. #define FEAT_JSON_BOOL(x) ((x) ? "true" : "false")
  254. // This intentionally does not use JSON-C so it works even if JSON-C is not present
  255. // This is used for anonymous statistics reporting, so it intentionally
  256. // does not include the configure options, which would be very easy to use
  257. // for tracking custom builds (and complicate outputting valid JSON).
  258. void print_build_info_json(void) {
  259. printf("{\n");
  260. printf(" \"features\": {\n");
  261. printf(" \"dbengine\": %s,\n", FEAT_JSON_BOOL(FEAT_DBENGINE));
  262. printf(" \"native-https\": %s,\n", FEAT_JSON_BOOL(FEAT_NATIVE_HTTPS));
  263. printf(" \"cloud\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
  264. #ifdef DISABLE_CLOUD
  265. printf(" \"cloud-disabled\": true,\n");
  266. #else
  267. printf(" \"cloud-disabled\": false,\n");
  268. #endif
  269. printf(" \"aclk-ng\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
  270. printf(" \"aclk-ng-new-cloud-proto\": %s,\n", FEAT_JSON_BOOL(1));
  271. printf(" \"aclk-legacy\": %s,\n", FEAT_JSON_BOOL(0));
  272. printf(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
  273. printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML));
  274. printf(" \"stream-compression\": %s\n", FEAT_JSON_BOOL(FEAT_STREAM_COMPRESSION));
  275. printf(" },\n");
  276. printf(" \"libs\": {\n");
  277. printf(" \"protobuf\": %s,\n", FEAT_JSON_BOOL(FEAT_PROTOBUF));
  278. printf(" \"protobuf-source\": \"%s\",\n", FEAT_PROTOBUF_BUNDLED);
  279. printf(" \"jemalloc\": %s,\n", FEAT_JSON_BOOL(FEAT_JEMALLOC));
  280. printf(" \"jsonc\": %s,\n", FEAT_JSON_BOOL(FEAT_JSONC));
  281. printf(" \"libcap\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBCAP));
  282. printf(" \"libcrypto\": %s,\n", FEAT_JSON_BOOL(FEAT_CRYPTO));
  283. printf(" \"libm\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBM));
  284. printf(" \"tcmalloc\": %s,\n", FEAT_JSON_BOOL(FEAT_TCMALLOC));
  285. printf(" \"zlib\": %s\n", FEAT_JSON_BOOL(FEAT_ZLIB));
  286. printf(" },\n");
  287. printf(" \"plugins\": {\n");
  288. printf(" \"apps\": %s,\n", FEAT_JSON_BOOL(FEAT_APPS_PLUGIN));
  289. printf(" \"cgroup-net\": %s,\n", FEAT_JSON_BOOL(FEAT_CGROUP_NET));
  290. printf(" \"cups\": %s,\n", FEAT_JSON_BOOL(FEAT_CUPS));
  291. printf(" \"ebpf\": %s,\n", FEAT_JSON_BOOL(FEAT_EBPF));
  292. printf(" \"ipmi\": %s,\n", FEAT_JSON_BOOL(FEAT_IPMI));
  293. printf(" \"nfacct\": %s,\n", FEAT_JSON_BOOL(FEAT_NFACCT));
  294. printf(" \"perf\": %s,\n", FEAT_JSON_BOOL(FEAT_PERF));
  295. printf(" \"slabinfo\": %s,\n", FEAT_JSON_BOOL(FEAT_SLABINFO));
  296. printf(" \"xen\": %s,\n", FEAT_JSON_BOOL(FEAT_XEN));
  297. printf(" \"xen-vbd-error\": %s\n", FEAT_JSON_BOOL(FEAT_XEN_VBD_ERROR));
  298. printf(" },\n");
  299. printf(" \"exporters\": {\n");
  300. printf(" \"kinesis\": %s,\n", FEAT_JSON_BOOL(FEAT_KINESIS));
  301. printf(" \"pubsub\": %s,\n", FEAT_JSON_BOOL(FEAT_PUBSUB));
  302. printf(" \"mongodb\": %s,\n", FEAT_JSON_BOOL(FEAT_MONGO));
  303. printf(" \"prom-remote-write\": %s\n", FEAT_JSON_BOOL(FEAT_REMOTE_WRITE));
  304. printf(" }\n");
  305. printf("}\n");
  306. };
  307. #define add_to_bi(buffer, str) \
  308. { if(first) { \
  309. buffer_strcat (b, str); \
  310. first = 0; \
  311. } else \
  312. buffer_strcat (b, "|" str); }
  313. void analytics_build_info(BUFFER *b) {
  314. int first = 1;
  315. #ifdef ENABLE_DBENGINE
  316. add_to_bi(b, "dbengine");
  317. #endif
  318. #ifdef ENABLE_HTTPS
  319. add_to_bi(b, "Native HTTPS");
  320. #endif
  321. #ifdef ENABLE_ACLK
  322. add_to_bi(b, "Netdata Cloud|ACLK Next Generation|New Cloud Protocol Support");
  323. #endif
  324. #if (FEAT_TLS_HOST_VERIFY!=0)
  325. add_to_bi(b, "TLS Host Verification");
  326. #endif
  327. #ifdef ENABLE_ML
  328. add_to_bi(b, "Machine Learning");
  329. #endif
  330. #ifdef ENABLE_COMPRESSION
  331. add_to_bi(b, "Stream Compression");
  332. #endif
  333. #ifdef HAVE_PROTOBUF
  334. add_to_bi(b, "protobuf");
  335. #endif
  336. #ifdef ENABLE_JEMALLOC
  337. add_to_bi(b, "jemalloc");
  338. #endif
  339. #ifdef ENABLE_JSONC
  340. add_to_bi(b, "JSON-C");
  341. #endif
  342. #ifdef HAVE_CAPABILITY
  343. add_to_bi(b, "libcap");
  344. #endif
  345. #ifdef HAVE_CRYPTO
  346. add_to_bi(b, "libcrypto");
  347. #endif
  348. #ifdef STORAGE_WITH_MATH
  349. add_to_bi(b, "libm");
  350. #endif
  351. #ifdef ENABLE_TCMALLOC
  352. add_to_bi(b, "tcalloc");
  353. #endif
  354. #ifdef NETDATA_WITH_ZLIB
  355. add_to_bi(b, "zlib");
  356. #endif
  357. #ifdef ENABLE_APPS_PLUGIN
  358. add_to_bi(b, "apps");
  359. #endif
  360. #ifdef HAVE_SETNS
  361. add_to_bi(b, "cgroup Network Tracking");
  362. #endif
  363. #ifdef HAVE_CUPS
  364. add_to_bi(b, "CUPS");
  365. #endif
  366. #ifdef HAVE_LIBBPF
  367. add_to_bi(b, "EBPF");
  368. #endif
  369. #ifdef HAVE_FREEIPMI
  370. add_to_bi(b, "IPMI");
  371. #endif
  372. #ifdef HAVE_NFACCT
  373. add_to_bi(b, "NFACCT");
  374. #endif
  375. #ifdef ENABLE_PERF_PLUGIN
  376. add_to_bi(b, "perf");
  377. #endif
  378. #ifdef ENABLE_SLABINFO
  379. add_to_bi(b, "slabinfo");
  380. #endif
  381. #ifdef HAVE_LIBXENSTAT
  382. add_to_bi(b, "Xen");
  383. #endif
  384. #ifdef HAVE_XENSTAT_VBD_ERROR
  385. add_to_bi(b, "Xen VBD Error Tracking");
  386. #endif
  387. #ifdef HAVE_KINESIS
  388. add_to_bi(b, "AWS Kinesis");
  389. #endif
  390. #ifdef ENABLE_EXPORTING_PUBSUB
  391. add_to_bi(b, "GCP PubSub");
  392. #endif
  393. #ifdef HAVE_MONGOC
  394. add_to_bi(b, "MongoDB");
  395. #endif
  396. #ifdef ENABLE_PROMETHEUS_REMOTE_WRITE
  397. add_to_bi(b, "Prometheus Remote Write");
  398. #endif
  399. }