mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-28 20:04:47 +00:00
lxc: working on buster (gandalf), and almost working on virtual (jessie), except lxc_net
This commit is contained in:
parent
0e0de01136
commit
ce6e67fffc
7 changed files with 371 additions and 303 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# -*- sh -*-
|
||||
|
||||
: << =cut
|
||||
|
@ -12,26 +12,20 @@ lxc_ram - Plugin to monitor LXC memory usage.
|
|||
[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
|
||||
|
||||
Unknown license
|
||||
2-clause BSD License
|
||||
or GPLv3 license, at your option
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
|
@ -40,83 +34,54 @@ Unknown license
|
|||
|
||||
=cut
|
||||
|
||||
. $MUNIN_LIBDIR/plugins/plugin.sh
|
||||
|
||||
# configurable: true/false
|
||||
areastack=${areastack:-false}
|
||||
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "$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 '
|
||||
|
||||
|
||||
do_autoconf() {
|
||||
if [ -r /proc/stat ]; then
|
||||
echo yes
|
||||
else
|
||||
echo "no (no /proc/stat)"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
do_config() {
|
||||
echo 'graph_title Memory '
|
||||
echo 'graph_args -l 0 --base 1024'
|
||||
echo 'graph_vlabel byte'
|
||||
echo 'graph_category memory'
|
||||
|
||||
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"
|
||||
if [ "$areastack" = "true" ]; then
|
||||
echo "mem_usage_$guest.draw AREASTACK"
|
||||
fi
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
do_fetch() {
|
||||
for guest_name in $guest_names; do
|
||||
guest="$(clean_fieldname "$guest_name")"
|
||||
|
||||
value=$($f_comm -n "$guest_name" memory.usage_in_bytes)
|
||||
echo "mem_usage_$guest.value $value"
|
||||
|
||||
value=$($f_comm -n "$guest_name" memory.stat | grep total_cache | awk '{print($2)}')
|
||||
echo "mem_cache_$guest.value $value"
|
||||
|
||||
value=$($f_comm -n "$guest_name" memory.stat | grep total_active_anon | awk '{print($2)}')
|
||||
echo "mem_active_$guest.value $value"
|
||||
|
||||
value=$($f_comm -n "$guest_name" memory.stat | grep total_inactive_anon | awk '{print($2)}')
|
||||
echo "mem_inactive_$guest.value $value"
|
||||
done
|
||||
}
|
||||
. $MUNIN_LIBDIR/plugins/lxc-lib
|
||||
|
||||
active_guests=$(active_guests)
|
||||
|
||||
if [ "$1" = "autoconf" ]; then
|
||||
do_autoconf
|
||||
elif [ "$1" = "config" ]; then
|
||||
do_config
|
||||
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = "1" ]; then do_fetch; fi
|
||||
else
|
||||
do_fetch
|
||||
if [ -r /proc/stat ]; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo "no (no /proc/stat)"
|
||||
exit 0
|
||||
fi
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue