@cryptotaxi247 / netdata-1 / commits / c2d625779

deduplicate mountinfo based on mount point (#13215)

Costa Tsaousis committed Jun 26, 2022 at 12:02 UTC c2d625779799ea5725a881cc318b39a43ad2274e
1 file changed +11
collectors/proc.plugin/proc_self_mountinfo.c
+11
@@ -199,11 +199,21 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
199
200 struct mountinfo *root = NULL, *last = NULL, *mi = NULL;
201
202 + // create a dictionary to track uniqueness
203 + DICTIONARY *dict = dictionary_create(DICTIONARY_FLAG_SINGLE_THREADED|DICTIONARY_FLAG_DONT_OVERWRITE_VALUE|DICTIONARY_FLAG_NAME_LINK_DONT_CLONE);
204 +
205 unsigned long l, lines = procfile_lines(ff);
206 for(l = 0; l < lines ;l++) {
207 if(unlikely(procfile_linewords(ff, l) < 5))
208 continue;
209
210 + // make sure we don't add the same item twice
211 + char *v = (char *)dictionary_set(dict, procfile_lineword(ff, l, 4), "N", 2);
212 + if(v) {
213 + if(*v == 'O') continue;
214 + *v = 'O';
215 + }
216 +
217 mi = mallocz(sizeof(struct mountinfo));
218
219 unsigned long w = 0;
@@ -411,6 +421,7 @@ struct mountinfo *mountinfo_read(int do_statvfs) {
421 }
422 */
423
424 + dictionary_destroy(dict);
425 procfile_close(ff);
426 return root;
427 }