@cryptotaxi247 / netdata-1 / commits / 1b819afdb

cgroups: fix network interfaces detection when using `virsh` (#11096)

Ilya Mashchenko committed May 6, 2021 at 10:50 UTC 1b819afdbba067ae6abbeac20fb8805cd1e4e3c4
2 files changed +13 -5
collectors/cgroups.plugin/cgroup-network-helper.sh
+12 -4
@@ -123,7 +123,7 @@ proc_pid_fdinfo_iff() {
123 find_tun_tap_interfaces_for_cgroup() {
124 local c="${1}" # the cgroup path
125 [ -d "${c}/emulator" ] && c="${c}/emulator" # check for 'emulator' subdirectory
126 - c="${c}/cgroup.procs" # make full path
126 + c="${c}/cgroup.procs" # make full path
127
128 # for each pid of the cgroup
129 # find any tun/tap devices linked to the pid
@@ -168,18 +168,26 @@ virsh_find_all_interfaces_for_cgroup() {
168 then
169 local d
170 d="$(virsh_cgroup_to_domain_name "${c}")"
171 + # convert hex to character
172 + # e.g.: vm01\x2dweb => vm01-web (https://github.com/netdata/netdata/issues/11088#issuecomment-832618149)
173 + d="$(printf '%b' "${d}")"
174
175 if [ ! -z "${d}" ]
176 then
177 debug "running: virsh domiflist ${d}; to find the network interfaces"
178
176 - # match only 'network' interfaces from virsh output
179 + # 'virsh -r domiflist <domain>' example output
180 + # Interface Type Source Model MAC
181 + #--------------------------------------------------------------
182 + # vnet3 bridge br0 virtio 52:54:00:xx:xx:xx
183 + # vnet4 network default virtio 52:54:00:yy:yy:yy
184
185 + # match only 'network' interfaces from virsh output
186 set_source "virsh"
187 "${virsh}" -r domiflist "${d}" |\
188 sed -n \
181 - -e "s|^\([^[:space:]]\+\)[[:space:]]\+network[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+[^[:space:]]\+[[:space:]]\+[^[:space:]]\+$|\1 \1_\2|p" \
182 - -e "s|^\([^[:space:]]\+\)[[:space:]]\+bridge[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+[^[:space:]]\+[[:space:]]\+[^[:space:]]\+$|\1 \1_\2|p"
189 + -e "s|^[[:space:]]\?\([^[:space:]]\+\)[[:space:]]\+network[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+[^[:space:]]\+[[:space:]]\+[^[:space:]]\+$|\1 \1_\2|p" \
190 + -e "s|^[[:space:]]\?\([^[:space:]]\+\)[[:space:]]\+bridge[[:space:]]\+\([^[:space:]]\+\)[[:space:]]\+[^[:space:]]\+[[:space:]]\+[^[:space:]]\+$|\1 \1_\2|p"
191 else
192 debug "no virsh domain extracted from cgroup ${c}"
193 fi
collectors/cgroups.plugin/cgroup-network.c
+1 -1
@@ -453,7 +453,7 @@ void detect_veth_interfaces(pid_t pid) {
453
454 if(!eligible_ifaces(host)) {
455 errno = 0;
456 - error("there are no double-linked host interfaces available.");
456 + info("there are no double-linked host interfaces available.");
457 goto cleanup;
458 }
459