1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 09:57:09 +00:00
Munin-Contrib/plugins/lxc/lxc-lib
2019-08-11 23:09:15 +02:00

80 lines
1.6 KiB
Text

: << =cut
=head1 NAME
lxc-lib -- some base functions for the lxc_* plugins
=head1 AUTHOR
schaefer@alphanet.ch
=head1 LICENSE
GPLv3
=cut
lxcpath=${lxcpath:-/var/lib/lxc}
function active_guests {
local g active i ok
for g in $(lxc-ls | sort -u)
do
# handle optional exclude list in $1
ok=1
for i in $1
do
if [ "$i" = "$g" ]; then
ok=0
fi
done
if [ $ok = 1 ]; then
if lxc-info -n $g 2>&1 | grep -qs RUNNING; then
active="$active $g"
fi
fi
done
echo $active
}
function lxc_cgroup {
# lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir)
lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //'
}
function lxc_clean_fieldname {
# clean_fieldname should be used on the whole identifier, not just the
# lxc instance ID, because if it is only numeric, the first digit will
# be replaced with a "_"; this is a work-around
case "${1::1}" in
[0-9]) echo $(clean_fieldname ${1::1}$1);; # 104 -> __104
*) echo $(clean_fieldname $1);;
esac
}
function lxc_netdev {
local g=$1 dev
if [ -f $lxcpath/$g/config ]; then
# lxc 3 vs < 3
(egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \
|| egrep '^lxc.network.veth.pair' $lxcpath/$g/config
) | awk '{print $NF;}'
else
echo unknown
fi
}
# BUGS
# - I don't think this is enough or even appropriate
function lxc_autoconf {
if [ -r /proc/stat ]; then
echo yes
exit 0
else
echo "no (no /proc/stat)"
exit 0
fi
}