buildinfo.c 13 KB

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