buildinfo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. #ifdef NETDATA_TRACE_ALLOCATIONS
  165. #define FEAT_TRACE_ALLOC 1
  166. #else
  167. #define FEAT_TRACE_ALLOC 0
  168. #endif
  169. char *get_value_from_key(char *buffer, char *key) {
  170. char *s = NULL, *t = NULL;
  171. s = t = buffer + strlen(key) + 2;
  172. if (s) {
  173. while (*s == '\'')
  174. s++;
  175. while (*++t != '\0');
  176. while (--t > s && *t == '\'')
  177. *t = '\0';
  178. }
  179. return s;
  180. }
  181. void get_install_type(char **install_type, char **prebuilt_arch, char **prebuilt_dist) {
  182. char *install_type_filename;
  183. int install_type_filename_len = (strlen(netdata_configured_user_config_dir) + strlen(".install-type") + 3);
  184. install_type_filename = mallocz(sizeof(char) * install_type_filename_len);
  185. snprintfz(install_type_filename, install_type_filename_len - 1, "%s/%s", netdata_configured_user_config_dir, ".install-type");
  186. FILE *fp = fopen(install_type_filename, "r");
  187. if (fp) {
  188. char *s, buf[256 + 1];
  189. size_t len = 0;
  190. while ((s = fgets_trim_len(buf, 256, fp, &len))) {
  191. if (!strncmp(buf, "INSTALL_TYPE='", 14))
  192. *install_type = strdupz((char *)get_value_from_key(buf, "INSTALL_TYPE"));
  193. else if (!strncmp(buf, "PREBUILT_ARCH='", 15))
  194. *prebuilt_arch = strdupz((char *)get_value_from_key(buf, "PREBUILT_ARCH"));
  195. else if (!strncmp(buf, "PREBUILT_DISTRO='", 17))
  196. *prebuilt_dist = strdupz((char *)get_value_from_key(buf, "PREBUILT_DISTRO"));
  197. }
  198. fclose(fp);
  199. }
  200. freez(install_type_filename);
  201. }
  202. void print_build_info(void) {
  203. char *install_type = NULL;
  204. char *prebuilt_arch = NULL;
  205. char *prebuilt_distro = NULL;
  206. get_install_type(&install_type, &prebuilt_arch, &prebuilt_distro);
  207. printf("Configure options: %s\n", CONFIGURE_COMMAND);
  208. if (install_type == NULL) {
  209. printf("Install type: unknown\n");
  210. } else {
  211. printf("Install type: %s\n", install_type);
  212. }
  213. if (prebuilt_arch != NULL) {
  214. printf(" Binary architecture: %s\n", prebuilt_arch);
  215. }
  216. if (prebuilt_distro != NULL) {
  217. printf(" Packaging distro: %s\n", prebuilt_distro);
  218. }
  219. freez(install_type);
  220. freez(prebuilt_arch);
  221. freez(prebuilt_distro);
  222. printf("Features:\n");
  223. printf(" dbengine: %s\n", FEAT_YES_NO(FEAT_DBENGINE));
  224. printf(" Native HTTPS: %s\n", FEAT_YES_NO(FEAT_NATIVE_HTTPS));
  225. printf(" Netdata Cloud: %s %s\n", FEAT_YES_NO(FEAT_CLOUD), FEAT_CLOUD_MSG);
  226. printf(" ACLK: %s\n", FEAT_YES_NO(FEAT_CLOUD));
  227. printf(" TLS Host Verification: %s\n", FEAT_YES_NO(FEAT_TLS_HOST_VERIFY));
  228. printf(" Machine Learning: %s\n", FEAT_YES_NO(FEAT_ML));
  229. printf(" Stream Compression: %s\n", FEAT_YES_NO(FEAT_STREAM_COMPRESSION));
  230. printf("Libraries:\n");
  231. printf(" protobuf: %s%s\n", FEAT_YES_NO(FEAT_PROTOBUF), FEAT_PROTOBUF_BUNDLED);
  232. printf(" jemalloc: %s\n", FEAT_YES_NO(FEAT_JEMALLOC));
  233. printf(" JSON-C: %s\n", FEAT_YES_NO(FEAT_JSONC));
  234. printf(" libcap: %s\n", FEAT_YES_NO(FEAT_LIBCAP));
  235. printf(" libcrypto: %s\n", FEAT_YES_NO(FEAT_CRYPTO));
  236. printf(" libm: %s\n", FEAT_YES_NO(FEAT_LIBM));
  237. printf(" tcalloc: %s\n", FEAT_YES_NO(FEAT_TCMALLOC));
  238. printf(" zlib: %s\n", FEAT_YES_NO(FEAT_ZLIB));
  239. printf("Plugins:\n");
  240. printf(" apps: %s\n", FEAT_YES_NO(FEAT_APPS_PLUGIN));
  241. printf(" cgroup Network Tracking: %s\n", FEAT_YES_NO(FEAT_CGROUP_NET));
  242. printf(" CUPS: %s\n", FEAT_YES_NO(FEAT_CUPS));
  243. printf(" EBPF: %s\n", FEAT_YES_NO(FEAT_EBPF));
  244. printf(" IPMI: %s\n", FEAT_YES_NO(FEAT_IPMI));
  245. printf(" NFACCT: %s\n", FEAT_YES_NO(FEAT_NFACCT));
  246. printf(" perf: %s\n", FEAT_YES_NO(FEAT_PERF));
  247. printf(" slabinfo: %s\n", FEAT_YES_NO(FEAT_SLABINFO));
  248. printf(" Xen: %s\n", FEAT_YES_NO(FEAT_XEN));
  249. printf(" Xen VBD Error Tracking: %s\n", FEAT_YES_NO(FEAT_XEN_VBD_ERROR));
  250. printf("Exporters:\n");
  251. printf(" AWS Kinesis: %s\n", FEAT_YES_NO(FEAT_KINESIS));
  252. printf(" GCP PubSub: %s\n", FEAT_YES_NO(FEAT_PUBSUB));
  253. printf(" MongoDB: %s\n", FEAT_YES_NO(FEAT_MONGO));
  254. printf(" Prometheus Remote Write: %s\n", FEAT_YES_NO(FEAT_REMOTE_WRITE));
  255. printf("Debug/Developer Features:\n");
  256. printf(" Trace Allocations: %s\n", FEAT_YES_NO(FEAT_TRACE_ALLOC));
  257. };
  258. #define FEAT_JSON_BOOL(x) ((x) ? "true" : "false")
  259. // This intentionally does not use JSON-C so it works even if JSON-C is not present
  260. // This is used for anonymous statistics reporting, so it intentionally
  261. // does not include the configure options, which would be very easy to use
  262. // for tracking custom builds (and complicate outputting valid JSON).
  263. void print_build_info_json(void) {
  264. printf("{\n");
  265. printf(" \"features\": {\n");
  266. printf(" \"dbengine\": %s,\n", FEAT_JSON_BOOL(FEAT_DBENGINE));
  267. printf(" \"native-https\": %s,\n", FEAT_JSON_BOOL(FEAT_NATIVE_HTTPS));
  268. printf(" \"cloud\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
  269. #ifdef DISABLE_CLOUD
  270. printf(" \"cloud-disabled\": true,\n");
  271. #else
  272. printf(" \"cloud-disabled\": false,\n");
  273. #endif
  274. printf(" \"aclk\": %s,\n", FEAT_JSON_BOOL(FEAT_CLOUD));
  275. printf(" \"tls-host-verify\": %s,\n", FEAT_JSON_BOOL(FEAT_TLS_HOST_VERIFY));
  276. printf(" \"machine-learning\": %s\n", FEAT_JSON_BOOL(FEAT_ML));
  277. printf(" \"stream-compression\": %s\n", FEAT_JSON_BOOL(FEAT_STREAM_COMPRESSION));
  278. printf(" },\n");
  279. printf(" \"libs\": {\n");
  280. printf(" \"protobuf\": %s,\n", FEAT_JSON_BOOL(FEAT_PROTOBUF));
  281. printf(" \"protobuf-source\": \"%s\",\n", FEAT_PROTOBUF_BUNDLED);
  282. printf(" \"jemalloc\": %s,\n", FEAT_JSON_BOOL(FEAT_JEMALLOC));
  283. printf(" \"jsonc\": %s,\n", FEAT_JSON_BOOL(FEAT_JSONC));
  284. printf(" \"libcap\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBCAP));
  285. printf(" \"libcrypto\": %s,\n", FEAT_JSON_BOOL(FEAT_CRYPTO));
  286. printf(" \"libm\": %s,\n", FEAT_JSON_BOOL(FEAT_LIBM));
  287. printf(" \"tcmalloc\": %s,\n", FEAT_JSON_BOOL(FEAT_TCMALLOC));
  288. printf(" \"zlib\": %s\n", FEAT_JSON_BOOL(FEAT_ZLIB));
  289. printf(" },\n");
  290. printf(" \"plugins\": {\n");
  291. printf(" \"apps\": %s,\n", FEAT_JSON_BOOL(FEAT_APPS_PLUGIN));
  292. printf(" \"cgroup-net\": %s,\n", FEAT_JSON_BOOL(FEAT_CGROUP_NET));
  293. printf(" \"cups\": %s,\n", FEAT_JSON_BOOL(FEAT_CUPS));
  294. printf(" \"ebpf\": %s,\n", FEAT_JSON_BOOL(FEAT_EBPF));
  295. printf(" \"ipmi\": %s,\n", FEAT_JSON_BOOL(FEAT_IPMI));
  296. printf(" \"nfacct\": %s,\n", FEAT_JSON_BOOL(FEAT_NFACCT));
  297. printf(" \"perf\": %s,\n", FEAT_JSON_BOOL(FEAT_PERF));
  298. printf(" \"slabinfo\": %s,\n", FEAT_JSON_BOOL(FEAT_SLABINFO));
  299. printf(" \"xen\": %s,\n", FEAT_JSON_BOOL(FEAT_XEN));
  300. printf(" \"xen-vbd-error\": %s\n", FEAT_JSON_BOOL(FEAT_XEN_VBD_ERROR));
  301. printf(" },\n");
  302. printf(" \"exporters\": {\n");
  303. printf(" \"kinesis\": %s,\n", FEAT_JSON_BOOL(FEAT_KINESIS));
  304. printf(" \"pubsub\": %s,\n", FEAT_JSON_BOOL(FEAT_PUBSUB));
  305. printf(" \"mongodb\": %s,\n", FEAT_JSON_BOOL(FEAT_MONGO));
  306. printf(" \"prom-remote-write\": %s\n", FEAT_JSON_BOOL(FEAT_REMOTE_WRITE));
  307. printf(" }\n");
  308. printf(" \"debug-n-devel\": {\n");
  309. printf(" \"trace-allocations\": %s\n }\n",FEAT_JSON_BOOL(FEAT_TRACE_ALLOC));
  310. printf("}\n");
  311. };
  312. #define add_to_bi(buffer, str) \
  313. { if(first) { \
  314. buffer_strcat (b, str); \
  315. first = 0; \
  316. } else \
  317. buffer_strcat (b, "|" str); }
  318. void analytics_build_info(BUFFER *b) {
  319. int first = 1;
  320. #ifdef ENABLE_DBENGINE
  321. add_to_bi(b, "dbengine");
  322. #endif
  323. #ifdef ENABLE_HTTPS
  324. add_to_bi(b, "Native HTTPS");
  325. #endif
  326. #ifdef ENABLE_ACLK
  327. add_to_bi(b, "Netdata Cloud");
  328. #endif
  329. #if (FEAT_TLS_HOST_VERIFY!=0)
  330. add_to_bi(b, "TLS Host Verification");
  331. #endif
  332. #ifdef ENABLE_ML
  333. add_to_bi(b, "Machine Learning");
  334. #endif
  335. #ifdef ENABLE_COMPRESSION
  336. add_to_bi(b, "Stream Compression");
  337. #endif
  338. #ifdef HAVE_PROTOBUF
  339. add_to_bi(b, "protobuf");
  340. #endif
  341. #ifdef ENABLE_JEMALLOC
  342. add_to_bi(b, "jemalloc");
  343. #endif
  344. #ifdef ENABLE_JSONC
  345. add_to_bi(b, "JSON-C");
  346. #endif
  347. #ifdef HAVE_CAPABILITY
  348. add_to_bi(b, "libcap");
  349. #endif
  350. #ifdef HAVE_CRYPTO
  351. add_to_bi(b, "libcrypto");
  352. #endif
  353. #ifdef STORAGE_WITH_MATH
  354. add_to_bi(b, "libm");
  355. #endif
  356. #ifdef ENABLE_TCMALLOC
  357. add_to_bi(b, "tcalloc");
  358. #endif
  359. #ifdef NETDATA_WITH_ZLIB
  360. add_to_bi(b, "zlib");
  361. #endif
  362. #ifdef ENABLE_APPS_PLUGIN
  363. add_to_bi(b, "apps");
  364. #endif
  365. #ifdef HAVE_SETNS
  366. add_to_bi(b, "cgroup Network Tracking");
  367. #endif
  368. #ifdef HAVE_CUPS
  369. add_to_bi(b, "CUPS");
  370. #endif
  371. #ifdef HAVE_LIBBPF
  372. add_to_bi(b, "EBPF");
  373. #endif
  374. #ifdef HAVE_FREEIPMI
  375. add_to_bi(b, "IPMI");
  376. #endif
  377. #ifdef HAVE_NFACCT
  378. add_to_bi(b, "NFACCT");
  379. #endif
  380. #ifdef ENABLE_PERF_PLUGIN
  381. add_to_bi(b, "perf");
  382. #endif
  383. #ifdef ENABLE_SLABINFO
  384. add_to_bi(b, "slabinfo");
  385. #endif
  386. #ifdef HAVE_LIBXENSTAT
  387. add_to_bi(b, "Xen");
  388. #endif
  389. #ifdef HAVE_XENSTAT_VBD_ERROR
  390. add_to_bi(b, "Xen VBD Error Tracking");
  391. #endif
  392. #ifdef HAVE_KINESIS
  393. add_to_bi(b, "AWS Kinesis");
  394. #endif
  395. #ifdef ENABLE_EXPORTING_PUBSUB
  396. add_to_bi(b, "GCP PubSub");
  397. #endif
  398. #ifdef HAVE_MONGOC
  399. add_to_bi(b, "MongoDB");
  400. #endif
  401. #ifdef ENABLE_PROMETHEUS_REMOTE_WRITE
  402. add_to_bi(b, "Prometheus Remote Write");
  403. #endif
  404. #ifdef NETDATA_TRACE_ALLOCATIONS
  405. add_to_bi(b, "DebugTraceAlloc");
  406. #endif
  407. }