1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-21 18:41:03 +00:00

Merge branch 'lxc-multigraph'

Many contributions from Marc Schaefer and Lars Kruse.
This commit is contained in:
Lars Kruse 2019-08-19 19:05:54 +02:00
commit a040cb5abe
6 changed files with 416 additions and 549 deletions

View file

@ -1,92 +0,0 @@
#!/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 cpu'
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

View file

@ -1,81 +0,0 @@
#!/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 cpu'
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

416
plugins/lxc/lxc_guests Executable file
View file

@ -0,0 +1,416 @@
#!/bin/sh
# -*- sh -*-
: << =cut
=head1 NAME
lxc_guests - collect statistics about containers virtualized via LXC
=head1 CONFIGURATION
[lxc_guests]
user root
# The memory usage of containers are by default drawn as stacked area
# charts. Alternatively a non-stacked graph with lines can be configured.
# Default: true
#env.ram_display_stacked true
# lxc container path, default below
#env.lxcpath /var/lib/lxc
# exclude the following containers
# (default none excluded)
#env.exclude container1 container2
# path where tasks sysfs files are stored,
# set this if the various attempts in the
# code don't work
# (default none)
#env.cgrouppath /sys/fs/cgroup/cpuacct/lxc/
=head1 INTERPRETATION
This plugin needs root privilege.
This plugin has been tested with lxc 3 and
lx2 (on Debian buster and Debian jessie,
respectively).
For the network graphs to work, you need
to have in every container's config file
a line defining the virtual network interface
path (else lxc will use a random name at
each container's start); see the lxc_netdev()
function below.
If using lxc 2, make sure you do not have cruft
in your container config files, you can test
it with:
lxc-cgroup -o /dev/stdout -l INFO -n 104 cpuacct.usage
-- with 104 a valid lxc instance), if you
get a warning, fix the config file.
For the logins graph, the "users" command is required in each
container.
Tested on Debian buster and Debian jessie.
=head1 AUTHOR
vajtsz vajtsz@gmail.com
mitty mitty@mitty.jp
alphanet schaefer@alphanet.ch (many changes and multigraph)
Lars Kruse <devel@sumpfralle.de>
=head1 LICENSE
2-clause BSD License
or GPLv3 license or later, at your option
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
set -eu
. "$MUNIN_LIBDIR/plugins/plugin.sh"
lxcpath=${lxcpath:-/var/lib/lxc}
# containers to be ignored
exclude=${exclude:-}
ram_display_stacked=${ram_display_stacked:-true}
# try to guess the location, if empty
cgrouppath=${cgrouppath:-}
# --- FUNCTIONS
get_active_guests() {
local excludes="$1"
local guest_name
for guest_name in $(lxc-ls)
do
# handle optional exclude list in $1
if ! echo "$excludes" | grep -qwF "$guest_name"; then
if lxc-info -n "$guest_name" --state 2>/dev/null | grep -qw RUNNING; then
echo "$guest_name"
fi
fi
done
}
get_lxc_cgroup_info() {
local guest_name="$1"
local field="$2"
# lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir)
lxc-cgroup -o /dev/stdout -l INFO -n "$guest_name" "$field" | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //'
}
lxc_netdev() {
local guest_name="$1"
if [ -f "$lxcpath/$guest_name/config" ]; then
# lxc 3 vs < 3
(grep -E '^lxc.net.0.veth.pair' "$lxcpath/$guest_name/config" 2>/dev/null \
|| grep -E '^lxc.network.veth.pair' "$lxcpath/$guest_name/config"
) | awk '{print $NF;}'
fi
}
# find proper sysfs and count it
# Debian 6.0: /sys/fs/cgroup/<container>/tasks
# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc/<container>/tasks
# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc/<container>/tasks
# and with cgmanager on jessie
lxc_count_processes () {
local guest_name="$1"
local SYSFS
[ -z "$guest_name" ] && return 0
if [ -n "$cgrouppath" ]; then
SYSFS="$cgrouppath/$guest_name/tasks"
if [ -e "$SYSFS" ]; then
wc -l <"$SYSFS"
return
fi
fi
for SYSFS in \
"/sys/fs/cgroup/$guest_name/tasks" \
"/sys/fs/cgroup/lxc/$guest_name/tasks" \
"/sys/fs/cgroup/cpuacct/lxc/$guest_name/tasks" \
"/sys/fs/cgroup/systemd/lxc/$guest_name/tasks" \
"/sys/fs/cgroup/cpuacct/sysdefault/lxc/$guest_name/tasks"
do
if [ -e "$SYSFS" ]; then
wc -l <"$SYSFS"
return
fi
done
if [ -e /usr/bin/cgm ]; then
cgm getvalue cpu "lxc/$guest_name" tasks 2>/dev/null | wc -l
else
get_lxc_cgroup_info "$guest_name" "tasks" | wc -l
fi
}
# change the first character of a string to upper case
title_case() {
local text="$1"
printf "%s%s" "$(echo "$text" | cut -c 1 | tr "[:lower:]" "[:upper:]")" "$(echo "$text" | cut -c 2-)"
}
do_autoconf() {
if [ ! -r /proc/net/dev ]; then
echo "no (/proc/net/dev cannot be read)"
elif [ ! -e "$lxcpath" ]; then
echo "no ($lxcpath is not present)"
elif [ -z "$(which lxc-ls)" ]; then
echo "no ('lxc-ls' is not available in PATH)"
else
echo yes
fi
}
do_config() {
local active_guests guest_name draw_style
active_guests=$(get_active_guests "$exclude")
cat <<EOF
multigraph lxc_cpu
graph_title CPU Usage
graph_args -l 0 --base 1000
graph_vlabel USER_HZ
graph_category virtualization
EOF
for guest_name in $active_guests
do
for cpu_usage in user system
do
cat <<EOF
$(clean_fieldname "cpu_${cpu_usage}_${guest_name}").label $guest_name: $(title_case "$cpu_usage")
$(clean_fieldname "cpu_${cpu_usage}_${guest_name}").type DERIVE
$(clean_fieldname "cpu_${cpu_usage}_${guest_name}").min 0
EOF
done
done
cat <<EOF
multigraph lxc_cpu_time
graph_title CPU time
graph_args -l 0 --base 1000
graph_vlabel nanosec
graph_category virtualization
EOF
for guest_name in $active_guests
do
cat <<EOF
$(clean_fieldname "cpu_time_${guest_name}").label $guest_name: CPU time
$(clean_fieldname "cpu_time_${guest_name}").type DERIVE
$(clean_fieldname "cpu_time_${guest_name}").min 0
EOF
done
cat <<EOF
multigraph lxc_logins
graph_title Logins
graph_category virtualization
EOF
for guest_name in $active_guests
do
cat <<EOF
$(clean_fieldname "logins_${guest_name}").label $guest_name: logins
$(clean_fieldname "logins_${guest_name}").type GAUGE
EOF
done
cat <<EOF
multigraph lxc_net
graph_title Network traffic
graph_args --base 1000
graph_vlabel bits in (-) / out (+) per \${graph_period}
graph_category virtualization
graph_info This graph shows the traffic of active LXC containers.
EOF
for guest_name in $active_guests
do
device=$(lxc_netdev "$guest_name")
if [ -z "$device" ]; then
continue
fi
cat <<EOF
$(clean_fieldname "net_${guest_name}_down").label $guest_name
$(clean_fieldname "net_${guest_name}_down").type DERIVE
$(clean_fieldname "net_${guest_name}_down").graph no
$(clean_fieldname "net_${guest_name}_down").cdef $(clean_fieldname "net_${guest_name}_down"),8,*
$(clean_fieldname "net_${guest_name}_down").min 0
$(clean_fieldname "net_${guest_name}_up").label $guest_name
$(clean_fieldname "net_${guest_name}_up").type DERIVE
$(clean_fieldname "net_${guest_name}_up").negative $(clean_fieldname "net_${guest_name}_down")
$(clean_fieldname "net_${guest_name}_up").cdef $(clean_fieldname "net_${guest_name}_up"),8,*
$(clean_fieldname "net_${guest_name}_up").min 0
EOF
if [ -r "/sys/class/net/$device/speed" ]; then
megabit_per_second=$(cat "/sys/class/net/$device/speed")
bps=$((megabit_per_second * 1000 * 1000))
cat <<EOF
$(clean_fieldname "net_${guest_name}_down").max $bps
$(clean_fieldname "net_${guest_name}_up").max $bps
EOF
fi
done
cat <<EOF
multigraph lxc_proc
graph_title Processes
graph_args -l 0 --base 1000
graph_vlabel Number of processes
graph_category virtualization
EOF
for guest_name in $active_guests
do
cat <<EOF
$(clean_fieldname "lxc_proc_${guest_name}").label $guest_name: processes
$(clean_fieldname "lxc_proc_${guest_name}").type GAUGE
$(clean_fieldname "lxc_proc_${guest_name}").min 0
EOF
done
cat <<EOF
multigraph lxc_ram
graph_title Memory
graph_args -l 0 --base 1024
graph_vlabel byte
graph_category virtualization
EOF
for guest_name in $active_guests
do
if [ "$ram_display_stacked" != "true" ]; then
draw_style="LINE1"
else
draw_style="AREASTACK"
fi
cat <<EOF
$(clean_fieldname "mem_usage_${guest_name}").label ${guest_name}: Mem usage
$(clean_fieldname "mem_usage_${guest_name}").type GAUGE
$(clean_fieldname "mem_usage_${guest_name}").draw $draw_style
$(clean_fieldname "mem_cache_${guest_name}").label ${guest_name}: Cache
$(clean_fieldname "mem_cache_${guest_name}").type GAUGE
$(clean_fieldname "mem_active_${guest_name}").label ${guest_name}: Active
$(clean_fieldname "mem_active_${guest_name}").type GAUGE
$(clean_fieldname "mem_inactive_${guest_name}").label ${guest_name}: Inactive
$(clean_fieldname "mem_inactive_${guest_name}").type GAUGE
EOF
done
}
do_fetch() {
local active_guests cpu_usage device value_up value_down
active_guests=$(get_active_guests "$exclude")
echo "multigraph lxc_cpu"
for guest_name in $active_guests
do
for cpu_usage in user system
do
echo "$(clean_fieldname "cpu_${cpu_usage}_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "cpuacct.stat" | grep "$cpu_usage" | awk '{ print $2; }')"
done
done
echo "multigraph lxc_cpu_time"
for guest_name in $active_guests
do
echo "$(clean_fieldname "cpu_time_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "cpuacct.usage")"
done
echo "multigraph lxc_logins"
for guest_name in $active_guests
do
echo "$(clean_fieldname "logins_${guest_name}").value $(lxc-attach -n "$guest_name" users | wc -w)"
done
echo "multigraph lxc_net"
for guest_name in $active_guests
do
device=$(lxc_netdev "$guest_name")
if [ -z "$device" ]; then
value_up="U"
value_down="U"
else
value_up=$(grep -E "^ *${device}:" /proc/net/dev | awk '{print $10;}')
value_down=$(grep -E "^ *${device}:" /proc/net/dev | awk '{print $2;}')
fi
cat <<EOF
$(clean_fieldname "net_${guest_name}_up").value $value_up
$(clean_fieldname "net_${guest_name}_down").value $value_down
EOF
done
echo "multigraph lxc_proc"
for guest_name in $active_guests
do
echo "$(clean_fieldname "lxc_proc_${guest_name}").value $(lxc_count_processes "$guest_name")"
done
echo "multigraph lxc_ram"
for guest_name in $active_guests
do
cat <<EOF
$(clean_fieldname "mem_usage_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "memory.usage_in_bytes")
$(clean_fieldname "mem_cache_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "memory.stat" | grep total_cache | awk '{print $2;}')
$(clean_fieldname "mem_active_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "memory.stat" | grep total_active_anon | awk '{print $2;}')
$(clean_fieldname "mem_inactive_${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "memory.stat" | grep total_inactive_anon | awk '{print $2;}')
EOF
done
}
case "${1:-}" in
autoconf)
do_autoconf
exit 0
;;
config)
do_config
if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ]; then do_fetch; fi
exit 0
;;
"")
do_fetch
exit 0
;;
*)
echo >&2 "Invalid action requested (none of: autoconf / config / '')"
exit 1
esac

