mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51: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:
parent
9af96d2c60
commit
ec3a7f4045
1 changed files with 23 additions and 21 deletions
|
@ -141,34 +141,37 @@ function lxc_netdev {
|
||||||
# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc/<container>/tasks
|
# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc/<container>/tasks
|
||||||
# and with cgmanager on jessie
|
# and with cgmanager on jessie
|
||||||
lxc_count_processes () {
|
lxc_count_processes () {
|
||||||
|
local guest_name="$1"
|
||||||
local SYSFS
|
local SYSFS
|
||||||
|
|
||||||
[ -z "$1" ] && return 0
|
[ -z "$guest_name" ] && return 0
|
||||||
|
|
||||||
if [ -n "$cgrouppath" ]; then
|
if [ -n "$cgrouppath" ]; then
|
||||||
SYSFS="$cgrouppath/$1/tasks"
|
SYSFS="$cgrouppath/$guest_name/tasks"
|
||||||
if [ -e $SYSFS ]; then
|
if [ -e $SYSFS ]; then
|
||||||
return $(wc -l < $SYSFS)
|
wc -l <"$SYSFS"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for SYSFS in \
|
for SYSFS in \
|
||||||
/sys/fs/cgroup/"$1"/tasks \
|
/sys/fs/cgroup/"$guest_name"/tasks \
|
||||||
/sys/fs/cgroup/lxc/"$1"/tasks \
|
/sys/fs/cgroup/lxc/"$guest_name"/tasks \
|
||||||
/sys/fs/cgroup/systemd/lxc/"$1"/tasks \
|
/sys/fs/cgroup/systemd/lxc/"$guest_name"/tasks \
|
||||||
/sys/fs/cgroup/cpuacct/lxc/"$1"/tasks \
|
/sys/fs/cgroup/cpuacct/lxc/"$guest_name"/tasks \
|
||||||
/sys/fs/cgroup/cpuacct/sysdefault/lxc/"$1"/tasks
|
/sys/fs/cgroup/cpuacct/sysdefault/lxc/"$guest_name"/tasks
|
||||||
do
|
do
|
||||||
if [ -e $SYSFS ]; then
|
if [ -e $SYSFS ]; then
|
||||||
return $(wc -l < $SYSFS)
|
wc -l <"$SYSFS"
|
||||||
|
return
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -e /usr/bin/cgm ]; then
|
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
|
fi
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -359,24 +362,23 @@ for n in $active_guests
|
||||||
do
|
do
|
||||||
device=$(lxc_netdev "$n")
|
device=$(lxc_netdev "$n")
|
||||||
if [ "$device" = "unknown" ]; then
|
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
|
fi
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
$(clean_fieldname "net__${n}_up").value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}')
|
$(clean_fieldname "net__${n}_up").value $value_up
|
||||||
$(clean_fieldname "net__${n}_down").value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}')
|
$(clean_fieldname "net__${n}_down").value $value_down
|
||||||
EOF
|
EOF
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "multigraph lxc_proc"
|
echo "multigraph lxc_proc"
|
||||||
for n in $active_guests
|
for n in $active_guests
|
||||||
do
|
do
|
||||||
lxc_count_processes "$n"
|
echo "$(clean_fieldname "lxc_proc__${n}").value $(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
|
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "multigraph lxc_ram"
|
echo "multigraph lxc_ram"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue