1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Plugin lxc: fix quoting issues

This commit is contained in:
Lars Kruse 2019-08-12 00:38:38 +02:00
parent 0d593014b4
commit 89003f0188

View file

@ -81,7 +81,8 @@ or GPLv3 license or later, at your option
=cut =cut
. $MUNIN_LIBDIR/plugins/plugin.sh . "$MUNIN_LIBDIR/plugins/plugin.sh"
lxcpath=${lxcpath:-/var/lib/lxc} lxcpath=${lxcpath:-/var/lib/lxc}
# containers to be ignored # containers to be ignored
@ -106,14 +107,14 @@ function active_guests {
fi fi
done done
if [ $ok = 1 ]; then if [ "$ok" = 1 ]; then
if lxc-info -n $g 2>&1 | grep -qs RUNNING; then if lxc-info -n "$g" 2>&1 | grep -qs RUNNING; then
active="$active $g" active="$active $g"
fi fi
fi fi
done done
echo $active echo "$active"
} }
@ -126,10 +127,10 @@ function lxc_cgroup {
function lxc_netdev { function lxc_netdev {
local g=$1 dev local g=$1 dev
if [ -f $lxcpath/$g/config ]; then if [ -f "$lxcpath/$g/config" ]; then
# lxc 3 vs < 3 # lxc 3 vs < 3
(egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \ (egrep '^lxc.net.0.veth.pair' "$lxcpath/$g/config" 2>/dev/null \
|| egrep '^lxc.network.veth.pair' $lxcpath/$g/config || egrep '^lxc.network.veth.pair' "$lxcpath/$g/config"
) | awk '{print $NF;}' ) | awk '{print $NF;}'
else else
echo unknown echo unknown
@ -152,20 +153,20 @@ lxc_count_processes () {
if [ -n "$cgrouppath" ]; then if [ -n "$cgrouppath" ]; then
SYSFS="$cgrouppath/$guest_name/tasks" SYSFS="$cgrouppath/$guest_name/tasks"
if [ -e $SYSFS ]; then if [ -e "$SYSFS" ]; then
wc -l <"$SYSFS" wc -l <"$SYSFS"
return return
fi fi
fi fi
for SYSFS in \ for SYSFS in \
/sys/fs/cgroup/"$guest_name"/tasks \ "/sys/fs/cgroup/$guest_name/tasks" \
/sys/fs/cgroup/lxc/"$guest_name"/tasks \ "/sys/fs/cgroup/lxc/$guest_name/tasks" \
/sys/fs/cgroup/systemd/lxc/"$guest_name"/tasks \ "/sys/fs/cgroup/systemd/lxc/$guest_name/tasks" \
/sys/fs/cgroup/cpuacct/lxc/"$guest_name"/tasks \ "/sys/fs/cgroup/cpuacct/lxc/$guest_name/tasks" \
/sys/fs/cgroup/cpuacct/sysdefault/lxc/"$guest_name"/tasks "/sys/fs/cgroup/cpuacct/sysdefault/lxc/$guest_name/tasks"
do do
if [ -e $SYSFS ]; then if [ -e "$SYSFS" ]; then
wc -l <"$SYSFS" wc -l <"$SYSFS"
return return
fi fi
@ -212,7 +213,7 @@ EOF
for i in user system for i in user system
do do
cat <<EOF cat <<EOF
$(clean_fieldname "cpu_${i}__${n}").label $n: $(echo ${i:0:1} | tr "[:lower:]" "[:upper:]")${i:1} $(clean_fieldname "cpu_${i}__${n}").label $n: $(echo "${i:0:1}" | tr "[:lower:]" "[:upper:]")${i:1}
$(clean_fieldname "cpu_${i}__${n}").type DERIVE $(clean_fieldname "cpu_${i}__${n}").type DERIVE
$(clean_fieldname "cpu_${i}__${n}").min 0 $(clean_fieldname "cpu_${i}__${n}").min 0
EOF EOF
@ -269,8 +270,8 @@ EOF
continue continue
fi fi
bps="U" bps="U"
if [ -r /sys/class/net/$device/speed ]; then if [ -r "/sys/class/net/$device/speed" ]; then
bps=$(($(cat /sys/class/net/$device/speed) * 1000 * 1000)) bps=$(($(cat "/sys/class/net/$device/speed") * 1000 * 1000))
fi fi
cat <<EOF cat <<EOF
$(clean_fieldname "net__${n}_down").label $n $(clean_fieldname "net__${n}_down").label $n
@ -345,20 +346,20 @@ for n in $active_guests
do do
for i in user system for i in user system
do do
echo $(clean_fieldname "cpu_${i}__${n}").value $(lxc_cgroup -n "$n" cpuacct.stat | grep $i | awk '{ print $2; }') echo "$(clean_fieldname "cpu_${i}__${n}").value $(lxc_cgroup -n "$n" cpuacct.stat | grep "$i" | awk '{ print $2; }')"
done done
done done
echo "multigraph lxc_cpu_time" echo "multigraph lxc_cpu_time"
for n in $active_guests for n in $active_guests
do do
echo $(clean_fieldname "cpu_time__${n}").value $(lxc_cgroup -n "$n" cpuacct.usage) echo "$(clean_fieldname "cpu_time__${n}").value $(lxc_cgroup -n "$n" cpuacct.usage)"
done done
echo "multigraph lxc_logins" echo "multigraph lxc_logins"
for n in $active_guests for n in $active_guests
do do
echo $(clean_fieldname "logins__${n}").value $(lxc-attach -n "$n" users | wc -w) echo "$(clean_fieldname "logins__${n}").value $(lxc-attach -n "$n" users | wc -w)"
done done
echo "multigraph lxc_net" echo "multigraph lxc_net"