mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-24 18:07:20 +00:00
116 lines
2.4 KiB
Bash
Executable file
116 lines
2.4 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
: << =cut
|
|
|
|
=head1 NAME
|
|
|
|
lxc_net - Munin plugin to graph traffic of active LXC containers.
|
|
|
|
=head1 APPLICABLE SYSTEMS
|
|
|
|
LXC container with "lxc.network.type=veth" and "lxc.network.veth.pair" settings.
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
env.lxcpath - Set the path where LXC containers are stored, default: /var/lib/lxc
|
|
env.exclude - Removing containers from graphs, default: empty
|
|
|
|
[lxc_net]
|
|
env.lxcpath /var/lib/lxc
|
|
env.exclude container1 container2
|
|
|
|
=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, 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
|
|
|
|
#%# family=auto
|
|
#%# capabilities=autoconf
|
|
|
|
=cut
|
|
|
|
. $MUNIN_LIBDIR/plugins/plugin.sh
|
|
|
|
. $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
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$1" = "config" ]; then
|
|
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
|
|
|
|
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
|
|
|