root / plugins / lxc / lxc_proc @ 17f78427
Historique | Voir | Annoter | Télécharger (2,37 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# -*- sh -*- |
| 3 |
|
| 4 |
: << =cut |
| 5 |
|
| 6 |
=head1 NAME |
| 7 |
|
| 8 |
lxc_proc - Plugin to monitor LXC Processes count |
| 9 |
|
| 10 |
=head1 CONFIGURATION |
| 11 |
|
| 12 |
env.cgrouppath - Set the path where 'tasks' sysfs files are stored, default: empty |
| 13 |
|
| 14 |
[lxc_proc] |
| 15 |
user root |
| 16 |
env.cgrouppath /sys/fs/cgroup/cpuacct/lxc/ |
| 17 |
|
| 18 |
=head1 INTERPRETATION |
| 19 |
|
| 20 |
This plugin needs root privilege. |
| 21 |
|
| 22 |
=head1 AUTHOR |
| 23 |
|
| 24 |
vajtsz vajtsz@gmail.com |
| 25 |
|
| 26 |
=head1 LICENSE |
| 27 |
|
| 28 |
Unknown license |
| 29 |
|
| 30 |
=head1 MAGIC MARKERS |
| 31 |
|
| 32 |
#%# family=auto |
| 33 |
#%# capabilities=autoconf |
| 34 |
|
| 35 |
=cut |
| 36 |
|
| 37 |
. $MUNIN_LIBDIR/plugins/plugin.sh |
| 38 |
|
| 39 |
## find proper sysfs and count it |
| 40 |
# Debian 6.0: /sys/fs/cgroup/<container>/tasks |
| 41 |
# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc/<container>/tasks |
| 42 |
# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc/<container>/tasks |
| 43 |
# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc/<container>/tasks |
| 44 |
# Ubuntu 14.04: /sys/fs/cgroup/systemd/lxc/<container>/tasks |
| 45 |
count_processes () {
|
| 46 |
[ -z "$1" ] && return 0 |
| 47 |
|
| 48 |
if [ -n "$cgrouppath" ]; then |
| 49 |
SYSFS=$cgrouppath/$1/tasks |
| 50 |
if [ -e $SYSFS ]; then |
| 51 |
return `wc -l < $SYSFS` |
| 52 |
fi |
| 53 |
fi |
| 54 |
|
| 55 |
for SYSFS in \ |
| 56 |
/sys/fs/cgroup/$1/tasks \ |
| 57 |
/sys/fs/cgroup/lxc/$1/tasks \ |
| 58 |
/sys/fs/cgroup/systemd/lxc/$1/tasks \ |
| 59 |
/sys/fs/cgroup/cpuacct/lxc/$1/tasks \ |
| 60 |
/sys/fs/cgroup/cpuacct/sysdefault/lxc/$1/tasks \ |
| 61 |
; do |
| 62 |
if [ -e $SYSFS ]; then |
| 63 |
return `wc -l < $SYSFS` |
| 64 |
fi |
| 65 |
done |
| 66 |
|
| 67 |
return 0 |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
guest_names=`lxc-ls | sort -u` |
| 72 |
for guest in $guest_names; do |
| 73 |
if lxc-info -n $guest 2>&1 | grep -qs RUNNING ; then |
| 74 |
active="$active $guest" |
| 75 |
fi |
| 76 |
done |
| 77 |
guest_names="$active" |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
f_comm='lxc-cgroup ' |
| 82 |
|
| 83 |
if [ "$1" = "autoconf" ]; then |
| 84 |
if [ -r /proc/stat ]; then |
| 85 |
echo yes |
| 86 |
exit 0 |
| 87 |
else |
| 88 |
echo "no (no /proc/stat)" |
| 89 |
exit 0 |
| 90 |
fi |
| 91 |
fi |
| 92 |
|
| 93 |
if [ "$1" = "config" ]; then |
| 94 |
|
| 95 |
echo 'graph_title Processes ' |
| 96 |
echo 'graph_args -l 0 --base 1000' |
| 97 |
echo 'graph_vlabel Number of processes' |
| 98 |
echo 'graph_category processes' |
| 99 |
|
| 100 |
|
| 101 |
for guest_name in $guest_names; do |
| 102 |
guest="$(clean_fieldname $guest_name)" |
| 103 |
echo 'lxc_proc_'$guest'.label '$guest_name': processes' |
| 104 |
echo 'lxc_proc_'$guest'.type GAUGE' |
| 105 |
echo 'lxc_proc_'$guest'.min 0' |
| 106 |
done |
| 107 |
exit 0 |
| 108 |
fi |
| 109 |
|
| 110 |
for guest_name in $guest_names; do |
| 111 |
guest="$(clean_fieldname $guest_name)" |
| 112 |
|
| 113 |
count_processes $guest_name |
| 114 |
tmp_g=$? |
| 115 |
if [ $tmp_g -eq 0 ]; then |
| 116 |
tmp_g=`$f_comm -n $guest_name tasks | wc -l` |
| 117 |
fi |
| 118 |
echo 'lxc_proc_'$guest'.value '$tmp_g |
| 119 |
|
| 120 |
|
| 121 |
done |
| 122 |
|
| 123 |
|
