Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #488 from jesusch/master
added lxc plugins from https://github.com/vajtsz/munin-plugins
- Loading branch information
Showing
5 changed files
with
531 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
# -*- sh -*- | ||
|
||
: << =cut | ||
=head1 NAME | ||
lxc_cpu - Plugin to monitor LXC CPU usage | ||
=head1 CONFIGURATION | ||
[lxc_*] | ||
user root | ||
=head1 INTERPRETATION | ||
This plugin needs root privilege. | ||
=head1 AUTHOR | ||
vajtsz vajtsz@gmail.com | ||
mitty mitty@mitty.jp | ||
=head1 LICENSE | ||
Unknown license | ||
=head1 MAGIC MARKERS | ||
#%# family=auto | ||
#%# capabilities=autoconf | ||
=cut | ||
|
||
. $MUNIN_LIBDIR/plugins/plugin.sh | ||
|
||
guest_names=`lxc-ls | sort -u` | ||
for guest in $guest_names; do | ||
if lxc-info -n $guest 2>&1 | grep -qs RUNNING ; then | ||
active="$active $guest" | ||
fi | ||
done | ||
guest_names="$active" | ||
|
||
|
||
|
||
f_comm='lxc-cgroup ' | ||
|
||
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 | ||
|
||
echo 'graph_title CPU Usage ' | ||
echo 'graph_args -l 0 --base 1000' | ||
echo 'graph_vlabel USER_HZ' | ||
echo 'graph_category lxc' | ||
|
||
|
||
for guest_name in $guest_names; | ||
do | ||
guest="$(clean_fieldname $guest_name)" | ||
echo 'cpu_user_'$guest'.label '$guest_name': User' | ||
echo 'cpu_user_'$guest'.type DERIVE' | ||
echo 'cpu_user_'$guest'.min 0' | ||
echo 'cpu_system_'$guest'.label '$guest_name': System' | ||
echo 'cpu_system_'$guest'.type DERIVE' | ||
echo 'cpu_system_'$guest'.min 0' | ||
done | ||
exit 0 | ||
fi | ||
|
||
for guest_name in $guest_names; | ||
do | ||
guest="$(clean_fieldname $guest_name)" | ||
|
||
tmp_g=`$f_comm -n $guest_name cpuacct.stat | grep user` | ||
tmp_v=`echo $tmp_g | awk '{print($2)}'` | ||
echo 'cpu_user_'$guest'.value '$tmp_v | ||
|
||
tmp_g=`$f_comm -n $guest_name cpuacct.stat | grep system` | ||
tmp_v=`echo $tmp_g | awk '{print($2)}'` | ||
echo 'cpu_system_'$guest'.value '$tmp_v | ||
|
||
done | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
# -*- sh -*- | ||
|
||
: << =cut | ||
=head1 NAME | ||
lxc_cpu_time - Plugin to monitor LXC CPU time usage | ||
=head1 CONFIGURATION | ||
[lxc_*] | ||
user root | ||
=head1 INTERPRETATION | ||
This plugin needs root privilege. | ||
=head1 AUTHOR | ||
vajtsz vajtsz@gmail.com | ||
mitty mitty@mitty.jp | ||
=head1 LICENSE | ||
Unknown license | ||
=head1 MAGIC MARKERS | ||
#%# family=auto | ||
#%# capabilities=autoconf | ||
=cut | ||
|
||
. $MUNIN_LIBDIR/plugins/plugin.sh | ||
|
||
guest_names=`lxc-ls | sort -u` | ||
for guest in $guest_names; do | ||
if lxc-info -n $guest 2>&1 | grep -qs RUNNING ; then | ||
active="$active $guest" | ||
fi | ||
done | ||
guest_names="$active" | ||
|
||
|
||
f_comm='lxc-cgroup ' | ||
|
||
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 | ||
|
||
echo 'graph_title CPU time ' | ||
echo 'graph_args -l 0 --base 1000' | ||
echo 'graph_vlabel nanosec' | ||
echo 'graph_category lxc' | ||
|
||
for guest_name in $guest_names; | ||
do | ||
guest="$(clean_fieldname $guest_name)" | ||
echo 'cpu_time_'$guest'.label '$guest_name': CPU time' | ||
echo 'cpu_time_'$guest'.type DERIVE' | ||
echo 'cpu_time_'$guest'.min 0' | ||
done | ||
exit 0 | ||
fi | ||
|
||
for guest_name in $guest_names; | ||
do | ||
guest="$(clean_fieldname $guest_name)" | ||
tmp_g=`$f_comm -n $guest_name cpuacct.usage ` | ||
echo 'cpu_time_'$guest'.value '$tmp_g | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#!/bin/sh | ||
|
||
: << =cut | ||
=head1 NAME | ||
lxc_net - Munin plugin to graph traffic of active LXC containers. | ||
=head1 APPLICABLE SYSTEMS | ||
LXC container with "lxc.network.type=veth" and "lxc.network.veth.pair" settings. | ||
=head1 CONFIGURATION | ||
env.lxcpath - Set the path where LXC containers are stored, default: /var/lib/lxc | ||
env.exclude - Removing containers from graphs, default: empty | ||
[lxc_net] | ||
env.lxcpath /var/lib/lxc | ||
env.exclude container1 container2 | ||
=head1 INTERPRETATION | ||
This plugin reads a "lxc.network.veth.pair" setting from "config" file of each container, | ||
because lxc-start command creates a random named veth device without the setting. | ||
If your xen config (/var/lib/lxc/GUEST_NAME/config does not contain this parameter, | ||
then you have to fill it, becouse if every guest restart generate new device name, then the graph will be useless | ||
( example config : lxc.network.veth.pair = vethsamba ) | ||
=head1 AUTHOR | ||
mitty mitty@mitty.jp | ||
=head1 LICENSE | ||
2-clause BSD License | ||
=head1 MAGIC MARKERS | ||
#%# familiy=auto | ||
#%# capabilities=autoconf | ||
=cut | ||
|
||
. $MUNIN_LIBDIR/plugins/plugin.sh | ||
|
||
lxcpath=${lxcpath:-/var/lib/lxc} | ||
|
||
if [ "$1" = "autoconf" ]; then | ||
if [ ! -r /proc/net/dev ]; then | ||
echo "no (/proc/net/dev cannot be read)" | ||
exit 0 | ||
fi | ||
if [ ! -e "$lxcpath" ]; then | ||
echo "no ($lxcdir is not present)" | ||
exit 0 | ||
fi | ||
|
||
echo yes | ||
fi | ||
|
||
actives="" | ||
for guest in `ls $lxcpath`; do | ||
if [ `echo $exclude | grep -c "\b$guest\b"` -eq 1 ]; then | ||
continue; | ||
fi | ||
if [ -f "$lxcpath/$guest/config" ]; then | ||
device=`grep '^lxc\.network\.veth\.pair[ \t]*=[ \t]*' $lxcpath/$guest/config | \ | ||
awk '{ split($0, a, /=/); gsub(/[ \t]/, "", a[2]); print a[2]; }'` | ||
if [ -n "$device" ]; then | ||
device_re=`echo $device | sed -e 's/\./\\\\./g'` | ||
if [ `grep -c "^ *$device_re:" /proc/net/dev` -eq 1 ]; then | ||
actives="$actives $guest" | ||
eval "dev_$(clean_fieldname $guest)=$device" | ||
fi | ||
fi | ||
fi | ||
done | ||
|
||
if [ "$1" = "config" ]; then | ||
echo "graph_title Network traffic" | ||
echo "graph_args --base 1000" | ||
echo "graph_vlabel bits in (-) / out (+) per ${graph_period}" | ||
echo "graph_category lxc" | ||
echo "graph_info This graph shows the traffic of active LXC containers." | ||
|
||
for guestname in $actives; do | ||
guest=$(clean_fieldname $guestname) | ||
device=$(eval 'echo $dev_'$guest) | ||
bps="U" | ||
if [ -r /sys/class/net/$device/speed ]; then | ||
bps=$(cat /sys/class/net/$device/speed) | ||
bps=$(($bps * 1000 * 1000)) | ||
fi | ||
|
||
echo "${guest}_down.label $guestname" | ||
echo "${guest}_down.type DERIVE" | ||
echo "${guest}_down.graph no" | ||
echo "${guest}_down.cdef ${guest}_down,8,*" | ||
echo "${guest}_down.min 0" | ||
echo "${guest}_down.max $bps" | ||
echo "${guest}_up.label $guestname" | ||
echo "${guest}_up.type DERIVE" | ||
echo "${guest}_up.negative ${guest}_down" | ||
echo "${guest}_up.cdef ${guest}_up,8,*" | ||
echo "${guest}_up.min 0" | ||
echo "${guest}_up.max $bps" | ||
done | ||
exit 0 | ||
fi | ||
|
||
|
||
for guest in $actives; do | ||
guest=$(clean_fieldname $guest) | ||
device=$(eval 'echo $dev_'$guest) | ||
device_re=`echo $device | sed -e 's/\./\\\\./g'` | ||
line=`grep "^ *$device_re:" /proc/net/dev` | ||
echo -n "${guest}_down.value " | ||
echo $line | awk '{ | ||
split($0, a, /: */); | ||
print $2; | ||
}' | ||
echo -n "${guest}_up.value " | ||
echo $line | awk '{ | ||
split($0, a, /: */); | ||
print $10; | ||
}' | ||
done |
Oops, something went wrong.