1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-30 21:04:59 +00:00

lxc: working on buster (gandalf), and almost working on virtual (jessie), except lxc_net

This commit is contained in:
Marc SCHAEFER 2019-08-10 11:33:27 +02:00 committed by Lars Kruse
parent 0e0de01136
commit ce6e67fffc
7 changed files with 371 additions and 303 deletions

View file

@ -22,10 +22,12 @@ This plugin needs root privilege.
=head1 AUTHOR
vajtsz vajtsz@gmail.com
(many changes schaefer@alphanet.ch)
=head1 LICENSE
Unknown license
2-clause BSD License
or GPLv3 license, at your option
=head1 MAGIC MARKERS
@ -36,12 +38,16 @@ Unknown license
. $MUNIN_LIBDIR/plugins/plugin.sh
. $MUNIN_LIBDIR/plugins/lxc-lib
active_guests=$(active_guests)
## find proper sysfs and count it
# Debian 6.0: /sys/fs/cgroup/<container>/tasks
# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc/<container>/tasks
# Ubuntu 14.04: /sys/fs/cgroup/systemd/lxc/<container>/tasks
# and with cgmanager on jessie
count_processes () {
[ -z "$1" ] && return 0
@ -51,11 +57,10 @@ count_processes () {
return `wc -l < $SYSFS`
fi
fi
for SYSFS in \
/sys/fs/cgroup/$1/tasks \
/sys/fs/cgroup/lxc/$1/tasks \
/sys/fs/cgroup/systemd/lxc/$1/tasks \
/sys/fs/cgroup/cpuacct/lxc/$1/tasks \
/sys/fs/cgroup/cpuacct/sysdefault/lxc/$1/tasks \
; do
@ -64,60 +69,51 @@ count_processes () {
fi
done
if [ -e /usr/bin/cgm ]; then
return `cgm getvalue cpu lxc/$1 tasks 2>/dev/null | wc -l`
fi
return 0
}
guest_names=`lxc-ls | sort -u`
for guest in $guest_names; do
if lxc-info -n $guest 2>&1 | grep -qs RUNNING ; then
active="$active $guest"
fi
done
guest_names="$active"
f_comm='lxc-cgroup '
if [ "$1" = "autoconf" ]; then
if [ -r /proc/stat ]; then
echo yes
exit 0
else
echo "no (no /proc/stat)"
exit 0
fi
if [ -r /proc/stat ]; then
echo yes
exit 0
else
echo "no (no /proc/stat)"
exit 0
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Processes '
echo 'graph_args -l 0 --base 1000'
echo 'graph_vlabel Number of processes'
echo 'graph_category processes'
for guest_name in $guest_names; do
guest="$(clean_fieldname $guest_name)"
echo 'lxc_proc_'$guest'.label '$guest_name': processes'
echo 'lxc_proc_'$guest'.type GAUGE'
echo 'lxc_proc_'$guest'.min 0'
done
exit 0
cat <<EOF
graph_title Processes
graph_args -l 0 --base 1000
graph_vlabel Number of processes
graph_category lxc
EOF
for n in $active_guests
do
g=$(lxc_clean_fieldname $n)
cat <<EOF
lxc_proc_${g}.label $n: processes
lxc_proc_${g}.type GAUGE
lxc_proc_${g}.min 0
EOF
done
exit 0
fi
for guest_name in $guest_names; do
guest="$(clean_fieldname $guest_name)"
count_processes $guest_name
tmp_g=$?
if [ $tmp_g -eq 0 ]; then
tmp_g=`$f_comm -n $guest_name tasks | wc -l`
fi
echo 'lxc_proc_'$guest'.value '$tmp_g
done
for n in $active_guests
do
g=$(lxc_clean_fieldname $n)
count_processes $n
tmp_g=$?
if [ $tmp_g -eq 0 ]; then
tmp_g=$(lxc_cgroup -n $n tasks | wc -l)
fi
echo "lxc_proc_${g}.value $tmp_g"
done