We have extended collectd virt plugin to extract info about disk usage from a libvirt domain using libguestfs. We have had several issues with it which were raised here in 2018 by Peter Dimitrov. Currently the collectd plugin works fine and retrieves the required statistics. Current collectd configuration says that interval of reading statistics (interval of calling all plugins read functions) is 50 seconds. After certain period of time (e.g. certain number of calls of plugin read functions - about 490 calls), collectd is terminated with signal SIGABRT with the following backtrace:
(gdb) bt #0 0x00007ffff71f2e97 in raise () from /lib/x86_64-linux-gnu/libc.so.6 #1 0x00007ffff71f4801 in abort () from /lib/x86_64-linux-gnu/libc.so.6 #2 0x00007ffff723d897 in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #3 0x00007ffff72e8cff in ?? () from /lib/x86_64-linux-gnu/libc.so.6 #4 0x00007ffff72e8d21 in __fortify_fail () from /lib/x86_64-linux-gnu/libc.so.6 #5 0x00007ffff72e6a10 in __chk_fail () from /lib/x86_64-linux-gnu/libc.so.6 #6 0x00007ffff72e8c0a in __fdelt_warn () from /lib/x86_64-linux-gnu/libc.so.6 #7 0x00007ffff47ed8ba in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #8 0x00007ffff47ee2f5 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #9 0x00007ffff47efefc in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #10 0x00007ffff4794ca5 in guestfs_disk_create_argv () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #11 0x00007ffff4807b18 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #12 0x00007ffff47f0b44 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #13 0x00007ffff47f0d7b in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #14 0x00007ffff47f1c55 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #15 0x00007ffff4784927 in guestfs_add_drive_opts_argv () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #16 0x00007ffff48128e0 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #17 0x00007ffff4813cd6 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #18 0x00007ffff47ab2c3 in guestfs_add_libvirt_dom_argv () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #19 0x00007ffff4812cf6 in ?? () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #20 0x00007ffff4760368 in guestfs_add_domain_argv () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #21 0x00007ffff47dfc38 in guestfs_add_domain_va () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #22 0x00007ffff47dfee4 in guestfs_add_domain () from /usr/lib/x86_64-linux-gnu/libguestfs.so.0 #23 0x00007ffff4a78bec in refresh_lists (inst=inst@entry=0x7ffff4c7f940 <lv_read_user_data>) at src/virt.c:2049 #24 0x00007ffff4a7a327 in lv_read (ud=<optimized out>) at src/virt.c:1656 #25 0x0000555555564a1c in plugin_read_thread (args=<optimized out>) at src/daemon/plugin.c:540 #26 0x00007ffff79b66db in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0 #27 0x00007ffff72d588f in clone () from /lib/x86_64-linux-gnu/libc.so.6
The code using libguestfs called every time virt plugin read function is invoked is given below. I need to mention that the code presented here lacks proper cleanup.
/* guestfs_extend start */ /* get FS stats using libguestfs */ /* Filesystems. */
guestfs_h *g = NULL; int ret = 0; int j = 0; int cnt_drives = 0; char **fses = NULL; struct guestfs_statvfs *fs_stats = NULL; struct fs_info *fs = NULL;
/* Work around collectd bug with waitpid() after fork() */ signal (SIGCHLD, SIG_DFL);
g = guestfs_create(); if (g == NULL) { ERROR(PLUGIN_NAME " plugin: failed to create libguestfs handle"); goto cont; //exit(EXIT_FAILURE); }