From 5dc3787f00676bba8f521dbf3fd228f38c6f7445 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Wed, 8 May 2013 23:51:44 +0900 Subject: [PATCH 1/4] add new option 'env.stack_usage' to lxc_ram * draw memory usages of containers as stacked area charts * the type of other graphs are not changed (default -> LINE2) --- plugins/lxc/lxc_ram | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index db770778..004f829a 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.stack_usage true + =head1 INTERPRETATION This plugin needs root privilege. +If env.stack_usage 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: empty) + =head1 AUTHOR vajtsz vajtsz@gmail.com @@ -62,13 +70,24 @@ if [ "$1" = "config" ]; then echo 'graph_vlabel byte' echo 'graph_category memory' + if [ "$stack_usage" = "true" ]; then + for guest_name in $guest_names; do + guest="$(clean_fieldname $guest_name)" + + echo 'mem_usage_'$guest'.label '$guest_name': Mem usage' + echo 'mem_usage_'$guest'.type GAUGE' + echo 'mem_usage_'$guest'.draw AREASTACK' + done + fi 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 [ "$stack_usage" != "true" ]; then + echo 'mem_usage_'$guest'.label '$guest_name': Mem usage' + echo 'mem_usage_'$guest'.type GAUGE' + fi echo 'mem_cache_'$guest'.label '$guest_name': Cache' echo 'mem_cache_'$guest'.type GAUGE' echo 'mem_active_'$guest'.label '$guest_name': Active' From 1c917e64b084eff773a808220239e4972035fa0b Mon Sep 17 00:00:00 2001 From: Adrian Moisey Date: Tue, 8 Jul 2014 11:41:35 +0200 Subject: [PATCH 2/4] Add support for Ubuntu 14.04 --- plugins/lxc/lxc_proc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/lxc/lxc_proc b/plugins/lxc/lxc_proc index c2e3b02d..d1aa7a9a 100755 --- a/plugins/lxc/lxc_proc +++ b/plugins/lxc/lxc_proc @@ -41,6 +41,7 @@ Unknown license # 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 count_processes () { [ -z "$1" ] && return 0 @@ -54,6 +55,7 @@ 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 From 58e5b2f32ca05f5e9410dd5a64998ef72ba0bdeb Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Sun, 31 Jul 2016 21:42:32 +0900 Subject: [PATCH 3/4] rename option to 'env.areastack' --- plugins/lxc/lxc_ram | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index 004f829a..c0437341 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -13,16 +13,16 @@ lxc_ram - Plugin to monitor LXC memory usage. user root [lxc_ram] - env.stack_usage true + env.areastack true =head1 INTERPRETATION This plugin needs root privilege. -If env.stack_usage is set to true, all memory usages of containers will be +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: empty) +(default: false) =head1 AUTHOR @@ -70,7 +70,7 @@ if [ "$1" = "config" ]; then echo 'graph_vlabel byte' echo 'graph_category memory' - if [ "$stack_usage" = "true" ]; then + if [ "$areastack" = "true" ]; then for guest_name in $guest_names; do guest="$(clean_fieldname $guest_name)" @@ -84,7 +84,7 @@ if [ "$1" = "config" ]; then do guest="$(clean_fieldname $guest_name)" - if [ "$stack_usage" != "true" ]; then + if [ "$areastack" != "true" ]; then echo 'mem_usage_'$guest'.label '$guest_name': Mem usage' echo 'mem_usage_'$guest'.type GAUGE' fi From 1c412d1907b4cbaa6645aa08f5af073dbffb59b3 Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Sun, 5 Mar 2017 00:19:58 +0900 Subject: [PATCH 4/4] refactor: code of areastack option is hard to understand - reviewed on https://github.com/munin-monitoring/contrib/pull/738#pullrequestreview-5187474 - split two conditional branches to simple if-else code --- plugins/lxc/lxc_ram | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/plugins/lxc/lxc_ram b/plugins/lxc/lxc_ram index c0437341..4208f875 100755 --- a/plugins/lxc/lxc_ram +++ b/plugins/lxc/lxc_ram @@ -78,16 +78,10 @@ if [ "$1" = "config" ]; then echo 'mem_usage_'$guest'.type GAUGE' echo 'mem_usage_'$guest'.draw AREASTACK' done - fi + + for guest_name in $guest_names; do + guest="$(clean_fieldname $guest_name)" - for guest_name in $guest_names; - do - guest="$(clean_fieldname $guest_name)" - - if [ "$areastack" != "true" ]; then - echo 'mem_usage_'$guest'.label '$guest_name': Mem usage' - echo 'mem_usage_'$guest'.type GAUGE' - fi echo 'mem_cache_'$guest'.label '$guest_name': Cache' echo 'mem_cache_'$guest'.type GAUGE' echo 'mem_active_'$guest'.label '$guest_name': Active' @@ -96,6 +90,22 @@ if [ "$1" = "config" ]; then echo 'mem_inactive_'$guest'.type GAUGE' done + else + for guest_name in $guest_names; + do + guest="$(clean_fieldname $guest_name)" + + echo 'mem_usage_'$guest'.label '$guest_name': Mem usage' + echo 'mem_usage_'$guest'.type GAUGE' + echo 'mem_cache_'$guest'.label '$guest_name': Cache' + echo 'mem_cache_'$guest'.type GAUGE' + echo 'mem_active_'$guest'.label '$guest_name': Active' + echo 'mem_active_'$guest'.type GAUGE' + echo 'mem_inactive_'$guest'.label '$guest_name': Inactive' + echo 'mem_inactive_'$guest'.type GAUGE' + + done + fi exit 0 fi