ebpf_filesystem.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "ebpf_filesystem.h"
  3. struct config fs_config = { .first_section = NULL,
  4. .last_section = NULL,
  5. .mutex = NETDATA_MUTEX_INITIALIZER,
  6. .index = { .avl_tree = { .root = NULL, .compar = appconfig_section_compare },
  7. .rwlock = AVL_LOCK_INITIALIZER } };
  8. static ebpf_local_maps_t fs_maps[] = {{.name = "tbl_ext4", .internal_input = NETDATA_KEY_CALLS_SYNC,
  9. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  10. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  11. {.name = "tbl_xfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
  12. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  13. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  14. {.name = "tbl_nfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
  15. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  16. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  17. {.name = "tbl_zfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
  18. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  19. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  20. {.name = "tbl_btrfs", .internal_input = NETDATA_KEY_CALLS_SYNC,
  21. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  22. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  23. {.name = "tbl_ext_addr", .internal_input = 1,
  24. .user_input = 0, .type = NETDATA_EBPF_MAP_STATIC,
  25. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED},
  26. {.name = NULL, .internal_input = 0, .user_input = 0,
  27. .type = NETDATA_EBPF_MAP_CONTROLLER,
  28. .map_fd = ND_EBPF_MAP_FD_NOT_INITIALIZED}};
  29. static netdata_syscall_stat_t filesystem_aggregated_data[NETDATA_EBPF_HIST_MAX_BINS];
  30. static netdata_publish_syscall_t filesystem_publish_aggregated[NETDATA_EBPF_HIST_MAX_BINS];
  31. char **dimensions = NULL;
  32. static netdata_idx_t *filesystem_hash_values = NULL;
  33. /*****************************************************************
  34. *
  35. * COMMON FUNCTIONS
  36. *
  37. *****************************************************************/
  38. /**
  39. * Create Filesystem chart
  40. *
  41. * Create latency charts
  42. *
  43. * @param update_every value to overwrite the update frequency set by the server.
  44. */
  45. static void ebpf_obsolete_fs_charts(int update_every)
  46. {
  47. int i;
  48. uint32_t test = NETDATA_FILESYSTEM_FLAG_CHART_CREATED | NETDATA_FILESYSTEM_REMOVE_CHARTS;
  49. for (i = 0; localfs[i].filesystem; i++) {
  50. ebpf_filesystem_partitions_t *efp = &localfs[i];
  51. uint32_t flags = efp->flags;
  52. if ((flags & test) == test) {
  53. flags &= ~NETDATA_FILESYSTEM_FLAG_CHART_CREATED;
  54. ebpf_write_chart_obsolete(NETDATA_FILESYSTEM_FAMILY, efp->hread.name,
  55. efp->hread.title,
  56. EBPF_COMMON_DIMENSION_CALL, efp->family_name,
  57. NULL, NETDATA_EBPF_CHART_TYPE_STACKED, efp->hread.order, update_every);
  58. ebpf_write_chart_obsolete(NETDATA_FILESYSTEM_FAMILY, efp->hwrite.name,
  59. efp->hwrite.title,
  60. EBPF_COMMON_DIMENSION_CALL, efp->family_name,
  61. NULL, NETDATA_EBPF_CHART_TYPE_STACKED, efp->hwrite.order, update_every);
  62. ebpf_write_chart_obsolete(NETDATA_FILESYSTEM_FAMILY, efp->hopen.name, efp->hopen.title,
  63. EBPF_COMMON_DIMENSION_CALL, efp->family_name,
  64. NULL, NETDATA_EBPF_CHART_TYPE_STACKED, efp->hopen.order, update_every);
  65. ebpf_write_chart_obsolete(NETDATA_FILESYSTEM_FAMILY, efp->hadditional.name, efp->hadditional.title,
  66. EBPF_COMMON_DIMENSION_CALL, efp->family_name,
  67. NULL, NETDATA_EBPF_CHART_TYPE_STACKED, efp->hadditional.order,
  68. update_every);
  69. }
  70. efp->flags = flags;
  71. }
  72. }
  73. /**
  74. * Create Filesystem chart
  75. *
  76. * Create latency charts
  77. *
  78. * @param update_every value to overwrite the update frequency set by the server.
  79. */
  80. static void ebpf_create_fs_charts(int update_every)
  81. {
  82. static int order = NETDATA_CHART_PRIO_EBPF_FILESYSTEM_CHARTS;
  83. char chart_name[64], title[256], family[64], ctx[64];
  84. int i;
  85. uint32_t test = NETDATA_FILESYSTEM_FLAG_CHART_CREATED|NETDATA_FILESYSTEM_REMOVE_CHARTS;
  86. for (i = 0; localfs[i].filesystem; i++) {
  87. ebpf_filesystem_partitions_t *efp = &localfs[i];
  88. uint32_t flags = efp->flags;
  89. if (flags & NETDATA_FILESYSTEM_FLAG_HAS_PARTITION && !(flags & test)) {
  90. snprintfz(title, 255, "%s latency for each read request.", efp->filesystem);
  91. snprintfz(family, 63, "%s_latency", efp->family);
  92. snprintfz(chart_name, 63, "%s_read_latency", efp->filesystem);
  93. efp->hread.name = strdupz(chart_name);
  94. efp->hread.title = strdupz(title);
  95. efp->hread.order = order;
  96. efp->family_name = strdupz(family);
  97. ebpf_create_chart(NETDATA_FILESYSTEM_FAMILY, efp->hread.name,
  98. title,
  99. EBPF_COMMON_DIMENSION_CALL, family,
  100. "filesystem.read_latency", NETDATA_EBPF_CHART_TYPE_STACKED, order, ebpf_create_global_dimension,
  101. filesystem_publish_aggregated, NETDATA_EBPF_HIST_MAX_BINS,
  102. update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
  103. order++;
  104. snprintfz(title, 255, "%s latency for each write request.", efp->filesystem);
  105. snprintfz(chart_name, 63, "%s_write_latency", efp->filesystem);
  106. efp->hwrite.name = strdupz(chart_name);
  107. efp->hwrite.title = strdupz(title);
  108. efp->hwrite.order = order;
  109. ebpf_create_chart(NETDATA_FILESYSTEM_FAMILY, efp->hwrite.name,
  110. title,
  111. EBPF_COMMON_DIMENSION_CALL, family,
  112. "filesystem.write_latency", NETDATA_EBPF_CHART_TYPE_STACKED, order, ebpf_create_global_dimension,
  113. filesystem_publish_aggregated, NETDATA_EBPF_HIST_MAX_BINS,
  114. update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
  115. order++;
  116. snprintfz(title, 255, "%s latency for each open request.", efp->filesystem);
  117. snprintfz(chart_name, 63, "%s_open_latency", efp->filesystem);
  118. efp->hopen.name = strdupz(chart_name);
  119. efp->hopen.title = strdupz(title);
  120. efp->hopen.order = order;
  121. ebpf_create_chart(NETDATA_FILESYSTEM_FAMILY, efp->hopen.name,
  122. title,
  123. EBPF_COMMON_DIMENSION_CALL, family,
  124. "filesystem.open_latency", NETDATA_EBPF_CHART_TYPE_STACKED, order, ebpf_create_global_dimension,
  125. filesystem_publish_aggregated, NETDATA_EBPF_HIST_MAX_BINS,
  126. update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
  127. order++;
  128. char *type = (efp->flags & NETDATA_FILESYSTEM_ATTR_CHARTS) ? "attribute" : "sync";
  129. snprintfz(title, 255, "%s latency for each %s request.", efp->filesystem, type);
  130. snprintfz(chart_name, 63, "%s_%s_latency", efp->filesystem, type);
  131. snprintfz(ctx, 63, "filesystem.%s_latency", type);
  132. efp->hadditional.name = strdupz(chart_name);
  133. efp->hadditional.title = strdupz(title);
  134. efp->hadditional.order = order;
  135. ebpf_create_chart(NETDATA_FILESYSTEM_FAMILY, efp->hadditional.name, title,
  136. EBPF_COMMON_DIMENSION_CALL, family,
  137. ctx, NETDATA_EBPF_CHART_TYPE_STACKED, order, ebpf_create_global_dimension,
  138. filesystem_publish_aggregated, NETDATA_EBPF_HIST_MAX_BINS,
  139. update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM);
  140. order++;
  141. efp->flags |= NETDATA_FILESYSTEM_FLAG_CHART_CREATED;
  142. }
  143. }
  144. }
  145. /**
  146. * Initialize eBPF data
  147. *
  148. * @param em main thread structure.
  149. *
  150. * @return it returns 0 on success and -1 otherwise.
  151. */
  152. int ebpf_filesystem_initialize_ebpf_data(ebpf_module_t *em)
  153. {
  154. int i;
  155. const char *saved_name = em->thread_name;
  156. uint64_t kernels = em->kernels;
  157. for (i = 0; localfs[i].filesystem; i++) {
  158. ebpf_filesystem_partitions_t *efp = &localfs[i];
  159. if (!efp->probe_links && efp->flags & NETDATA_FILESYSTEM_LOAD_EBPF_PROGRAM) {
  160. em->thread_name = efp->filesystem;
  161. em->kernels = efp->kernels;
  162. efp->probe_links = ebpf_load_program(ebpf_plugin_dir, em, running_on_kernel, isrh, &efp->objects);
  163. if (!efp->probe_links) {
  164. em->thread_name = saved_name;
  165. em->kernels = kernels;
  166. return -1;
  167. }
  168. efp->flags |= NETDATA_FILESYSTEM_FLAG_HAS_PARTITION;
  169. pthread_mutex_lock(&lock);
  170. ebpf_update_kernel_memory(&plugin_statistics, &fs_maps[i], EBPF_ACTION_STAT_ADD);
  171. pthread_mutex_unlock(&lock);
  172. // Nedeed for filesystems like btrfs
  173. if ((efp->flags & NETDATA_FILESYSTEM_FILL_ADDRESS_TABLE) && (efp->addresses.function)) {
  174. ebpf_load_addresses(&efp->addresses, fs_maps[i + 1].map_fd);
  175. }
  176. }
  177. efp->flags &= ~NETDATA_FILESYSTEM_LOAD_EBPF_PROGRAM;
  178. }
  179. em->thread_name = saved_name;
  180. em->kernels = kernels;
  181. if (!dimensions) {
  182. dimensions = ebpf_fill_histogram_dimension(NETDATA_EBPF_HIST_MAX_BINS);
  183. memset(filesystem_aggregated_data, 0 , NETDATA_EBPF_HIST_MAX_BINS * sizeof(netdata_syscall_stat_t));
  184. memset(filesystem_publish_aggregated, 0 , NETDATA_EBPF_HIST_MAX_BINS * sizeof(netdata_publish_syscall_t));
  185. filesystem_hash_values = callocz(ebpf_nprocs, sizeof(netdata_idx_t));
  186. }
  187. return 0;
  188. }
  189. /**
  190. * Read Local partitions
  191. *
  192. * @return the total of partitions that will be monitored
  193. */
  194. static int ebpf_read_local_partitions()
  195. {
  196. char filename[FILENAME_MAX + 1];
  197. snprintfz(filename, FILENAME_MAX, "%s/proc/self/mountinfo", netdata_configured_host_prefix);
  198. procfile *ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
  199. if(unlikely(!ff)) {
  200. snprintfz(filename, FILENAME_MAX, "%s/proc/1/mountinfo", netdata_configured_host_prefix);
  201. ff = procfile_open(filename, " \t", PROCFILE_FLAG_DEFAULT);
  202. if(unlikely(!ff)) return 0;
  203. }
  204. ff = procfile_readall(ff);
  205. if(unlikely(!ff))
  206. return 0;
  207. int count = 0;
  208. unsigned long l, i, lines = procfile_lines(ff);
  209. for (i = 0; localfs[i].filesystem; i++) {
  210. localfs[i].flags |= NETDATA_FILESYSTEM_REMOVE_CHARTS;
  211. }
  212. for(l = 0; l < lines ; l++) {
  213. // In "normal" situation the expected value is at column 7
  214. // When `shared` options is added to mount information, the filesystem is at column 8
  215. // Finally when we have systemd starting netdata, it will be at column 9
  216. unsigned long index = procfile_linewords(ff, l) - 3;
  217. char *fs = procfile_lineword(ff, l, index);
  218. for (i = 0; localfs[i].filesystem; i++) {
  219. ebpf_filesystem_partitions_t *w = &localfs[i];
  220. if (w->enabled && (!strcmp(fs, w->filesystem) ||
  221. (w->optional_filesystem && !strcmp(fs, w->optional_filesystem)))) {
  222. localfs[i].flags |= NETDATA_FILESYSTEM_LOAD_EBPF_PROGRAM;
  223. localfs[i].flags &= ~NETDATA_FILESYSTEM_REMOVE_CHARTS;
  224. count++;
  225. break;
  226. }
  227. }
  228. }
  229. procfile_close(ff);
  230. return count;
  231. }
  232. /**
  233. * Update partition
  234. *
  235. * Update the partition structures before to plot
  236. *
  237. * @param em main thread structure
  238. *
  239. * @return 0 on success and -1 otherwise.
  240. */
  241. static int ebpf_update_partitions(ebpf_module_t *em)
  242. {
  243. static time_t update_every = 0;
  244. time_t curr = now_realtime_sec();
  245. if (curr < update_every)
  246. return 0;
  247. update_every = curr + 5 * em->update_every;
  248. if (!ebpf_read_local_partitions()) {
  249. em->optional = -1;
  250. return -1;
  251. }
  252. if (ebpf_filesystem_initialize_ebpf_data(em)) {
  253. return -1;
  254. }
  255. return 0;
  256. }
  257. /*****************************************************************
  258. *
  259. * CLEANUP FUNCTIONS
  260. *
  261. *****************************************************************/
  262. /*
  263. * Cleanup eBPF data
  264. */
  265. void ebpf_filesystem_cleanup_ebpf_data()
  266. {
  267. int i;
  268. for (i = 0; localfs[i].filesystem; i++) {
  269. ebpf_filesystem_partitions_t *efp = &localfs[i];
  270. if (efp->probe_links) {
  271. freez(efp->family_name);
  272. freez(efp->hread.name);
  273. freez(efp->hread.title);
  274. freez(efp->hwrite.name);
  275. freez(efp->hwrite.title);
  276. freez(efp->hopen.name);
  277. freez(efp->hopen.title);
  278. freez(efp->hadditional.name);
  279. freez(efp->hadditional.title);
  280. }
  281. }
  282. }
  283. /**
  284. * Filesystem Free
  285. *
  286. * Cleanup variables after child threads to stop
  287. *
  288. * @param ptr thread data.
  289. */
  290. static void ebpf_filesystem_free(ebpf_module_t *em)
  291. {
  292. pthread_mutex_lock(&ebpf_exit_cleanup);
  293. em->enabled = NETDATA_THREAD_EBPF_STOPPING;
  294. pthread_mutex_unlock(&ebpf_exit_cleanup);
  295. ebpf_filesystem_cleanup_ebpf_data();
  296. if (dimensions)
  297. ebpf_histogram_dimension_cleanup(dimensions, NETDATA_EBPF_HIST_MAX_BINS);
  298. freez(filesystem_hash_values);
  299. pthread_mutex_lock(&ebpf_exit_cleanup);
  300. em->enabled = NETDATA_THREAD_EBPF_STOPPED;
  301. pthread_mutex_unlock(&ebpf_exit_cleanup);
  302. }
  303. /**
  304. * Filesystem exit
  305. *
  306. * Cancel child thread.
  307. *
  308. * @param ptr thread data.
  309. */
  310. static void ebpf_filesystem_exit(void *ptr)
  311. {
  312. ebpf_module_t *em = (ebpf_module_t *)ptr;
  313. ebpf_filesystem_free(em);
  314. }
  315. /*****************************************************************
  316. *
  317. * MAIN THREAD
  318. *
  319. *****************************************************************/
  320. /**
  321. * Select hist
  322. *
  323. * Select a histogram to store data.
  324. *
  325. * @param efp pointer for the structure with pointers.
  326. * @param id histogram selector
  327. *
  328. * @return It returns a pointer for the histogram
  329. */
  330. static inline netdata_ebpf_histogram_t *select_hist(ebpf_filesystem_partitions_t *efp, uint32_t *idx, uint32_t id)
  331. {
  332. if (id < NETDATA_KEY_CALLS_READ) {
  333. *idx = id;
  334. return &efp->hread;
  335. } else if (id < NETDATA_KEY_CALLS_WRITE) {
  336. *idx = id - NETDATA_KEY_CALLS_READ;
  337. return &efp->hwrite;
  338. } else if (id < NETDATA_KEY_CALLS_OPEN) {
  339. *idx = id - NETDATA_KEY_CALLS_WRITE;
  340. return &efp->hopen;
  341. } else if (id < NETDATA_KEY_CALLS_SYNC ){
  342. *idx = id - NETDATA_KEY_CALLS_OPEN;
  343. return &efp->hadditional;
  344. }
  345. return NULL;
  346. }
  347. /**
  348. * Read hard disk table
  349. *
  350. * @param table index for the hash table
  351. *
  352. * Read the table with number of calls for all functions
  353. */
  354. static void read_filesystem_table(ebpf_filesystem_partitions_t *efp, int fd)
  355. {
  356. netdata_idx_t *values = filesystem_hash_values;
  357. uint32_t key;
  358. uint32_t idx;
  359. for (key = 0; key < NETDATA_KEY_CALLS_SYNC; key++) {
  360. netdata_ebpf_histogram_t *w = select_hist(efp, &idx, key);
  361. if (!w) {
  362. continue;
  363. }
  364. int test = bpf_map_lookup_elem(fd, &key, values);
  365. if (test < 0) {
  366. continue;
  367. }
  368. uint64_t total = 0;
  369. int i;
  370. int end = ebpf_nprocs;
  371. for (i = 0; i < end; i++) {
  372. total += values[i];
  373. }
  374. if (idx >= NETDATA_EBPF_HIST_MAX_BINS)
  375. idx = NETDATA_EBPF_HIST_MAX_BINS - 1;
  376. w->histogram[idx] = total;
  377. }
  378. }
  379. /**
  380. * Read hard disk table
  381. *
  382. * @param table index for the hash table
  383. *
  384. * Read the table with number of calls for all functions
  385. */
  386. static void read_filesystem_tables()
  387. {
  388. int i;
  389. for (i = 0; localfs[i].filesystem; i++) {
  390. ebpf_filesystem_partitions_t *efp = &localfs[i];
  391. if (efp->flags & NETDATA_FILESYSTEM_FLAG_HAS_PARTITION) {
  392. read_filesystem_table(efp, fs_maps[i].map_fd);
  393. }
  394. }
  395. }
  396. /**
  397. * Socket read hash
  398. *
  399. * This is the thread callback.
  400. * This thread is necessary, because we cannot freeze the whole plugin to read the data on very busy socket.
  401. *
  402. * @param ptr It is a NULL value for this thread.
  403. *
  404. * @return It always returns NULL.
  405. */
  406. void ebpf_filesystem_read_hash(ebpf_module_t *em)
  407. {
  408. ebpf_obsolete_fs_charts(em->update_every);
  409. (void) ebpf_update_partitions(em);
  410. if (em->optional)
  411. return;
  412. read_filesystem_tables();
  413. }
  414. /**
  415. * Send Hard disk data
  416. *
  417. * Send hard disk information to Netdata.
  418. */
  419. static void ebpf_histogram_send_data()
  420. {
  421. uint32_t i;
  422. uint32_t test = NETDATA_FILESYSTEM_FLAG_HAS_PARTITION | NETDATA_FILESYSTEM_REMOVE_CHARTS;
  423. for (i = 0; localfs[i].filesystem; i++) {
  424. ebpf_filesystem_partitions_t *efp = &localfs[i];
  425. if ((efp->flags & test) == NETDATA_FILESYSTEM_FLAG_HAS_PARTITION) {
  426. write_histogram_chart(NETDATA_FILESYSTEM_FAMILY, efp->hread.name,
  427. efp->hread.histogram, dimensions, NETDATA_EBPF_HIST_MAX_BINS);
  428. write_histogram_chart(NETDATA_FILESYSTEM_FAMILY, efp->hwrite.name,
  429. efp->hwrite.histogram, dimensions, NETDATA_EBPF_HIST_MAX_BINS);
  430. write_histogram_chart(NETDATA_FILESYSTEM_FAMILY, efp->hopen.name,
  431. efp->hopen.histogram, dimensions, NETDATA_EBPF_HIST_MAX_BINS);
  432. write_histogram_chart(NETDATA_FILESYSTEM_FAMILY, efp->hadditional.name,
  433. efp->hadditional.histogram, dimensions, NETDATA_EBPF_HIST_MAX_BINS);
  434. }
  435. }
  436. }
  437. /**
  438. * Main loop for this collector.
  439. *
  440. * @param em main structure for this thread
  441. */
  442. static void filesystem_collector(ebpf_module_t *em)
  443. {
  444. int update_every = em->update_every;
  445. heartbeat_t hb;
  446. heartbeat_init(&hb);
  447. int counter = update_every - 1;
  448. while (!ebpf_exit_plugin) {
  449. (void)heartbeat_next(&hb, USEC_PER_SEC);
  450. if (ebpf_exit_plugin || ++counter != update_every)
  451. continue;
  452. counter = 0;
  453. ebpf_filesystem_read_hash(em);
  454. pthread_mutex_lock(&lock);
  455. ebpf_create_fs_charts(update_every);
  456. ebpf_histogram_send_data();
  457. pthread_mutex_unlock(&lock);
  458. }
  459. }
  460. /*****************************************************************
  461. *
  462. * ENTRY THREAD
  463. *
  464. *****************************************************************/
  465. /**
  466. * Update Filesystem
  467. *
  468. * Update file system structure using values read from configuration file.
  469. */
  470. static void ebpf_update_filesystem()
  471. {
  472. char dist[NETDATA_FS_MAX_DIST_NAME + 1];
  473. int i;
  474. for (i = 0; localfs[i].filesystem; i++) {
  475. snprintfz(dist, NETDATA_FS_MAX_DIST_NAME, "%sdist", localfs[i].filesystem);
  476. localfs[i].enabled = appconfig_get_boolean(&fs_config, NETDATA_FILESYSTEM_CONFIG_NAME, dist,
  477. CONFIG_BOOLEAN_YES);
  478. }
  479. }
  480. /**
  481. * Filesystem thread
  482. *
  483. * Thread used to generate socket charts.
  484. *
  485. * @param ptr a pointer to `struct ebpf_module`
  486. *
  487. * @return It always return NULL
  488. */
  489. void *ebpf_filesystem_thread(void *ptr)
  490. {
  491. netdata_thread_cleanup_push(ebpf_filesystem_exit, ptr);
  492. ebpf_module_t *em = (ebpf_module_t *)ptr;
  493. em->maps = fs_maps;
  494. ebpf_update_filesystem();
  495. // Initialize optional as zero, to identify when there are not partitions to monitor
  496. em->optional = 0;
  497. if (ebpf_update_partitions(em)) {
  498. if (em->optional)
  499. info("Netdata cannot monitor the filesystems used on this host.");
  500. goto endfilesystem;
  501. }
  502. int algorithms[NETDATA_EBPF_HIST_MAX_BINS];
  503. ebpf_fill_algorithms(algorithms, NETDATA_EBPF_HIST_MAX_BINS, NETDATA_EBPF_INCREMENTAL_IDX);
  504. ebpf_global_labels(filesystem_aggregated_data, filesystem_publish_aggregated, dimensions, dimensions,
  505. algorithms, NETDATA_EBPF_HIST_MAX_BINS);
  506. pthread_mutex_lock(&lock);
  507. ebpf_create_fs_charts(em->update_every);
  508. ebpf_update_stats(&plugin_statistics, em);
  509. pthread_mutex_unlock(&lock);
  510. filesystem_collector(em);
  511. endfilesystem:
  512. ebpf_update_disabled_plugin_stats(em);
  513. netdata_thread_cleanup_pop(1);
  514. return NULL;
  515. }