From ce6e67fffc89f25290eec5bab3aa7b2f02766b9a Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sat, 10 Aug 2019 11:33:27 +0200 Subject: [PATCH 01/48] lxc: working on buster (gandalf), and almost working on virtual (jessie), except lxc_net --- plugins/lxc/lxc-lib | 63 +++++++++++++++++ plugins/lxc/lxc_cpu | 90 +++++++++++------------- plugins/lxc/lxc_cpu_time | 72 ++++++++++---------- plugins/lxc/lxc_logins | 71 +++++++++++++++++++ plugins/lxc/lxc_net | 143 ++++++++++++++++++--------------------- plugins/lxc/lxc_proc | 100 +++++++++++++-------------- plugins/lxc/lxc_ram | 135 ++++++++++++++---------------------- 7 files changed, 371 insertions(+), 303 deletions(-) create mode 100644 plugins/lxc/lxc-lib create mode 100755 plugins/lxc/lxc_logins diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib new file mode 100644 index 00000000..90f90e6b --- /dev/null +++ b/plugins/lxc/lxc-lib @@ -0,0 +1,63 @@ +: << =cut + +=head1 NAME + +lxc-lib -- some base functions for the lxc_* plugins + +=head1 AUTHOR + +schaefer@alphanet.ch + +=head1 LICENSE + +GPLv3 + +=cut + +lxcpath=${lxcpath:-/var/lib/lxc} + +function active_guests { + local g active i ok + for g in $(lxc-ls | sort -u) + do + # handle optional exclude list in $1 + ok=1 + for i in $1 + do + if [ "$i" = "$g" ]; then + ok=0 + fi + done + + if [ $ok = 1 ]; then + if lxc-info -n $g 2>&1 | grep -qs RUNNING; then + active="$active $g" + fi + fi + done + + echo $active +} + +function lxc_cgroup { + # lxc3 + lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' + + # lxc < 3 + #lxc-cgroup $* +} + +function lxc_clean_fieldname { + # workaround for bug leaving out the first number + echo $(clean_fieldname ${1::1}$1) +} + +function lxc_netdev { + local g=$1 dev + + if [ -f $lxcpath/$g/config ]; then + grep lxc.net.0.veth.pair $lxcpath/$g/config | awk '{print $NF;}' + else + echo unknown + fi +} diff --git a/plugins/lxc/lxc_cpu b/plugins/lxc/lxc_cpu index 909a4628..2f76ff85 100755 --- a/plugins/lxc/lxc_cpu +++ b/plugins/lxc/lxc_cpu @@ -20,10 +20,12 @@ This plugin needs root privilege. 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 @@ -34,59 +36,49 @@ Unknown license . $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" +. $MUNIN_LIBDIR/plugins/lxc-lib - - -f_comm='lxc-cgroup ' +active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + 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 + cat <&1 | grep -qs RUNNING ; then - active="$active $guest" - fi -done -guest_names="$active" +. $MUNIN_LIBDIR/plugins/lxc-lib - -f_comm='lxc-cgroup ' +active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + if [ -r /proc/stat ]; then + echo yes + exit 0 + else + echo "no (no /proc/stat)" + exit 0 + fi fi if [ "$1" = "config" ]; then + cat </tasks # Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks # Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc//tasks # Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc//tasks -# Ubuntu 14.04: /sys/fs/cgroup/systemd/lxc//tasks +# and with cgmanager on jessie count_processes () { [ -z "$1" ] && return 0 @@ -51,11 +57,10 @@ count_processes () { 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 @@ -64,60 +69,51 @@ count_processes () { fi done + if [ -e /usr/bin/cgm ]; then + return `cgm getvalue cpu lxc/$1 tasks 2>/dev/null | wc -l` + fi + 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 + 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 + cat <&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 < Date: Sat, 10 Aug 2019 11:43:35 +0200 Subject: [PATCH 02/48] lxc < 3 support --- plugins/lxc/lxc-lib | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib index 90f90e6b..577cc70d 100644 --- a/plugins/lxc/lxc-lib +++ b/plugins/lxc/lxc-lib @@ -44,7 +44,7 @@ function lxc_cgroup { lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' # lxc < 3 - #lxc-cgroup $* +# lxc-cgroup $* } function lxc_clean_fieldname { @@ -56,7 +56,11 @@ function lxc_netdev { local g=$1 dev if [ -f $lxcpath/$g/config ]; then - grep lxc.net.0.veth.pair $lxcpath/$g/config | awk '{print $NF;}' + # lxc3 + egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' + + # lxc < 3 +# egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' else echo unknown fi From 2cfba9f8408e10c9a951faa00b38bda895696719 Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sat, 10 Aug 2019 11:48:51 +0200 Subject: [PATCH 03/48] Comment --- plugins/lxc/README | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 plugins/lxc/README diff --git a/plugins/lxc/README b/plugins/lxc/README new file mode 100644 index 00000000..915f8168 --- /dev/null +++ b/plugins/lxc/README @@ -0,0 +1,7 @@ +This works for lxc 3 (and, also, if you the two special cases in +lxc-lib, namely lxc-cgroup and lxc-netdev, you can support lxc < 3 too. + +Tested on Debian buster and Debian jessie. + +See the individual files for copyright and installation/configuration +information. From ab67ad805dc474184baa116eac91bf1d5e4e07bd Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sat, 10 Aug 2019 11:51:09 +0200 Subject: [PATCH 04/48] Comment --- plugins/lxc/README | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/lxc/README b/plugins/lxc/README index 915f8168..a437d22f 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -5,3 +5,5 @@ Tested on Debian buster and Debian jessie. See the individual files for copyright and installation/configuration information. + +This is version 1.0 by schaefer@alphanet.ch From 9ef366c71a649d645aea5d9f4a12e5d984fdd2e5 Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 09:40:39 +0200 Subject: [PATCH 05/48] - autoconf cleanup - better lxc_clean_fieldname workaround supporting non numeric compatibility - lxc_netdev now compatible with lxc3 and lxc2 at a small CPU cost - lxc_cgroup now compatible with lxc3 and lxc2; may however fail with lxc2 if your config file contains cruft --- plugins/lxc/README | 2 +- plugins/lxc/lxc-lib | 34 +++++++++++++++++++++++----------- plugins/lxc/lxc_cpu | 8 +------- plugins/lxc/lxc_cpu_time | 8 +------- plugins/lxc/lxc_logins | 8 +------- plugins/lxc/lxc_proc | 8 +------- plugins/lxc/lxc_ram | 8 +------- 7 files changed, 29 insertions(+), 47 deletions(-) diff --git a/plugins/lxc/README b/plugins/lxc/README index a437d22f..941ff402 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -6,4 +6,4 @@ Tested on Debian buster and Debian jessie. See the individual files for copyright and installation/configuration information. -This is version 1.0 by schaefer@alphanet.ch +This is version 1.1 by schaefer@alphanet.ch diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib index 577cc70d..a88e9528 100644 --- a/plugins/lxc/lxc-lib +++ b/plugins/lxc/lxc-lib @@ -40,28 +40,40 @@ function active_guests { } function lxc_cgroup { - # lxc3 + # lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir) lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' - - # lxc < 3 -# lxc-cgroup $* } function lxc_clean_fieldname { - # workaround for bug leaving out the first number - echo $(clean_fieldname ${1::1}$1) + # clean_fieldname should be used on the whole identifier, not just the + # lxc instance ID, because if it is only numeric, the first digit will + # be replaced with a "_"; this is a work-around + case "${1::1}" in + [0-9]) echo $(clean_fieldname ${1::1}$1);; # 104 -> __104 + *) echo $(clean_fieldname $1);; + esac } function lxc_netdev { local g=$1 dev if [ -f $lxcpath/$g/config ]; then - # lxc3 - egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' - - # lxc < 3 -# egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' + # lxc 3 vs < 3 + egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null | awk '{print $NF;}' \ + || egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' else echo unknown fi } + +# BUGS +# - I don't think this is enough or even appropriate +function lxc_autoconf { + if [ -r /proc/stat ]; then + echo yes + exit 0 + else + echo "no (no /proc/stat)" + exit 0 + fi +} diff --git a/plugins/lxc/lxc_cpu b/plugins/lxc/lxc_cpu index 2f76ff85..f501cad2 100755 --- a/plugins/lxc/lxc_cpu +++ b/plugins/lxc/lxc_cpu @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_cpu_time b/plugins/lxc/lxc_cpu_time index 8730a5a9..c483a916 100755 --- a/plugins/lxc/lxc_cpu_time +++ b/plugins/lxc/lxc_cpu_time @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_logins b/plugins/lxc/lxc_logins index d1fc3257..014aec33 100755 --- a/plugins/lxc/lxc_logins +++ b/plugins/lxc/lxc_logins @@ -38,13 +38,7 @@ GPLv3 active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_proc b/plugins/lxc/lxc_proc index e91274c9..f5c83704 100755 --- a/plugins/lxc/lxc_proc +++ b/plugins/lxc/lxc_proc @@ -77,13 +77,7 @@ count_processes () { } if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index 68e80038..bf6a4134 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -41,13 +41,7 @@ or GPLv3 license, at your option active_guests=$(active_guests) if [ "$1" = "autoconf" ]; then - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi + lxc_autoconf fi if [ "$1" = "config" ]; then From 89e0f1c72956091948554b66500e7d7ab35399ea Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 09:43:39 +0200 Subject: [PATCH 06/48] Update --- plugins/lxc/README | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/README b/plugins/lxc/README index 941ff402..ff81420f 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -1,5 +1,7 @@ -This works for lxc 3 (and, also, if you the two special cases in -lxc-lib, namely lxc-cgroup and lxc-netdev, you can support lxc < 3 too. +This works for lxc 3 (and lxc 2, as long as you don't have +cruft in your config file, test it with: + lxc-cgroup -o /dev/stdout -l INFO -n 104 cpuacct.usage +-- with 104 a valid lxc instance) Tested on Debian buster and Debian jessie. From 241b0c60672d7c244e54619c0540fa05ec49f5e2 Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 10:11:24 +0200 Subject: [PATCH 07/48] Fix for lxc < 3 --- plugins/lxc/lxc-lib | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib index a88e9528..bf9687ae 100644 --- a/plugins/lxc/lxc-lib +++ b/plugins/lxc/lxc-lib @@ -59,8 +59,9 @@ function lxc_netdev { if [ -f $lxcpath/$g/config ]; then # lxc 3 vs < 3 - egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null | awk '{print $NF;}' \ - || egrep '^lxc.network.veth.pair' $lxcpath/$g/config | awk '{print $NF;}' + (egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \ + || egrep '^lxc.network.veth.pair' $lxcpath/$g/config + ) | awk '{print $NF;}' else echo unknown fi From 5105020fcfadf6adb45133c604db55639de7596e Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 11:02:10 +0200 Subject: [PATCH 08/48] - added systemd possibility for stats - cleanup --- plugins/lxc/lxc_proc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/lxc_proc b/plugins/lxc/lxc_proc index f5c83704..be44d9c8 100755 --- a/plugins/lxc/lxc_proc +++ b/plugins/lxc/lxc_proc @@ -47,6 +47,7 @@ active_guests=$(active_guests) # Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks # Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc//tasks # Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc//tasks +# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc//tasks # and with cgmanager on jessie count_processes () { [ -z "$1" ] && return 0 @@ -61,9 +62,10 @@ count_processes () { 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 + /sys/fs/cgroup/cpuacct/sysdefault/lxc/$1/tasks + do if [ -e $SYSFS ]; then return `wc -l < $SYSFS` fi From 50a998b460f8ed33f09fd122793eb7f702b32c11 Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 11:02:35 +0200 Subject: [PATCH 09/48] areastack option --- plugins/lxc/lxc_ram | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index bf6a4134..8160d289 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -12,10 +12,18 @@ 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 @@ -40,6 +48,9 @@ or GPLv3 license, at your option active_guests=$(active_guests) +# configurable: true/false +areastack=${areastack:-false} + if [ "$1" = "autoconf" ]; then lxc_autoconf fi @@ -58,6 +69,12 @@ EOF cat < Date: Sun, 11 Aug 2019 11:02:50 +0200 Subject: [PATCH 10/48] version --- plugins/lxc/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lxc/README b/plugins/lxc/README index ff81420f..2f81a090 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -8,4 +8,4 @@ Tested on Debian buster and Debian jessie. See the individual files for copyright and installation/configuration information. -This is version 1.1 by schaefer@alphanet.ch +This is version 1.2 by schaefer@alphanet.ch From 154ffc100ba925e426efadf151b43209112993c8 Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 11:12:24 +0200 Subject: [PATCH 11/48] Fix --- plugins/lxc/README | 2 +- plugins/lxc/lxc_ram | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/README b/plugins/lxc/README index 2f81a090..b259f704 100644 --- a/plugins/lxc/README +++ b/plugins/lxc/README @@ -8,4 +8,4 @@ Tested on Debian buster and Debian jessie. See the individual files for copyright and installation/configuration information. -This is version 1.2 by schaefer@alphanet.ch +This is version 1.3 by schaefer@alphanet.ch diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index 8160d289..15a48898 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -69,7 +69,7 @@ EOF cat < Date: Sun, 11 Aug 2019 18:45:25 +0200 Subject: [PATCH 12/48] Initial version of multigraph version --- plugins/lxc/README | 11 ---- plugins/lxc/lxc-lib | 80 --------------------------- plugins/lxc/lxc_cpu | 78 -------------------------- plugins/lxc/lxc_cpu_time | 71 ------------------------ plugins/lxc/lxc_logins | 65 ---------------------- plugins/lxc/lxc_net | 116 --------------------------------------- plugins/lxc/lxc_proc | 115 -------------------------------------- plugins/lxc/lxc_ram | 98 --------------------------------- 8 files changed, 634 deletions(-) delete mode 100644 plugins/lxc/README delete mode 100644 plugins/lxc/lxc-lib delete mode 100755 plugins/lxc/lxc_cpu delete mode 100755 plugins/lxc/lxc_cpu_time delete mode 100755 plugins/lxc/lxc_logins delete mode 100755 plugins/lxc/lxc_net delete mode 100755 plugins/lxc/lxc_proc delete mode 100755 plugins/lxc/lxc_ram diff --git a/plugins/lxc/README b/plugins/lxc/README deleted file mode 100644 index b259f704..00000000 --- a/plugins/lxc/README +++ /dev/null @@ -1,11 +0,0 @@ -This works for lxc 3 (and lxc 2, as long as you don't have -cruft in your config file, test it with: - lxc-cgroup -o /dev/stdout -l INFO -n 104 cpuacct.usage --- with 104 a valid lxc instance) - -Tested on Debian buster and Debian jessie. - -See the individual files for copyright and installation/configuration -information. - -This is version 1.3 by schaefer@alphanet.ch diff --git a/plugins/lxc/lxc-lib b/plugins/lxc/lxc-lib deleted file mode 100644 index bf9687ae..00000000 --- a/plugins/lxc/lxc-lib +++ /dev/null @@ -1,80 +0,0 @@ -: << =cut - -=head1 NAME - -lxc-lib -- some base functions for the lxc_* plugins - -=head1 AUTHOR - -schaefer@alphanet.ch - -=head1 LICENSE - -GPLv3 - -=cut - -lxcpath=${lxcpath:-/var/lib/lxc} - -function active_guests { - local g active i ok - for g in $(lxc-ls | sort -u) - do - # handle optional exclude list in $1 - ok=1 - for i in $1 - do - if [ "$i" = "$g" ]; then - ok=0 - fi - done - - if [ $ok = 1 ]; then - if lxc-info -n $g 2>&1 | grep -qs RUNNING; then - active="$active $g" - fi - fi - done - - echo $active -} - -function lxc_cgroup { - # lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir) - lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' -} - -function lxc_clean_fieldname { - # clean_fieldname should be used on the whole identifier, not just the - # lxc instance ID, because if it is only numeric, the first digit will - # be replaced with a "_"; this is a work-around - case "${1::1}" in - [0-9]) echo $(clean_fieldname ${1::1}$1);; # 104 -> __104 - *) echo $(clean_fieldname $1);; - esac -} - -function lxc_netdev { - local g=$1 dev - - if [ -f $lxcpath/$g/config ]; then - # lxc 3 vs < 3 - (egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \ - || egrep '^lxc.network.veth.pair' $lxcpath/$g/config - ) | awk '{print $NF;}' - else - echo unknown - fi -} - -# BUGS -# - I don't think this is enough or even appropriate -function lxc_autoconf { - if [ -r /proc/stat ]; then - echo yes - exit 0 - else - echo "no (no /proc/stat)" - exit 0 - fi -} diff --git a/plugins/lxc/lxc_cpu b/plugins/lxc/lxc_cpu deleted file mode 100755 index f501cad2..00000000 --- a/plugins/lxc/lxc_cpu +++ /dev/null @@ -1,78 +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 -(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) - -if [ "$1" = "autoconf" ]; then - lxc_autoconf -fi - -if [ "$1" = "config" ]; then - cat </tasks -# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks -# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc//tasks -# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc//tasks -# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc//tasks -# and with cgmanager on jessie -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 - - if [ -e /usr/bin/cgm ]; then - return `cgm getvalue cpu lxc/$1 tasks 2>/dev/null | wc -l` - fi - - return 0 -} - -if [ "$1" = "autoconf" ]; then - lxc_autoconf -fi - -if [ "$1" = "config" ]; then - cat < Date: Sun, 11 Aug 2019 18:46:55 +0200 Subject: [PATCH 13/48] First multigraph version --- plugins/lxc/lxc-multigraph | 377 +++++++++++++++++++++++++++++++++++++ 1 file changed, 377 insertions(+) create mode 100755 plugins/lxc/lxc-multigraph diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph new file mode 100755 index 00000000..ee920004 --- /dev/null +++ b/plugins/lxc/lxc-multigraph @@ -0,0 +1,377 @@ +#!/bin/bash +# -*- sh -*- + +: << =cut + +=head1 NAME + +lxc-multigraph - Plugin to monitor LXC containers (v2.0) + +=head1 CONFIGURATION + + [lxc-multigraph] + user root + + # memory usage of containers drawn as + # stacked area charts (changes graph + # order) -- defaults to false + # env.ram_areastack 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, you need the bc command, and, +in each container, the users command. + +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) + +See https://framagit.org/alphanet/various-stuff +(plugins/lcx) + +=head1 LICENSE + +2-clause BSD License +or GPLv3 license or later, at your option + +=head1 MAGIC MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + +. $MUNIN_LIBDIR/plugins/plugin.sh + +lxcpath=${lxcpath:-/var/lib/lxc} + +function active_guests { + local g active i ok + for g in $(lxc-ls | sort -u) + do + # handle optional exclude list in $1 + ok=1 + for i in $1 + do + if [ "$i" = "$g" ]; then + ok=0 + fi + done + + if [ $ok = 1 ]; then + if lxc-info -n $g 2>&1 | grep -qs RUNNING; then + active="$active $g" + fi + fi + done + + echo $active +} + +function lxc_cgroup { + # lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir) + lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' +} + +function lxc_netdev { + local g=$1 dev + + if [ -f $lxcpath/$g/config ]; then + # lxc 3 vs < 3 + (egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \ + || egrep '^lxc.network.veth.pair' $lxcpath/$g/config + ) | awk '{print $NF;}' + else + echo unknown + fi +} + +# find proper sysfs and count it +# Debian 6.0: /sys/fs/cgroup//tasks +# Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks +# Ubuntu 12.04 with cgroup-lite: /sys/fs/cgroup/cpuacct/lxc//tasks +# Ubuntu 12.04 with cgroup-bin: /sys/fs/cgroup/cpuacct/sysdefault/lxc//tasks +# Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc//tasks +# and with cgmanager on jessie +lxc_count_processes () { + local SYSFS + + [ -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 + + if [ -e /usr/bin/cgm ]; then + return $(cgm getvalue cpu "lxc/$1" tasks 2>/dev/null | wc -l) + fi + + return 0 +} + +active_guests=$(active_guests $exclude) + +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 ($lxcpath is not present)" + exit 0 + fi + + echo yes +fi + +# --- CONFIG OUTPUT + +if [ "$1" = "config" ]; then + cat < Date: Sun, 11 Aug 2019 18:50:00 +0200 Subject: [PATCH 14/48] Sections and small fix --- plugins/lxc/lxc-multigraph | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index ee920004..4d79a3f4 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -82,6 +82,8 @@ or GPLv3 license or later, at your option lxcpath=${lxcpath:-/var/lib/lxc} +# --- FUNCTIONS + function active_guests { local g active i ok for g in $(lxc-ls | sort -u) @@ -161,8 +163,12 @@ lxc_count_processes () { return 0 } +# --- BASIC DEFINES + active_guests=$(active_guests $exclude) +# --- AUTOCONF + if [ "$1" = "autoconf" ]; then if [ ! -r /proc/net/dev ]; then echo "no (/proc/net/dev cannot be read)" @@ -357,7 +363,7 @@ done echo "multigraph lxc_proc" for n in $active_guests do - count_processes "$n" + lxc_count_processes "$n" tmp=$? if [ $tmp -eq 0 ]; then tmp=$(lxc_cgroup -n "$n" tasks | wc -l) From c0fe6dc3c740ecde18a858a926d47470ed7c112e Mon Sep 17 00:00:00 2001 From: Marc SCHAEFER Date: Sun, 11 Aug 2019 19:07:51 +0200 Subject: [PATCH 15/48] Compatibility with older field names --- plugins/lxc/lxc-multigraph | 87 ++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 42 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 4d79a3f4..5a0e206a 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -57,6 +57,9 @@ in each container, the users command. Tested on Debian buster and Debian jessie. +The double __ for values is for compatibility +with the previous implementation. + =head1 AUTHOR vajtsz vajtsz@gmail.com @@ -198,9 +201,9 @@ EOF for i in user system do cat < Date: Sun, 11 Aug 2019 23:31:16 +0200 Subject: [PATCH 16/48] Plugin lxc: unify whitespace --- plugins/lxc/lxc-multigraph | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 5a0e206a..1067ca15 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -110,11 +110,13 @@ function active_guests { echo $active } + function lxc_cgroup { # lxc3 (lxc < 3: may output some warnings if there is cruft in your config dir) lxc-cgroup -o /dev/stdout -l INFO $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' } + function lxc_netdev { local g=$1 dev @@ -128,6 +130,7 @@ function lxc_netdev { fi } + # find proper sysfs and count it # Debian 6.0: /sys/fs/cgroup//tasks # Ubuntu 12.04 with fstab: /sys/fs/cgroup/lxc//tasks @@ -166,6 +169,7 @@ lxc_count_processes () { return 0 } + # --- BASIC DEFINES active_guests=$(active_guests $exclude) @@ -218,7 +222,7 @@ graph_category lxc EOF for n in $active_guests - do + do cat < Date: Sun, 11 Aug 2019 23:36:12 +0200 Subject: [PATCH 17/48] Plugin lxc: exit after autoconf Previously processing continued after a successful autoconf operation. --- plugins/lxc/lxc-multigraph | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 1067ca15..37c4dcc3 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -179,14 +179,12 @@ active_guests=$(active_guests $exclude) 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 + elif [ ! -e "$lxcpath" ]; then echo "no ($lxcpath is not present)" - exit 0 + else + echo yes fi - - echo yes + exit 0 fi # --- CONFIG OUTPUT From ab6f4e3c6efcab485b6a0ba04757c4227f8e4d9f Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sun, 11 Aug 2019 23:40:21 +0200 Subject: [PATCH 18/48] Plugin lxc: fix configurable RAM graphing Previously (before the multigraph conversion) the configuration setting for "lxc_ram" was called "areastack". The multigraph conversion documented a new configuration setting "ram_areastack", but it was not used, yet. Thus we can switch to a more descriptive name: "ram_display_stacked". --- plugins/lxc/lxc-multigraph | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 37c4dcc3..5ea96a40 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -15,7 +15,7 @@ lxc-multigraph - Plugin to monitor LXC containers (v2.0) # memory usage of containers drawn as # stacked area charts (changes graph # order) -- defaults to false - # env.ram_areastack true + # env.ram_display_stacked true # lxc container path, default below #env.lxcpath /var/lib/lxc @@ -84,6 +84,8 @@ or GPLv3 license or later, at your option . $MUNIN_LIBDIR/plugins/plugin.sh lxcpath=${lxcpath:-/var/lib/lxc} +ram_display_stacked=${ram_display_stacked:-false} + # --- FUNCTIONS @@ -307,15 +309,16 @@ EOF for n in $active_guests do - cat < Date: Sun, 11 Aug 2019 23:52:33 +0200 Subject: [PATCH 19/48] Plugin lxc: draw stacked RAM graphs by default Previously "ram_display_stacked" defaulted to "false" (non-stacked graphs). The new default should be suitable for most situations. --- plugins/lxc/lxc-multigraph | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 5ea96a40..817e32e0 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -12,10 +12,10 @@ lxc-multigraph - Plugin to monitor LXC containers (v2.0) [lxc-multigraph] user root - # memory usage of containers drawn as - # stacked area charts (changes graph - # order) -- defaults to false - # env.ram_display_stacked true + # 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 @@ -84,7 +84,7 @@ or GPLv3 license or later, at your option . $MUNIN_LIBDIR/plugins/plugin.sh lxcpath=${lxcpath:-/var/lib/lxc} -ram_display_stacked=${ram_display_stacked:-false} +ram_display_stacked=${ram_display_stacked:-true} # --- FUNCTIONS @@ -309,10 +309,10 @@ EOF for n in $active_guests do - if [ "$ram_display_stacked" = "true" ]; then - draw_style="AREASTACK" - else + if [ "$ram_display_stacked" != "true" ]; then draw_style="LINE1" + else + draw_style="AREASTACK" fi cat < Date: Sun, 11 Aug 2019 23:58:15 +0200 Subject: [PATCH 20/48] Plugin lxc: function "lxc_count_processes" now outputs its result Previously the result was returned as the exit code of the function (which would prevent the usage of "set -e"). Additionally the fallback value that was previously calculated outside of the function is now part of it. --- plugins/lxc/lxc-multigraph | 44 ++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 817e32e0..a06c1c0e 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -141,34 +141,37 @@ function lxc_netdev { # Ubuntu 14.04 /sys/fs/cgroup/systemd/lxc//tasks # and with cgmanager on jessie lxc_count_processes () { + local guest_name="$1" local SYSFS - [ -z "$1" ] && return 0 + [ -z "$guest_name" ] && return 0 if [ -n "$cgrouppath" ]; then - SYSFS="$cgrouppath/$1/tasks" + SYSFS="$cgrouppath/$guest_name/tasks" if [ -e $SYSFS ]; then - return $(wc -l < $SYSFS) + wc -l <"$SYSFS" + return 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 + /sys/fs/cgroup/"$guest_name"/tasks \ + /sys/fs/cgroup/lxc/"$guest_name"/tasks \ + /sys/fs/cgroup/systemd/lxc/"$guest_name"/tasks \ + /sys/fs/cgroup/cpuacct/lxc/"$guest_name"/tasks \ + /sys/fs/cgroup/cpuacct/sysdefault/lxc/"$guest_name"/tasks do if [ -e $SYSFS ]; then - return $(wc -l < $SYSFS) + wc -l <"$SYSFS" + return fi done if [ -e /usr/bin/cgm ]; then - return $(cgm getvalue cpu "lxc/$1" tasks 2>/dev/null | wc -l) + cgm getvalue cpu "lxc/$guest_name" tasks 2>/dev/null | wc -l + else + lxc_cgroup -n "$guest_name" tasks | wc -l fi - - return 0 } @@ -359,24 +362,23 @@ for n in $active_guests do device=$(lxc_netdev "$n") if [ "$device" = "unknown" ]; then - continue + value_up="U" + value_down="U" + else + value_up=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}') + value_down=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}') fi cat < Date: Mon, 12 Aug 2019 00:02:46 +0200 Subject: [PATCH 21/48] Plugin lxc: explicitly assign all accepted environment variables --- plugins/lxc/lxc-multigraph | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index a06c1c0e..83a0598d 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -84,7 +84,11 @@ or GPLv3 license or later, at your option . $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 From e91f7ecba76f4a83705434621d7fdebe590788b7 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 00:12:11 +0200 Subject: [PATCH 22/48] Plugin lxc: remove ineffective usage of "bc" The command "wc -w" already outputs the final result. Thus we do not need this command (and do not have to depend on it). --- plugins/lxc/lxc-multigraph | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 83a0598d..ce759d04 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -52,8 +52,8 @@ it with: -- with 104 a valid lxc instance), if you get a warning, fix the config file. -For the logins graph, you need the bc command, and, -in each container, the users command. +For the logins graph, the "users" command is required in each +container. Tested on Debian buster and Debian jessie. @@ -358,7 +358,7 @@ done echo "multigraph lxc_logins" for n in $active_guests do - echo $(clean_fieldname "logins__${n}").value $(lxc-attach -n "$n" users | wc -w | bc) + echo $(clean_fieldname "logins__${n}").value $(lxc-attach -n "$n" users | wc -w) done echo "multigraph lxc_net" From 0d593014b4baf33c5c12b88cbac83df4b49fccf2 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 00:17:15 +0200 Subject: [PATCH 23/48] Plugin lxc: fix printing of "${graph_period}" This specific text token ("${graph_period}") is interpreted by munin and should not be interpreted by the shell. Thus it needs to be escaped. --- plugins/lxc/lxc-multigraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index ce759d04..24cda4bc 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -257,7 +257,7 @@ EOF multigraph lxc_net graph_title Network traffic graph_args --base 1000 -graph_vlabel bits in (-) / out (+) per ${graph_period} +graph_vlabel bits in (-) / out (+) per \${graph_period} graph_category lxc graph_info This graph shows the traffic of active LXC containers. EOF From 89003f01882e89e78b6bd3a6a1694f7e927f9e4e Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 00:38:38 +0200 Subject: [PATCH 24/48] Plugin lxc: fix quoting issues --- plugins/lxc/lxc-multigraph | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 24cda4bc..e238d2d0 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -81,7 +81,8 @@ or GPLv3 license or later, at your option =cut -. $MUNIN_LIBDIR/plugins/plugin.sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" + lxcpath=${lxcpath:-/var/lib/lxc} # containers to be ignored @@ -106,14 +107,14 @@ function active_guests { fi done - if [ $ok = 1 ]; then - if lxc-info -n $g 2>&1 | grep -qs RUNNING; then + if [ "$ok" = 1 ]; then + if lxc-info -n "$g" 2>&1 | grep -qs RUNNING; then active="$active $g" fi fi done - echo $active + echo "$active" } @@ -126,10 +127,10 @@ function lxc_cgroup { function lxc_netdev { local g=$1 dev - if [ -f $lxcpath/$g/config ]; then + if [ -f "$lxcpath/$g/config" ]; then # lxc 3 vs < 3 - (egrep '^lxc.net.0.veth.pair' $lxcpath/$g/config 2>/dev/null \ - || egrep '^lxc.network.veth.pair' $lxcpath/$g/config + (egrep '^lxc.net.0.veth.pair' "$lxcpath/$g/config" 2>/dev/null \ + || egrep '^lxc.network.veth.pair' "$lxcpath/$g/config" ) | awk '{print $NF;}' else echo unknown @@ -152,20 +153,20 @@ lxc_count_processes () { if [ -n "$cgrouppath" ]; then SYSFS="$cgrouppath/$guest_name/tasks" - if [ -e $SYSFS ]; then + 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/systemd/lxc/"$guest_name"/tasks \ - /sys/fs/cgroup/cpuacct/lxc/"$guest_name"/tasks \ - /sys/fs/cgroup/cpuacct/sysdefault/lxc/"$guest_name"/tasks + "/sys/fs/cgroup/$guest_name/tasks" \ + "/sys/fs/cgroup/lxc/$guest_name/tasks" \ + "/sys/fs/cgroup/systemd/lxc/$guest_name/tasks" \ + "/sys/fs/cgroup/cpuacct/lxc/$guest_name/tasks" \ + "/sys/fs/cgroup/cpuacct/sysdefault/lxc/$guest_name/tasks" do - if [ -e $SYSFS ]; then + if [ -e "$SYSFS" ]; then wc -l <"$SYSFS" return fi @@ -212,7 +213,7 @@ EOF for i in user system do cat < Date: Mon, 12 Aug 2019 00:40:15 +0200 Subject: [PATCH 25/48] Plugin lxc: simplify interface of "lxc_netdev" --- plugins/lxc/lxc-multigraph | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index e238d2d0..177c681d 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -132,8 +132,6 @@ function lxc_netdev { (egrep '^lxc.net.0.veth.pair' "$lxcpath/$g/config" 2>/dev/null \ || egrep '^lxc.network.veth.pair' "$lxcpath/$g/config" ) | awk '{print $NF;}' - else - echo unknown fi } @@ -266,7 +264,7 @@ EOF for n in $active_guests do device=$(lxc_netdev "$n") - if [ "$device" = "unknown" ]; then + if [ -z "$device" ]; then continue fi bps="U" @@ -366,7 +364,7 @@ echo "multigraph lxc_net" for n in $active_guests do device=$(lxc_netdev "$n") - if [ "$device" = "unknown" ]; then + if [ -z "$device" ]; then value_up="U" value_down="U" else From 914d1c5f25d00c735cc0e18d83ceff1fac26247f Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 00:43:25 +0200 Subject: [PATCH 26/48] Plugin lxc: clarify network bandwidth calculation --- plugins/lxc/lxc-multigraph | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 177c681d..183fcc8f 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -269,7 +269,8 @@ EOF fi bps="U" if [ -r "/sys/class/net/$device/speed" ]; then - bps=$(($(cat "/sys/class/net/$device/speed") * 1000 * 1000)) + megabit_per_second=$(cat "/sys/class/net/$device/speed") + bps=$((megabit_per_second * 1000 * 1000)) fi cat < Date: Mon, 12 Aug 2019 00:47:53 +0200 Subject: [PATCH 27/48] Plugin lxc: omit output of "max" if the network interface speed is unknown The "U" value is not defined for the "max" field. --- plugins/lxc/lxc-multigraph | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 183fcc8f..6bd54a7a 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -267,25 +267,26 @@ EOF if [ -z "$device" ]; then continue fi - bps="U" - if [ -r "/sys/class/net/$device/speed" ]; then - megabit_per_second=$(cat "/sys/class/net/$device/speed") - bps=$((megabit_per_second * 1000 * 1000)) - fi cat < Date: Mon, 12 Aug 2019 00:49:27 +0200 Subject: [PATCH 28/48] Plugin lxc: clarify variable names used in functions --- plugins/lxc/lxc-multigraph | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 6bd54a7a..312442eb 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -95,21 +95,21 @@ cgrouppath=${cgrouppath:-} # --- FUNCTIONS function active_guests { - local g active i ok - for g in $(lxc-ls | sort -u) + local guest_name active i ok + for guest_name in $(lxc-ls | sort -u) do # handle optional exclude list in $1 ok=1 for i in $1 do - if [ "$i" = "$g" ]; then + if [ "$i" = "$guest_name" ]; then ok=0 fi done if [ "$ok" = 1 ]; then - if lxc-info -n "$g" 2>&1 | grep -qs RUNNING; then - active="$active $g" + if lxc-info -n "$guest_name" 2>&1 | grep -qs RUNNING; then + active="$active $guest_name" fi fi done @@ -125,12 +125,12 @@ function lxc_cgroup { function lxc_netdev { - local g=$1 dev + local guest_name="$1" - if [ -f "$lxcpath/$g/config" ]; then + if [ -f "$lxcpath/$guest_name/config" ]; then # lxc 3 vs < 3 - (egrep '^lxc.net.0.veth.pair' "$lxcpath/$g/config" 2>/dev/null \ - || egrep '^lxc.network.veth.pair' "$lxcpath/$g/config" + (egrep '^lxc.net.0.veth.pair' "$lxcpath/$guest_name/config" 2>/dev/null \ + || egrep '^lxc.network.veth.pair' "$lxcpath/$guest_name/config" ) | awk '{print $NF;}' fi } From 6413375cdc9b5e663bec2e8494e92a09f7338f3d Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 00:56:24 +0200 Subject: [PATCH 29/48] Plugin lxc: simplify processing in function "active_guests" --- plugins/lxc/lxc-multigraph | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 312442eb..aa63f679 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -95,7 +95,7 @@ cgrouppath=${cgrouppath:-} # --- FUNCTIONS function active_guests { - local guest_name active i ok + local guest_name i ok for guest_name in $(lxc-ls | sort -u) do # handle optional exclude list in $1 @@ -109,12 +109,10 @@ function active_guests { if [ "$ok" = 1 ]; then if lxc-info -n "$guest_name" 2>&1 | grep -qs RUNNING; then - active="$active $guest_name" + echo "$guest_name" fi fi done - - echo "$active" } From 276e96c0ddf458d06f156b2bf17d825830c5c925 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:04:09 +0200 Subject: [PATCH 30/48] Plugin lxc: remove ineffective "sort -u" from function "active_guests" The output of "lxc-ls" is not line-splitted. Thus all active guests are printed in a single line and "sort -u" (removal of non-unique entries) had no effect. --- plugins/lxc/lxc-multigraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index aa63f679..72eeb382 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -96,7 +96,7 @@ cgrouppath=${cgrouppath:-} function active_guests { local guest_name i ok - for guest_name in $(lxc-ls | sort -u) + for guest_name in $(lxc-ls) do # handle optional exclude list in $1 ok=1 From 46626b9953a72828c97c3e20c7060d08baaf9cfb Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:08:22 +0200 Subject: [PATCH 31/48] Plugin lxc: simplify implementation of function "active_guests" --- plugins/lxc/lxc-multigraph | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 72eeb382..f9521971 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -95,20 +95,13 @@ cgrouppath=${cgrouppath:-} # --- FUNCTIONS function active_guests { - local guest_name i ok + local excludes="$1" + local guest_name for guest_name in $(lxc-ls) do # handle optional exclude list in $1 - ok=1 - for i in $1 - do - if [ "$i" = "$guest_name" ]; then - ok=0 - fi - done - - if [ "$ok" = 1 ]; then - if lxc-info -n "$guest_name" 2>&1 | grep -qs RUNNING; then + 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 From 199b4517cb541c66ecb6835d6faf06b45e3c24f1 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:11:31 +0200 Subject: [PATCH 32/48] Plugin lxc: use "grep -E" instead of "egrep" --- plugins/lxc/lxc-multigraph | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index f9521971..220e7bb4 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -120,8 +120,8 @@ function lxc_netdev { if [ -f "$lxcpath/$guest_name/config" ]; then # lxc 3 vs < 3 - (egrep '^lxc.net.0.veth.pair' "$lxcpath/$guest_name/config" 2>/dev/null \ - || egrep '^lxc.network.veth.pair' "$lxcpath/$guest_name/config" + (grep -EF '^lxc.net.0.veth.pair' "$lxcpath/$guest_name/config" 2>/dev/null \ + || grep -EF '^lxc.network.veth.pair' "$lxcpath/$guest_name/config" ) | awk '{print $NF;}' fi } @@ -361,8 +361,8 @@ do value_up="U" value_down="U" else - value_up=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $10;}') - value_down=$(egrep "^ *${device}:" /proc/net/dev | awk '{print $2;}') + value_up=$(grep -E "^ *${device}:" /proc/net/dev | awk '{print $10;}') + value_down=$(grep -E "^ *${device}:" /proc/net/dev | awk '{print $2;}') fi cat < Date: Mon, 12 Aug 2019 01:12:29 +0200 Subject: [PATCH 33/48] Plugin lxc: fix handling of "excludes" parameter Previously only the first item in the "excludes" environment variable was really excluded. --- plugins/lxc/lxc-multigraph | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 220e7bb4..417a42e5 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -171,7 +171,7 @@ lxc_count_processes () { # --- BASIC DEFINES -active_guests=$(active_guests $exclude) +active_guests=$(active_guests "$exclude") # --- AUTOCONF From 33b2f3ed8b3b6ab8b10492433e2bf704c95bf435 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:23:05 +0200 Subject: [PATCH 34/48] Plugin lxc: use comprehensible names for variables --- plugins/lxc/lxc-multigraph | 116 ++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 417a42e5..dd337cae 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -197,14 +197,14 @@ graph_vlabel USER_HZ graph_category lxc EOF - for n in $active_guests + for guest_name in $active_guests do - for i in user system + for cpu_usage in user system do cat < Date: Mon, 12 Aug 2019 01:27:39 +0200 Subject: [PATCH 35/48] Plugin lxc: simplify interface of "lxc_cgroup" and rename function --- plugins/lxc/lxc-multigraph | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index dd337cae..2c699538 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -109,9 +109,11 @@ function active_guests { } -function lxc_cgroup { +function 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 $* | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' + lxc-cgroup -o /dev/stdout -l INFO -n "$guest_name" "$field" | sed 's/^.*lxc_cgroup.c:main:[0-9][0-9]* - //' } @@ -164,7 +166,7 @@ lxc_count_processes () { if [ -e /usr/bin/cgm ]; then cgm getvalue cpu "lxc/$guest_name" tasks 2>/dev/null | wc -l else - lxc_cgroup -n "$guest_name" tasks | wc -l + get_lxc_cgroup_info "$guest_name" "tasks" | wc -l fi } @@ -337,14 +339,14 @@ for guest_name in $active_guests do for cpu_usage in user system do - echo "$(clean_fieldname "cpu_${cpu_usage}__${guest_name}").value $(lxc_cgroup -n "$guest_name" cpuacct.stat | grep "$cpu_usage" | awk '{ print $2; }')" + 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 $(lxc_cgroup -n "$guest_name" cpuacct.usage)" + echo "$(clean_fieldname "cpu_time__${guest_name}").value $(get_lxc_cgroup_info "$guest_name" "cpuacct.usage")" done echo "multigraph lxc_logins" @@ -381,9 +383,9 @@ echo "multigraph lxc_ram" for guest_name in $active_guests do cat < Date: Mon, 12 Aug 2019 01:38:16 +0200 Subject: [PATCH 36/48] Plugin lxc: separate function for title beautification This avoids a bashism. --- plugins/lxc/lxc-multigraph | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 2c699538..f97f925f 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -171,6 +171,13 @@ lxc_count_processes () { } +# 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-)" +} + + # --- BASIC DEFINES active_guests=$(active_guests "$exclude") @@ -204,7 +211,7 @@ EOF for cpu_usage in user system do cat < Date: Mon, 12 Aug 2019 01:39:30 +0200 Subject: [PATCH 37/48] Plugin lxc: change the plugin from "bash" to "sh" No more bashisms were left. --- plugins/lxc/lxc-multigraph | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index f97f925f..0becc68e 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # -*- sh -*- : << =cut @@ -94,7 +94,7 @@ cgrouppath=${cgrouppath:-} # --- FUNCTIONS -function active_guests { +active_guests() { local excludes="$1" local guest_name for guest_name in $(lxc-ls) @@ -109,7 +109,7 @@ function active_guests { } -function get_lxc_cgroup_info { +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) @@ -117,7 +117,7 @@ function get_lxc_cgroup_info { } -function lxc_netdev { +lxc_netdev() { local guest_name="$1" if [ -f "$lxcpath/$guest_name/config" ]; then From 4356a024a7c018206f26f253a0bcf0c7eb1e623d Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:42:52 +0200 Subject: [PATCH 38/48] Plugin lxc: clarify name for function "active_guests" Previously a variable and a function used the same name. This was no problem, but it can cause confusion. --- plugins/lxc/lxc-multigraph | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 0becc68e..70f7abad 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -94,7 +94,7 @@ cgrouppath=${cgrouppath:-} # --- FUNCTIONS -active_guests() { +get_active_guests() { local excludes="$1" local guest_name for guest_name in $(lxc-ls) @@ -180,7 +180,7 @@ title_case() { # --- BASIC DEFINES -active_guests=$(active_guests "$exclude") +active_guests=$(get_active_guests "$exclude") # --- AUTOCONF From f00f28cf6fadb589ecea14305cf22e12002838f3 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:49:48 +0200 Subject: [PATCH 39/48] Plugin lxc: use functions for top-level activities This clarifies the flow of control and allows to use MUNIN_CAP_DIRTYCONFIG later. --- plugins/lxc/lxc-multigraph | 134 +++++++++++++++++++++---------------- 1 file changed, 75 insertions(+), 59 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 70f7abad..d273b543 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -178,13 +178,7 @@ title_case() { } -# --- BASIC DEFINES - -active_guests=$(get_active_guests "$exclude") - -# --- AUTOCONF - -if [ "$1" = "autoconf" ]; then +do_autoconf() { if [ ! -r /proc/net/dev ]; then echo "no (/proc/net/dev cannot be read)" elif [ ! -e "$lxcpath" ]; then @@ -192,12 +186,13 @@ if [ "$1" = "autoconf" ]; then else echo yes fi - exit 0 -fi +} -# --- CONFIG OUTPUT -if [ "$1" = "config" ]; then +do_config() { + local active_guests guest_name draw_style + active_guests=$(get_active_guests "$exclude") + cat <&2 "Invalid action requested (none of: autoconf / config / '')" + exit 1 +esac From 59cb851cf5ed377f3c4164c63535335cd7d0421e Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:51:43 +0200 Subject: [PATCH 40/48] Plugin lxc: add support for MUNIN_CAP_DIRTYCONFIG --- plugins/lxc/lxc-multigraph | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index d273b543..bc7866de 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -402,6 +402,7 @@ case "${1:-}" in ;; config) do_config + if [ "${MUNIN_CAP_DIRTYCONFIG:-0}" = 1 ]; then do_fetch; fi exit 0 ;; "") From 856572ad9b02d39d46cb8f333f956e893323cbfd Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:02:31 +0200 Subject: [PATCH 41/48] Plugin lxc: verify the availability of "lxc-ls" Previously "autoconf" only verified, that /var/lib/lxc exists. But this could be just a remainder of a formerly installed lxc package. --- plugins/lxc/lxc-multigraph | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index bc7866de..102349e9 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -183,6 +183,8 @@ do_autoconf() { 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 From 3f8ef105ff86465321b8f0831d147f3afb45e940 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:05:33 +0200 Subject: [PATCH 42/48] Plugin lxc: enable "set -eu" for better error handling The code should be suitable for "exit-on-error" and "error-on-unset". --- plugins/lxc/lxc-multigraph | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 102349e9..4b2bbe67 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -81,6 +81,9 @@ or GPLv3 license or later, at your option =cut +set -eu + + . "$MUNIN_LIBDIR/plugins/plugin.sh" From f69587c28cb51dd78aa3377a7e9ae05a4d84f476 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:14:30 +0200 Subject: [PATCH 43/48] Plugin lxc: move to category "virtualization" See http://guide.munin-monitoring.org/en/latest/reference/graph-category.html#well-known-categories --- plugins/lxc/lxc-multigraph | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 4b2bbe67..7cffcfb1 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -203,7 +203,7 @@ multigraph lxc_cpu graph_title CPU Usage graph_args -l 0 --base 1000 graph_vlabel USER_HZ -graph_category lxc +graph_category virtualization EOF for guest_name in $active_guests @@ -224,7 +224,7 @@ multigraph lxc_cpu_time graph_title CPU time graph_args -l 0 --base 1000 graph_vlabel nanosec -graph_category lxc +graph_category virtualization EOF for guest_name in $active_guests @@ -240,7 +240,7 @@ EOF multigraph lxc_logins graph_title Logins -graph_category lxc +graph_category virtualization EOF for guest_name in $active_guests @@ -257,7 +257,7 @@ multigraph lxc_net graph_title Network traffic graph_args --base 1000 graph_vlabel bits in (-) / out (+) per \${graph_period} -graph_category lxc +graph_category virtualization graph_info This graph shows the traffic of active LXC containers. EOF @@ -295,7 +295,7 @@ multigraph lxc_proc graph_title Processes graph_args -l 0 --base 1000 graph_vlabel Number of processes -graph_category lxc +graph_category virtualization EOF for guest_name in $active_guests do @@ -312,7 +312,7 @@ multigraph lxc_ram graph_title Memory graph_args -l 0 --base 1024 graph_vlabel byte -graph_category lxc +graph_category virtualization EOF for guest_name in $active_guests From 2f1be9f90810976f225ceee01ab04d78418d1526 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:16:54 +0200 Subject: [PATCH 44/48] Plugin lxc: update list of authors --- plugins/lxc/lxc-multigraph | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 7cffcfb1..0b6c85d7 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -65,6 +65,7 @@ with the previous implementation. vajtsz vajtsz@gmail.com mitty mitty@mitty.jp alphanet schaefer@alphanet.ch (many changes and multigraph) +Lars Kruse See https://framagit.org/alphanet/various-stuff (plugins/lcx) From 3ebcb8b5500e664c36c5d09892af815dc428efac Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:17:06 +0200 Subject: [PATCH 45/48] Plugin lxc: remove reference to framagit repository Plugins maintained within the contrib repository of munin should not refer to other locations as their primary source. (otherwise they should be maintained in that primary source and not in the contrib repository) --- plugins/lxc/lxc-multigraph | 3 --- 1 file changed, 3 deletions(-) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc-multigraph index 0b6c85d7..90770d47 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc-multigraph @@ -67,9 +67,6 @@ mitty mitty@mitty.jp alphanet schaefer@alphanet.ch (many changes and multigraph) Lars Kruse -See https://framagit.org/alphanet/various-stuff -(plugins/lcx) - =head1 LICENSE 2-clause BSD License From 858f3e3af439284ab6a73a030fd7a19bbcec8770 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 01:55:53 +0200 Subject: [PATCH 46/48] Plugin lxc: rename to "lxc_guests" The plugin handles details of LXC guests. Thus we should leave the remainder of the namespace to other plugins. --- plugins/lxc/{lxc-multigraph => lxc_guests} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename plugins/lxc/{lxc-multigraph => lxc_guests} (99%) diff --git a/plugins/lxc/lxc-multigraph b/plugins/lxc/lxc_guests similarity index 99% rename from plugins/lxc/lxc-multigraph rename to plugins/lxc/lxc_guests index 90770d47..6d42bedb 100755 --- a/plugins/lxc/lxc-multigraph +++ b/plugins/lxc/lxc_guests @@ -5,11 +5,11 @@ =head1 NAME -lxc-multigraph - Plugin to monitor LXC containers (v2.0) +lxc_guests - collect statistics about containers virtualized via LXC =head1 CONFIGURATION - [lxc-multigraph] + [lxc_guests] user root # The memory usage of containers are by default drawn as stacked area From 6e452ac6dc480300780768bc6b7586a9abc0a854 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Mon, 12 Aug 2019 02:23:48 +0200 Subject: [PATCH 47/48] Plugin lxc: remove fieldname compatibility attempt with double underscores The attempt of compatibility (introduced in c0fe6dc3c) did not work, since the previous implementation *replaced* the first character (if it was invalid - e.g. a digit) instead of prepending an underscore. --- plugins/lxc/lxc_guests | 86 +++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 44 deletions(-) diff --git a/plugins/lxc/lxc_guests b/plugins/lxc/lxc_guests index 6d42bedb..0b201a3d 100755 --- a/plugins/lxc/lxc_guests +++ b/plugins/lxc/lxc_guests @@ -57,8 +57,6 @@ container. Tested on Debian buster and Debian jessie. -The double __ for values is for compatibility -with the previous implementation. =head1 AUTHOR @@ -209,9 +207,9 @@ EOF for cpu_usage in user system do cat < Date: Mon, 19 Aug 2019 15:07:16 +0200 Subject: [PATCH 48/48] - grep -EF is invalid - SYSFS: buster has an existing /sys/fs/cgroup/systemd/lxc/$guest_name/tasks, which does not contain anything useful, so checking /sys/fs/cgroup/cpuacct/lxc/$guest_name/tasks first. - spurious blank space for lxc_net and lxc_ram in here document --- plugins/lxc/lxc_guests | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/lxc/lxc_guests b/plugins/lxc/lxc_guests index 0b201a3d..97608d4d 100755 --- a/plugins/lxc/lxc_guests +++ b/plugins/lxc/lxc_guests @@ -121,8 +121,8 @@ lxc_netdev() { if [ -f "$lxcpath/$guest_name/config" ]; then # lxc 3 vs < 3 - (grep -EF '^lxc.net.0.veth.pair' "$lxcpath/$guest_name/config" 2>/dev/null \ - || grep -EF '^lxc.network.veth.pair' "$lxcpath/$guest_name/config" + (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 } @@ -152,8 +152,8 @@ lxc_count_processes () { for SYSFS in \ "/sys/fs/cgroup/$guest_name/tasks" \ "/sys/fs/cgroup/lxc/$guest_name/tasks" \ - "/sys/fs/cgroup/systemd/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 @@ -372,8 +372,8 @@ do_fetch() { fi cat <