2018-06-10 14:42:10 +02:00
|
|
|
#!/bin/sh
|
2014-05-30 17:55:55 +02:00
|
|
|
# -*- sh -*-
|
|
|
|
|
|
|
|
: << =cut
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
lxc_ram - Plugin to monitor LXC memory usage.
|
|
|
|
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
|
|
|
|
[lxc_*]
|
|
|
|
user root
|
|
|
|
|
2013-05-08 16:51:44 +02:00
|
|
|
[lxc_ram]
|
2016-07-31 14:42:32 +02:00
|
|
|
env.areastack true
|
2013-05-08 16:51:44 +02:00
|
|
|
|
2014-05-30 17:55:55 +02:00
|
|
|
=head1 INTERPRETATION
|
|
|
|
|
|
|
|
This plugin needs root privilege.
|
|
|
|
|
2016-07-31 14:42:32 +02:00
|
|
|
If env.areastack is set to true, all memory usages of containers will be
|
2013-05-08 16:51:44 +02:00
|
|
|
drawn as stacked area charts.
|
|
|
|
This option changes graph order, all of 'Mem usage' comes first and then others.
|
2016-07-31 14:42:32 +02:00
|
|
|
(default: false)
|
2013-05-08 16:51:44 +02:00
|
|
|
|
2014-05-30 17:55:55 +02:00
|
|
|
=head1 AUTHOR
|
|
|
|
|
|
|
|
vajtsz vajtsz@gmail.com
|
|
|
|
mitty mitty@mitty.jp
|
|
|
|
|
|
|
|
=head1 LICENSE
|
|
|
|
|
|
|
|
Unknown license
|
|
|
|
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
|
|
|
|
#%# family=auto
|
|
|
|
#%# capabilities=autoconf
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
|
2018-06-10 14:41:53 +02:00
|
|
|
# configurable: true/false
|
|
|
|
areastack=${areastack:-false}
|
|
|
|
|
|
|
|
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
. "$MUNIN_LIBDIR/plugins/plugin.sh"
|
|
|
|
|
|
|
|
|
|
|
|
guest_names=$(lxc-ls | sort -u)
|
2014-05-30 17:55:55 +02:00
|
|
|
for guest in $guest_names; do
|
2018-06-10 14:47:00 +02:00
|
|
|
if lxc-info -n "$guest" 2>&1 | grep -qs RUNNING ; then
|
|
|
|
active="$active $guest"
|
|
|
|
fi
|
2014-05-30 17:55:55 +02:00
|
|
|
done
|
|
|
|
guest_names="$active"
|
2018-06-10 14:47:00 +02:00
|
|
|
|
2014-05-30 17:55:55 +02:00
|
|
|
|
|
|
|
f_comm='lxc-cgroup '
|
|
|
|
|
|
|
|
if [ "$1" = "autoconf" ]; then
|
2018-06-10 14:47:00 +02:00
|
|
|
if [ -r /proc/stat ]; then
|
|
|
|
echo yes
|
|
|
|
else
|
|
|
|
echo "no (no /proc/stat)"
|
|
|
|
fi
|
|
|
|
exit 0
|
2014-05-30 17:55:55 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$1" = "config" ]; then
|
2018-06-10 14:47:00 +02:00
|
|
|
echo 'graph_title Memory '
|
|
|
|
echo 'graph_args -l 0 --base 1024'
|
|
|
|
echo 'graph_vlabel byte'
|
|
|
|
echo 'graph_category memory'
|
|
|
|
|
|
|
|
if [ "$areastack" = "true" ]; then
|
|
|
|
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_usage_$guest.draw AREASTACK"
|
|
|
|
done
|
|
|
|
|
|
|
|
for guest_name in $guest_names; do
|
|
|
|
guest="$(clean_fieldname "$guest_name")"
|
|
|
|
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
|
|
|
|
else
|
|
|
|
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
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
2014-05-30 17:55:55 +02:00
|
|
|
|
2013-05-08 16:51:44 +02:00
|
|
|
|
2018-06-10 14:47:00 +02:00
|
|
|
for guest_name in $guest_names; do
|
2018-06-10 14:41:53 +02:00
|
|
|
guest="$(clean_fieldname "$guest_name")"
|
2014-05-30 17:55:55 +02:00
|
|
|
|
2018-06-10 14:47:00 +02:00
|
|
|
value=$($f_comm -n "$guest_name" memory.usage_in_bytes)
|
|
|
|
echo "mem_usage_$guest.value $value"
|
2017-03-04 16:19:58 +01:00
|
|
|
|
2018-06-10 14:47:00 +02:00
|
|
|
value=$($f_comm -n "$guest_name" memory.stat | grep total_cache | awk '{print($2)}')
|
|
|
|
echo "mem_cache_$guest.value $value"
|
2014-05-30 17:55:55 +02:00
|
|
|
|
2018-06-10 14:47:00 +02:00
|
|
|
value=$($f_comm -n "$guest_name" memory.stat | grep total_active_anon | awk '{print($2)}')
|
|
|
|
echo "mem_active_$guest.value $value"
|
2014-05-30 17:55:55 +02:00
|
|
|
|
2018-06-10 14:47:00 +02:00
|
|
|
value=$($f_comm -n "$guest_name" memory.stat | grep total_inactive_anon | awk '{print($2)}')
|
|
|
|
echo "mem_inactive_$guest.value $value"
|
2018-06-10 14:41:53 +02:00
|
|
|
done
|