mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-29 20:34:51 +00:00
lxc: working on buster (gandalf), and almost working on virtual (jessie), except lxc_net
This commit is contained in:
parent
0e0de01136
commit
ce6e67fffc
7 changed files with 371 additions and 303 deletions
|
@ -22,110 +22,95 @@ env.exclude - Removing containers from graphs, default: empty
|
|||
=head1 INTERPRETATION
|
||||
|
||||
This plugin reads a "lxc.network.veth.pair" setting from "config" file of each container,
|
||||
because lxc-start command creates a random named veth device without the setting.
|
||||
|
||||
If your xen config (/var/lib/lxc/GUEST_NAME/config does not contain this parameter,
|
||||
then you have to fill it, because if every guest restart generate new device name, then the graph will be useless
|
||||
( example config : lxc.network.veth.pair = vethsamba )
|
||||
because lxc-start command creates a random named veth device without the setting, which
|
||||
changes at each run.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
mitty mitty@mitty.jp
|
||||
(many changes schaefer@alphanet.ch)
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
2-clause BSD License
|
||||
or GPLv3 license, at your option
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# familiy=auto
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
=cut
|
||||
|
||||
. $MUNIN_LIBDIR/plugins/plugin.sh
|
||||
|
||||
lxcpath=${lxcpath:-/var/lib/lxc}
|
||||
. $MUNIN_LIBDIR/plugins/lxc-lib
|
||||
|
||||
active_guests=$(active_guests $exclude)
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
if [ ! -r /proc/net/dev ]; then
|
||||
echo "no (/proc/net/dev cannot be read)"
|
||||
exit 0
|
||||
fi
|
||||
if [ ! -e "$lxcpath" ]; then
|
||||
echo "no ($lxcdir is not present)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo yes
|
||||
if [ ! -r /proc/net/dev ]; then
|
||||
echo "no (/proc/net/dev cannot be read)"
|
||||
exit 0
|
||||
fi
|
||||
if [ ! -e "$lxcpath" ]; then
|
||||
echo "no ($lxcdir is not present)"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo yes
|
||||
exit 0
|
||||
fi
|
||||
|
||||
actives=""
|
||||
for guest in `ls $lxcpath`; do
|
||||
if [ `echo $exclude | grep -c "\b$guest\b"` -eq 1 ]; then
|
||||
continue;
|
||||
fi
|
||||
if [ -f "$lxcpath/$guest/config" ]; then
|
||||
devices=`grep '^lxc\.network\.veth\.pair[ \t]*=[ \t]*' $lxcpath/$guest/config | \
|
||||
awk '{ split($0, a, /=/); gsub(/[ \t]/, "", a[2]); print a[2]; }'`
|
||||
if [ -n "$devices" ]; then
|
||||
for device in $devices; do
|
||||
device_re=`echo $device | sed -e 's/\./\\\\./g'`
|
||||
if [ `grep -c "^ *$device_re:" /proc/net/dev` -eq 1 ]; then
|
||||
actives="$actives $guest"
|
||||
eval "dev_$(clean_fieldname $guest)=$device"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title Network traffic"
|
||||
echo "graph_args --base 1000"
|
||||
echo "graph_vlabel bits in (-) / out (+) per ${graph_period}"
|
||||
echo "graph_category network"
|
||||
echo "graph_info This graph shows the traffic of active LXC containers."
|
||||
|
||||
for guestname in $actives; do
|
||||
guest=$(clean_fieldname $guestname)
|
||||
device=$(eval 'echo $dev_'$guest)
|
||||
bps="U"
|
||||
if [ -r /sys/class/net/$device/speed ]; then
|
||||
bps=$(cat /sys/class/net/$device/speed)
|
||||
bps=$(($bps * 1000 * 1000))
|
||||
fi
|
||||
|
||||
echo "${guest}_down.label $guestname"
|
||||
echo "${guest}_down.type DERIVE"
|
||||
echo "${guest}_down.graph no"
|
||||
echo "${guest}_down.cdef ${guest}_down,8,*"
|
||||
echo "${guest}_down.min 0"
|
||||
echo "${guest}_down.max $bps"
|
||||
echo "${guest}_up.label $guestname"
|
||||
echo "${guest}_up.type DERIVE"
|
||||
echo "${guest}_up.negative ${guest}_down"
|
||||
echo "${guest}_up.cdef ${guest}_up,8,*"
|
||||
echo "${guest}_up.min 0"
|
||||
echo "${guest}_up.max $bps"
|
||||
cat <<EOF
|
||||
graph_title Network traffic
|
||||
graph_args --base 1000
|
||||
graph_vlabel bits in (-) / out (+) per ${graph_period}
|
||||
graph_category lxc
|
||||
graph_info This graph shows the traffic of active LXC containers.
|
||||
EOF
|
||||
|
||||
for n in $active_guests
|
||||
do
|
||||
g=$(lxc_clean_fieldname $n)
|
||||
device=$(lxc_netdev $n)
|
||||
if [ "$device" = "unknown" ]; then
|
||||
continue
|
||||
fi
|
||||
bps="U"
|
||||
if [ -r /sys/class/net/$device/speed ]; then
|
||||
bps=$(($(cat /sys/class/net/$device/speed) * 1000 * 1000))
|
||||
fi
|
||||
cat <<EOF
|
||||
net_${g}_down.label $n
|
||||
net_${g}_down.type DERIVE
|
||||
net_${g}_down.graph no
|
||||
net_${g}_down.cdef net_${g}_down,8,*
|
||||
net_${g}_down.min 0
|
||||
net_${g}_down.max $bps
|
||||
net_${g}_up.label $n
|
||||
net_${g}_up.type DERIVE
|
||||
net_${g}_up.negative net_${g}_down
|
||||
net_${g}_up.cdef net_${g}_up,8,*
|
||||
net_${g}_up.min 0
|
||||
net_${g}_up.max $bps
|
||||
EOF
|
||||
done
|
||||
exit 0
|
||||
fi
|
||||
|
||||
for n in $active_guests
|
||||
do
|
||||
g=$(lxc_clean_fieldname $n)
|
||||
device=$(lxc_netdev $n)
|
||||
if [ "$device" = "unknown" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
for guest in $actives; do
|
||||
guest=$(clean_fieldname $guest)
|
||||
device=$(eval 'echo $dev_'$guest)
|
||||
device_re=`echo $device | sed -e 's/\./\\\\./g'`
|
||||
line=`grep "^ *$device_re:" /proc/net/dev`
|
||||
echo -n "${guest}_down.value "
|
||||
echo $line | awk '{
|
||||
split($0, a, /: */);
|
||||
print $2;
|
||||
}'
|
||||
echo -n "${guest}_up.value "
|
||||
echo $line | awk '{
|
||||
split($0, a, /: */);
|
||||
print $10;
|
||||
}'
|
||||
cat <<EOF
|
||||
net_${g}_up.value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}')
|
||||
net_${g}_down.value $(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}')
|
||||
EOF
|
||||
done
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue