1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 09:57:09 +00:00
Munin-Contrib/plugins/lxc/lxc_ram
2019-08-11 23:09:15 +02:00

98 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
# -*- sh -*-
: << =cut
=head1 NAME
lxc_ram - Plugin to monitor LXC memory usage.
=head1 CONFIGURATION
[lxc_*]
user root
[lxc_ram]
env.areastack true
=head1 INTERPRETATION
This plugin needs root privilege.
If env.areastack is set to true, all memory usages of containers will be
drawn as stacked area charts.
This option changes graph order, all of 'Mem usage' comes first and then others.
(default: false)
=head1 AUTHOR
vajtsz vajtsz@gmail.com
mitty mitty@mitty.jp
(many changes schaefer@alphanet.ch)
=head1 LICENSE
2-clause BSD License
or GPLv3 license, at your option
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
. $MUNIN_LIBDIR/plugins/lxc-lib
active_guests=$(active_guests)
# configurable: true/false
areastack=${areastack:-false}
if [ "$1" = "autoconf" ]; then
lxc_autoconf
fi
if [ "$1" = "config" ]; then
cat <<EOF
graph_title Memory
graph_args -l 0 --base 1024
graph_vlabel byte
graph_category lxc
EOF
for n in $active_guests
do
g=$(lxc_clean_fieldname $n)
cat <<EOF
mem_usage_${g}.label ${n}: Mem usage
mem_usage_${g}.type GAUGE
<<EOF
if [ "$areastack" = "true" ]; then
echo "mem_usage_${g}.draw AREASTACK"
fi
cat <<EOF
mem_cache_${g}.label ${n}: Cache
mem_cache_${g}.type GAUGE
mem_active_${g}.label ${n}: Active
mem_active_${g}.type GAUGE
mem_inactive_${g}.label ${n}: Inactive
mem_inactive_${g}.type GAUGE
EOF
done
exit 0
fi
for n in $active_guests
do
g=$(lxc_clean_fieldname $n)
cat <<EOF
mem_usage_${g}.value $(lxc_cgroup -n $n memory.usage_in_bytes)
mem_cache_${g}.value $(lxc_cgroup -n $n memory.stat | grep total_cache | awk '{print $2;}')
mem_active_${g}.value $(lxc_cgroup -n $n memory.stat | grep total_active_anon | awk '{print $2;}')
mem_inactive_${g}.value $(lxc_cgroup -n $n memory.stat | grep total_inactive_anon | awk '{print $2;}')
EOF
done