Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / lxc / lxc_cpu @ 8af08143

Historique | Voir | Annoter | Télécharger (1,6 ko)

1 e3c40a04 Bjoern Boschman
#!/bin/bash
2
# -*- sh -*-
3
4
: << =cut
5
6
=head1 NAME
7
8
lxc_cpu - Plugin to monitor LXC CPU usage
9
10
=head1 CONFIGURATION
11
12
  [lxc_*]
13
    user root
14
15
=head1 INTERPRETATION
16
17
This plugin needs root privilege.
18
19
=head1 AUTHOR
20
21
vajtsz  vajtsz@gmail.com
22
mitty   mitty@mitty.jp
23
24
=head1 LICENSE
25
26
Unknown license
27
28
=head1 MAGIC MARKERS
29
30
 #%# family=auto
31
 #%# capabilities=autoconf
32
33
=cut
34
35
. $MUNIN_LIBDIR/plugins/plugin.sh
36
37
guest_names=`lxc-ls | sort -u`
38
for guest in $guest_names; do
39
 if lxc-info -n $guest 2>&1 | grep -qs RUNNING ; then
40
  active="$active $guest"
41
 fi
42
done
43
guest_names="$active"
44
                
45
46
47
f_comm='lxc-cgroup  '
48
49
if [ "$1" = "autoconf" ]; then
50
	if [ -r /proc/stat ]; then
51
		echo yes
52
		exit 0
53
	else
54
		echo "no (no /proc/stat)"
55
		exit 0
56
	fi
57
fi
58
59
if [ "$1" = "config" ]; then
60
61
 echo 'graph_title CPU Usage '
62
 echo 'graph_args -l 0 --base 1000'
63
 echo 'graph_vlabel USER_HZ'
64
 echo 'graph_category lxc'
65
66
 
67
 for guest_name in $guest_names;
68
 do 
69
  guest="$(clean_fieldname $guest_name)"
70
  echo 'cpu_user_'$guest'.label '$guest_name': User'
71
  echo 'cpu_user_'$guest'.type DERIVE'
72
  echo 'cpu_user_'$guest'.min 0'
73
  echo 'cpu_system_'$guest'.label '$guest_name': System'
74
  echo 'cpu_system_'$guest'.type DERIVE'
75
  echo 'cpu_system_'$guest'.min 0'
76
 done
77
 exit 0
78
fi
79
80
 for guest_name in $guest_names;
81
 do 
82
  guest="$(clean_fieldname $guest_name)"
83
  
84
  tmp_g=`$f_comm -n $guest_name cpuacct.stat | grep user`
85
  tmp_v=`echo $tmp_g | awk '{print($2)}'`
86
  echo 'cpu_user_'$guest'.value '$tmp_v
87
  
88
  tmp_g=`$f_comm -n $guest_name cpuacct.stat | grep system`
89
  tmp_v=`echo $tmp_g | awk '{print($2)}'`
90
  echo 'cpu_system_'$guest'.value '$tmp_v
91
92
 done
93