View file

@ -1,131 +0,0 @@
#!/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, because 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
devices=`grep '^lxc\.network\.veth\.pair[ \t]*=[ \t]*' $lxcpath/$guest/config | \
awk '{ split($0, a, /=/); gsub(/[ \t]/, "", a[2]); print a[2]; }'`
if [ -n "$devices" ]; then
for device in $devices; do
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
done
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 network"
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

View file

@ -1,123 +0,0 @@
#!/bin/bash
# -*- sh -*-
: << =cut
=head1 NAME
lxc_proc - Plugin to monitor LXC Processes count
=head1 CONFIGURATION
env.cgrouppath - Set the path where 'tasks' sysfs files are stored, default: empty
[lxc_proc]
user root
env.cgrouppath /sys/fs/cgroup/cpuacct/lxc/
=head1 INTERPRETATION
This plugin needs root privilege.
=head1 AUTHOR
vajtsz vajtsz@gmail.com
=head1 LICENSE
Unknown license
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
. $MUNIN_LIBDIR/plugins/plugin.sh
## find proper sysfs and count it
# Debian 6.0: /sys/fs/cgroup/<container>/tasks
# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc/<container>/tasks
# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc/<container>/tasks
# Ubuntu 14.04: /sys/fs/cgroup/systemd/lxc/<container>/tasks
count_processes () {
[ -z "$1" ] && return 0
if [ -n "$cgrouppath" ]; then
SYSFS=$cgrouppath/$1/tasks
if [ -e $SYSFS ]; then
return `wc -l < $SYSFS`
fi
fi
for SYSFS in \
/sys/fs/cgroup/$1/tasks \
/sys/fs/cgroup/lxc/$1/tasks \
/sys/fs/cgroup/systemd/lxc/$1/tasks \
/sys/fs/cgroup/cpuacct/lxc/$1/tasks \
/sys/fs/cgroup/cpuacct/sysdefault/lxc/$1/tasks \
; do
if [ -e $SYSFS ]; then
return `wc -l < $SYSFS`
fi
done
return 0
}
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 Processes '
echo 'graph_args -l 0 --base 1000'
echo 'graph_vlabel Number of processes'
echo 'graph_category processes'
for guest_name in $guest_names; do
guest="$(clean_fieldname $guest_name)"
echo 'lxc_proc_'$guest'.label '$guest_name': processes'
echo 'lxc_proc_'$guest'.type GAUGE'
echo 'lxc_proc_'$guest'.min 0'
done
exit 0
fi
for guest_name in $guest_names; do
guest="$(clean_fieldname $guest_name)"
count_processes $guest_name
tmp_g=$?
if [ $tmp_g -eq 0 ]; then
tmp_g=`$f_comm -n $guest_name tasks | wc -l`
fi
echo 'lxc_proc_'$guest'.value '$tmp_g
done

View file

@ -1,122 +0,0 @@
#!/bin/sh
# -*- 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
=head1 LICENSE
Unknown license
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=cut
# 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
}
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
fi