mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-24 09:57:09 +00:00
115 lines
2.3 KiB
Bash
Executable file
115 lines
2.3 KiB
Bash
Executable file
#!/bin/bash
|
|
# -*- sh -*-
|
|
|
|
: << =cut
|
|
|
|
=head1 NAME
|
|
|
|
lxc_proc - Plugin to monitor LXC Processes count
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
env.cgrouppath - Set the path where 'tasks' sysfs files are stored, default: empty
|
|
|
|
[lxc_proc]
|
|
user root
|
|
env.cgrouppath /sys/fs/cgroup/cpuacct/lxc/
|
|
|
|
=head1 INTERPRETATION
|
|
|
|
This plugin needs root privilege.
|
|
|
|
=head1 AUTHOR
|
|
|
|
vajtsz vajtsz@gmail.com
|
|
(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)
|
|
|
|
## 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
|
|
|
|
if [ -n "$cgrouppath" ]; then
|
|
SYSFS=$cgrouppath/$1/tasks
|
|
if [ -e $SYSFS ]; then
|
|
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
|
|
if [ -e $SYSFS ]; then
|
|
return `wc -l < $SYSFS`
|
|
fi
|
|
done
|
|
|
|
if [ -e /usr/bin/cgm ]; then
|
|
return `cgm getvalue cpu lxc/$1 tasks 2>/dev/null | wc -l`
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
|
lxc_autoconf
|
|
fi
|
|
|
|
if [ "$1" = "config" ]; then
|
|
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 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
|