From 2812f751f01095bef32500e811dade8851c9b17f Mon Sep 17 00:00:00 2001 From: Gareth Davies Date: Thu, 16 May 2013 18:07:01 +0800 Subject: [PATCH 1/4] Added new non Ruby based Unicorn Plugin The existing Unicorn plugins are written in Ruby, which didn't work well for me due to ENV variables etc. This plugin monitors number of workers, total memory used and average memory per process for Unicorn. ln -s /usr/share/munin/plugins/unicorn_ /etc/munin/plugins/unicorn_average ln -s /usr/share/munin/plugins/unicorn_ /etc/munin/plugins/unicorn_memory ln -s /usr/share/munin/plugins/unicorn_ /etc/munin/plugins/unicorn_processes It can easily be adapated to any multi threaded server by just changing the value it searches for 'unicorn worker' in this case. --- plugins/unicorn/unicorn_ | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 plugins/unicorn/unicorn_ diff --git a/plugins/unicorn/unicorn_ b/plugins/unicorn/unicorn_ new file mode 100644 index 00000000..eac0453f --- /dev/null +++ b/plugins/unicorn/unicorn_ @@ -0,0 +1,56 @@ + +#!/bin/bash +# Copyright (c) 2013 Gareth Davies (shaolintiger@gmail.com www.shaolintiger.com) +# License GPLv2 + +mode=`echo $0 | cut -d _ -f 2` + +if [ "$1" = "suggest" ]; then + echo "memory" + echo "processes" + echo "average" + exit 0 +fi + +if [ "$mode" = "memory" ]; then + if [ "$1" = "config" ]; then + echo "graph_title Unicorn Memory" + echo "graph_vlabel RAM" + echo "graph_category Unicorn" + echo "graph_args --base 1024" + echo "ram.label RAM" + exit 0 + else + echo -n "ram.value " + ps awwwux | grep 'unicorn worker' | grep -v grep | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' + fi + +elif [ "$mode" = "processes" ]; then + if [ "$1" = "config" ]; then + echo "graph_title Unicorn Processes" + echo "graph_vlabel Processes" + echo "graph_category Unicorn" + echo "processes.label active processes" + else + echo -n "processes.value " + ps awwwux | grep 'unicorn worker' | grep -v grep | wc -l + exit 0 + fi + +elif [ "$mode" = "average" ]; then + if [ "$1" = "average" ]; then + echo 'graph_title Unicorn Average Process Size' + echo 'graph_args --base 1024 -l 0 ' + echo 'graph_vlabel Unicorn Average Process Size' + echo 'graph_category Unicorn' + echo 'php_average.label Unicorn Average Proccess Size' + echo 'php_average.draw LINE2' + echo 'php_average.info The average process size for Unicorn' + else + echo -n "average.value " + ps awwwux | grep 'unicorn worker' | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' + exit 0 + fi + +fi +exit 0 From 8ff6e0fdf22cc083a8ba7081fd7ba224c3f371f2 Mon Sep 17 00:00:00 2001 From: Gareth Davies Date: Thu, 16 May 2013 18:57:51 +0800 Subject: [PATCH 2/4] Update unicorn_ - Fixed memory and average giving same results - Fixed error in average graphing --- plugins/unicorn/unicorn_ | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/plugins/unicorn/unicorn_ b/plugins/unicorn/unicorn_ index eac0453f..533ccddf 100644 --- a/plugins/unicorn/unicorn_ +++ b/plugins/unicorn/unicorn_ @@ -1,4 +1,3 @@ - #!/bin/bash # Copyright (c) 2013 Gareth Davies (shaolintiger@gmail.com www.shaolintiger.com) # License GPLv2 @@ -14,15 +13,23 @@ fi if [ "$mode" = "memory" ]; then if [ "$1" = "config" ]; then - echo "graph_title Unicorn Memory" - echo "graph_vlabel RAM" + echo "graph_title Total Unicorn Memory" + echo "graph_vlabel Total RAM" echo "graph_category Unicorn" echo "graph_args --base 1024" - echo "ram.label RAM" + echo "ram.label Total RAM" exit 0 else - echo -n "ram.value " - ps awwwux | grep 'unicorn worker' | grep -v grep | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' + + memory_array=(`ps auwx | grep "unicorn worker" | grep -v grep | awk '{print $6 }'`) + + for i in "${memory_array[@]}" + do + sum=$(( $sum + $i )) + done + echo -n "ram.value " + echo $sum + fi elif [ "$mode" = "processes" ]; then @@ -38,14 +45,14 @@ elif [ "$mode" = "processes" ]; then fi elif [ "$mode" = "average" ]; then - if [ "$1" = "average" ]; then + if [ "$1" = "config" ]; then echo 'graph_title Unicorn Average Process Size' echo 'graph_args --base 1024 -l 0 ' echo 'graph_vlabel Unicorn Average Process Size' echo 'graph_category Unicorn' - echo 'php_average.label Unicorn Average Proccess Size' - echo 'php_average.draw LINE2' - echo 'php_average.info The average process size for Unicorn' + echo 'unicorn_average.label Unicorn Average Proccess Size' + echo 'unicorn_average.draw LINE2' + echo 'unicorn_average.info The average process size for Unicorn' else echo -n "average.value " ps awwwux | grep 'unicorn worker' | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' @@ -54,3 +61,4 @@ elif [ "$mode" = "average" ]; then fi exit 0 + From 9dfe0f34ca4968ebc298636e4d128be5d2233323 Mon Sep 17 00:00:00 2001 From: Gareth Davies Date: Thu, 16 May 2013 19:27:13 +0800 Subject: [PATCH 3/4] Fixed average memory graphing label error. Fixed average memory graphing label error. --- plugins/unicorn/unicorn_ | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/unicorn/unicorn_ b/plugins/unicorn/unicorn_ index 533ccddf..eb39ac39 100644 --- a/plugins/unicorn/unicorn_ +++ b/plugins/unicorn/unicorn_ @@ -48,17 +48,16 @@ elif [ "$mode" = "average" ]; then if [ "$1" = "config" ]; then echo 'graph_title Unicorn Average Process Size' echo 'graph_args --base 1024 -l 0 ' - echo 'graph_vlabel Unicorn Average Process Size' + echo 'graph_vlabel Average Process Size' echo 'graph_category Unicorn' - echo 'unicorn_average.label Unicorn Average Proccess Size' + echo 'unicorn_average.label Average Process Size' echo 'unicorn_average.draw LINE2' echo 'unicorn_average.info The average process size for Unicorn' else - echo -n "average.value " + echo -n "unicorn_average.value " ps awwwux | grep 'unicorn worker' | grep -v grep | grep -v master | awk '{total_mem = $6 * 1024 + total_mem; total_proc++} END{printf("%d\n", total_mem / total_proc)}' exit 0 fi fi exit 0 - From 6274c3af80cc3e6fb3197d6c5a153d2ec9063ab6 Mon Sep 17 00:00:00 2001 From: Gareth Davies Date: Wed, 29 May 2013 06:21:11 +0800 Subject: [PATCH 4/4] Fixed total memory being in the wrong scale --- plugins/unicorn/unicorn_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/unicorn/unicorn_ b/plugins/unicorn/unicorn_ index eb39ac39..74a7e30a 100644 --- a/plugins/unicorn/unicorn_ +++ b/plugins/unicorn/unicorn_ @@ -25,7 +25,7 @@ if [ "$mode" = "memory" ]; then for i in "${memory_array[@]}" do - sum=$(( $sum + $i )) + sum=$(( $sum + ( $i * 1024) )) done echo -n "ram.value " echo $sum