1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Plugin lxc: function "lxc_count_processes" now outputs its result

Previously the result was returned as the exit code of the function
(which would prevent the usage of "set -e").
Additionally the fallback value that was previously calculated outside
of the function is now part of it.
This commit is contained in:
Lars Kruse 2019-08-11 23:58:15 +02:00
parent 9af96d2c60
commit ec3a7f4045

View file

@ -141,34 +141,37 @@ function lxc_netdev {
# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc/<container>/tasks
# and with cgmanager on jessie
lxc_count_processes () {
local guest_name="$1"
local SYSFS
[ -z "$1" ] && return 0
[ -z "$guest_name" ] && return 0
if [ -n "$cgrouppath" ]; then
SYSFS="$cgrouppath/$1/tasks"
SYSFS="$cgrouppath/$guest_name/tasks"
if [ -e $SYSFS ]; then
return $(wc -l < $SYSFS)
wc -l <"$SYSFS"
return
fi
fi
for SYSFS in \
/sys/fs/cgroup/"$1"/tasks \
/sys/fs/cgroup/lxc/"$1"/tasks \
/sys/fs/cgroup/systemd/lxc/"$1"/tasks \
/sys/fs/cgroup/cpuacct/lxc/"$1"/tasks \
/sys/fs/cgroup/cpuacct/sysdefault/lxc/"$1"/tasks
/sys/fs/cgroup/"$guest_name"/tasks \
/sys/fs/cgroup/lxc/"$guest_name"/tasks \
/sys/fs/cgroup/systemd/lxc/"$guest_name"/tasks \
/sys/fs/cgroup/cpuacct/lxc/"$guest_name"/tasks \
/sys/fs/cgroup/cpuacct/sysdefault/lxc/"$guest_name"/tasks
do
if [ -e $SYSFS ]; then
return $(wc -l < $SYSFS)
wc -l <"$SYSFS"
return
fi
done
if [ -e /usr/bin/cgm ]; then
return $(cgm getvalue cpu "lxc/$1" tasks 2>/dev/null | wc -l)
cgm getvalue cpu "lxc/$guest_name" tasks 2>/dev/null | wc -l
else
lxc_cgroup -n "$guest_name" tasks | wc -l
fi
return 0
}
@ -359,24 +362,23 @@ for n in $active_guests
do
device=$(lxc_netdev "$n")
if [ "$device" = "unknown" ]; then
continue
value_up="U"
value_down="U"
else
value_up=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}')
value_down=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}')
fi
cat <<EOF
$(clean_fieldname "net__${n}_up").value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}')
$(clean_fieldname "net__${n}_down").value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}')
$(clean_fieldname "net__${n}_up").value $value_up
$(clean_fieldname "net__${n}_down").value $value_down
EOF
done
echo "multigraph lxc_proc"
for n in $active_guests
do
lxc_count_processes "$n"
tmp=$?
if [ $tmp -eq 0 ]; then
tmp=$(lxc_cgroup -n "$n" tasks | wc -l)
fi
echo $(clean_fieldname "lxc_proc__${n}").value $tmp
echo "$(clean_fieldname "lxc_proc__${n}").value $(lxc_count_processes "$n")"
done
echo "multigraph lxc_ram"