From edb4e1e81b3a4888925df8b510f116a7720f375a Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:38:52 +0200 Subject: [PATCH 1/7] Plugin apache_memory: specify common default values Previously the plugin did not work without configuration. Now it should work on many systems out of the box. --- plugins/apache/apache_memmory | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index 4e829191..f754e00f 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -10,8 +10,8 @@ apache_memmory -Indicate the medium size of all the apache child process =head1 CONFIGURATION [apache_*] -env.apuser user_running_apache -env.binname apache_binary_name +env.apuser user_running_apache (default: "www-data") +env.binname apache_binary_name (default: "apache2") =head1 AUTHOR @@ -31,8 +31,8 @@ GPLv2 . $MUNIN_LIBDIR/plugins/plugin.sh -USR=$apuser -PROCS=$binname +USR=${apuser:-www-data} +PROCS=${binname:-apache2} if [ "$1" = "autoconf" ]; then From b087127c04dc996527a1989c83966d7d5731814b Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:40:54 +0200 Subject: [PATCH 2/7] Plugin apache_memory: unify whitespace --- plugins/apache/apache_memmory | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index f754e00f..24583bb0 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -36,26 +36,24 @@ PROCS=${binname:-apache2} if [ "$1" = "autoconf" ]; then - echo yes - exit 0 + echo yes + exit 0 fi if [ "$1" = "config" ]; then - echo 'graph_title Medium size of apache child process.' - echo 'graph_args --base 1000 -l 0 ' - echo 'graph_vlabel Kb' - echo 'graph_scale no' - echo 'graph_category webserver' - echo 'graph_info Indicate the memdium size of all the apache child process.' + echo 'graph_title Medium size of apache child process.' + echo 'graph_args --base 1000 -l 0 ' + echo 'graph_vlabel Kb' + echo 'graph_scale no' + echo 'graph_category webserver' + echo 'graph_info Indicate the memdium size of all the apache child process.' + echo "servers.label servers" + echo "servers.type GAUGE" + echo "servers.min 0" - - echo "servers.label servers" - echo "servers.type GAUGE" - echo "servers.min 0" - - exit 0 + exit 0 fi VAL1=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | wc -l` From dd41152cdd6e5a12dd43dc4df03f4e5e46924b65 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:41:42 +0200 Subject: [PATCH 3/7] Plugin apache_memory: properly quote patterns and simplify calculation Previously the calculation had some issues: * patterns with whitespace caused errors * the number of processes could change between the steps for counting and averaging * handle "no match" properly (returning "U" - unknown - instead of an error) * avoid calculation based on unsafe "eval" --- plugins/apache/apache_memmory | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index 24583bb0..87a93a72 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -56,12 +56,11 @@ if [ "$1" = "config" ]; then exit 0 fi -VAL1=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | wc -l` - -VAL2=`ps auxf | grep ${PROCS} | grep ^${USR} | grep -v grep | awk '{s+=$6} END {print s}'` - -VAL3=`expr $VAL2 / $VAL1` - -echo "servers.value $VAL3" - +matched_processes=$(ps auxf | grep -- "$PROCS" | grep "^$USR" | grep -v grep) +if [ -n "$matched_processes" ]; then + average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum/count}') +else + average_memory="U" +fi +echo "servers.value $average_memory" From 1ac5fbdfe0dc941664711ee52414b2966957cdc9 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:45:47 +0200 Subject: [PATCH 4/7] Plugin apache_memory: fix quoting --- plugins/apache/apache_memmory | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index 87a93a72..e8dd47e6 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -29,7 +29,7 @@ GPLv2 =cut -. $MUNIN_LIBDIR/plugins/plugin.sh +. "$MUNIN_LIBDIR/plugins/plugin.sh" USR=${apuser:-www-data} PROCS=${binname:-apache2} From d8fd604e8fd9718c495f1ecbb75d6405c3e55432 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:46:23 +0200 Subject: [PATCH 5/7] Plugin apache_memory: improve title --- plugins/apache/apache_memmory | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index e8dd47e6..1390d4dc 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -42,7 +42,7 @@ fi if [ "$1" = "config" ]; then - echo 'graph_title Medium size of apache child process.' + echo 'graph_title Average size of apache child processes' echo 'graph_args --base 1000 -l 0 ' echo 'graph_vlabel Kb' echo 'graph_scale no' From e7fbfe0b8b12cde37600298ee4878a993ea798e2 Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:51:02 +0200 Subject: [PATCH 6/7] Plugin apache_memory: use base SI units for result Munin will take care for proper units dynamically. This breaks previously existing graphs. --- plugins/apache/apache_memmory | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memmory index 1390d4dc..2a391ee5 100755 --- a/plugins/apache/apache_memmory +++ b/plugins/apache/apache_memmory @@ -43,8 +43,8 @@ fi if [ "$1" = "config" ]; then echo 'graph_title Average size of apache child processes' - echo 'graph_args --base 1000 -l 0 ' - echo 'graph_vlabel Kb' + echo 'graph_args --base 1024 -l 0 ' + echo 'graph_vlabel Bytes' echo 'graph_scale no' echo 'graph_category webserver' echo 'graph_info Indicate the memdium size of all the apache child process.' @@ -58,7 +58,7 @@ fi matched_processes=$(ps auxf | grep -- "$PROCS" | grep "^$USR" | grep -v grep) if [ -n "$matched_processes" ]; then - average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum/count}') + average_memory=$(printf '%s' "$matched_processes" | awk '{count+=1; sum+=$6} END {print sum / count * 1024}') else average_memory="U" fi From 62ff5981d2660c95907c531a214690d6bdf167dc Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Tue, 21 Apr 2020 19:51:52 +0200 Subject: [PATCH 7/7] Rename plugin "apache_memmory" to "apache_memory" The original name was misspelled. --- plugins/apache/{apache_memmory => apache_memory} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/apache/{apache_memmory => apache_memory} (100%) diff --git a/plugins/apache/apache_memmory b/plugins/apache/apache_memory similarity index 100% rename from plugins/apache/apache_memmory rename to plugins/apache/apache_memory