2014-05-30 17:55:55 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
lxc_ram - Plugin to monitor LXC memory 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 Memory '
|
|
|
|
echo 'graph_args -l 0 --base 1024'
|
|
|
|
echo 'graph_vlabel byte'
|
2017-02-22 05:34:14 +01:00
|
|
|
echo 'graph_category memory'
|
2014-05-30 17:55:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
for guest_name in $guest_names;
|
|
|
|
do
|
|
|
|
guest="$(clean_fieldname $guest_name)"
|
|
|
|
|
|
|
|
echo 'mem_usage_'$guest'.label '$guest_name': Mem usage'
|
|
|
|
echo 'mem_usage_'$guest'.type GAUGE'
|
|
|
|
echo 'mem_cache_'$guest'.label '$guest_name': Cache'
|
|
|
|
echo 'mem_cache_'$guest'.type GAUGE'
|
|
|
|
echo 'mem_active_'$guest'.label '$guest_name': Active'
|
|
|
|
echo 'mem_active_'$guest'.type GAUGE'
|
|
|
|
echo 'mem_inactive_'$guest'.label '$guest_name': Inactive'
|
|
|
|
echo 'mem_inactive_'$guest'.type GAUGE'
|
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
for guest_name in $guest_names;
|
|
|
|
do
|
|
|
|
guest="$(clean_fieldname $guest_name)"
|
|
|
|
|
|
|
|
tmp_v=`$f_comm -n $guest_name memory.usage_in_bytes`
|
|
|
|
echo 'mem_usage_'$guest'.value '$tmp_v
|
|
|
|
|
|
|
|
tmp_g=`$f_comm -n $guest_name memory.stat | grep total_cache`
|
|
|
|
tmp_v=`echo $tmp_g | awk '{print($2)}'`
|
|
|
|
echo 'mem_cache_'$guest'.value '$tmp_v
|
|
|
|
|
|
|
|
tmp_g=`$f_comm -n $guest_name memory.stat | grep total_active_anon`
|
|
|
|
tmp_v=`echo $tmp_g | awk '{print($2)}'`
|
|
|
|
echo 'mem_active_'$guest'.value '$tmp_v
|
|
|
|
|
|
|
|
tmp_g=`$f_comm -n $guest_name memory.stat | grep total_inactive_anon`
|
|
|
|
tmp_v=`echo $tmp_g | awk '{print($2)}'`
|
|
|
|
echo 'mem_inactive_'$guest'.value '$tmp_v
|
|
|
|
|
|
|
|
done
|