root / plugins / lxc / lxc_proc @ 2ce1b321
Historique | Voir | Annoter | Télécharger (2,41 ko)
| 1 | e3c40a04 | Bjoern Boschman | #!/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 | 1c917e64 | Adrian Moisey | # Ubuntu 14.04: /sys/fs/cgroup/systemd/lxc/<container>/tasks |
| 45 | e3c40a04 | Bjoern Boschman | 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 | 1c917e64 | Adrian Moisey | /sys/fs/cgroup/systemd/lxc/$1/tasks \ |
| 59 | e3c40a04 | Bjoern Boschman | /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 | ff883dee | dipohl | echo 'graph_category processes' |
| 99 | e3c40a04 | Bjoern Boschman | |
| 100 | |||
| 101 | for guest_name in $guest_names; |
||
| 102 | do |
||
| 103 | guest="$(clean_fieldname $guest_name)" |
||
| 104 | echo 'lxc_proc_'$guest'.label '$guest_name': processes' |
||
| 105 | echo 'lxc_proc_'$guest'.type GAUGE' |
||
| 106 | echo 'lxc_proc_'$guest'.min 0' |
||
| 107 | done |
||
| 108 | exit 0 |
||
| 109 | fi |
||
| 110 | |||
| 111 | for guest_name in $guest_names; |
||
| 112 | do |
||
| 113 | guest="$(clean_fieldname $guest_name)" |
||
| 114 | |||
| 115 | count_processes $guest_name |
||
| 116 | tmp_g=$? |
||
| 117 | if [ $tmp_g -eq 0 ]; then |
||
| 118 | tmp_g=`$f_comm -n $guest_name tasks | wc -l` |
||
| 119 | fi |
||
| 120 | echo 'lxc_proc_'$guest'.value '$tmp_g |
||
| 121 | |||
| 122 | |||
| 123 | done |
||
| 124 |
