chore(cgroups.plugin): reduce the CPU time required for cgroup-network-helper.sh (#12711)
Ilya Mashchenko committed
Apr 19, 2022 at 15:00 UTC
c49c3cc965d772a4c7dc9dc98dcf97c5254a5530
1 file changed
+2
-9
collectors/cgroups.plugin/cgroup-network-helper.sh
+2
-9
@@ -218,15 +218,8 @@ netnsid_find_all_interfaces_for_pid() {
218
netnsid_find_all_interfaces_for_cgroup() {
219
local c="${1}" # the cgroup path
220
221
- # for each pid of the cgroup
222
- # find any tun/tap devices linked to the pid
223
- if [ -f "${c}/cgroup.procs" ]
224
- then
225
- local p
226
- for p in $(< "${c}/cgroup.procs" )
227
- do
228
- netnsid_find_all_interfaces_for_pid "${p}"
229
- done
221
+ if [ -f "${c}/cgroup.procs" ]; then
222
+ netnsid_find_all_interfaces_for_pid "$(head -n 1 "${c}/cgroup.procs" 2 >/dev/null)"
223
else
224
debug "Cannot find file '${c}/cgroup.procs', not searching for netnsid interfaces."
225
fi