#!/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//tasks # Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks # Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc//tasks # Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc//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/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 if [ -r /proc/stat ]; then echo yes exit 0 else echo "no (no /proc/stat)" exit 0 fi fi if [ "$1" = "config" ]; then cat <