From c3cf6b45d32725419d806a5f64bb08eadf7763a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Wed, 23 Mar 2016 22:33:22 -0300 Subject: [PATCH 1/4] php_errors handle multiple logs --- plugins/php/php_errors | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/php/php_errors b/plugins/php/php_errors index b38ce74c..315c0f6f 100644 --- a/plugins/php/php_errors +++ b/plugins/php/php_errors @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # Plugin to monitor error.log from apache server. # Revision 0.1 2011/06/17 12:00:00 Ulrich Lusseau @@ -14,27 +14,28 @@ #%# capabilities=autoconf # config example for /etc/munin/plugin-conf.d/munin-node #[apache_log] -#user root -#env.logfile /home/newsite/logs/errors.log +#user www-data +#env.logfile /home/newsite/logs/errors.log /var/log/php/otherlog.log # -LOG=${logfile:-/var/log/apache2/error.log} +LOGS=${logfile:-/var/log/apache2/error.log} if [ "$1" = "autoconf" ]; then - if [ -r "$LOG" ]; then - echo yes - exit 0 - else - echo no - exit 1 + for LOG in $LOGS; do + if [[ ! -r $LOGS ]]; then + echo no + exit 1 fi + done + + echo yes + exit 0 fi if [ "$1" = "config" ]; then - - echo 'graph_title PHP Errors from ' $LOG + echo 'graph_title PHP Errors from ' $LOGS echo 'graph_args --base 1000 -l 0' echo 'graph_vlabel Errors' echo 'LogWarning.label PHP Warning errors' @@ -49,4 +50,4 @@ awk 'BEGIN{c["LogWarning"]=0;c["LogNotice"]=0;c["LogFatal"]=0;c["LogFile"]=0; } /PHP Notice/{c["LogNotice"]++} /PHP Fatal error/{c["LogFatal"]++} /File does not exist/{c["LogFile"]++} - END{for(i in c){print i".value " c[i]} }' < $LOG + END{for(i in c){print i".value " c[i]} }' $LOGS From c324c34ea7a1890b7cfd6d58498abeaabf82a626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Wed, 23 Mar 2016 22:42:47 -0300 Subject: [PATCH 2/4] php_errors: coding-style/bash --- plugins/php/php_errors | 71 +++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/plugins/php/php_errors b/plugins/php/php_errors index 315c0f6f..4e7efe8e 100644 --- a/plugins/php/php_errors +++ b/plugins/php/php_errors @@ -1,28 +1,38 @@ #!/bin/bash -# -# Plugin to monitor error.log from apache server. -# Revision 0.1 2011/06/17 12:00:00 Ulrich Lusseau -# Initial revision -# -# Parameters: -# -# config (required) -# autoconf (optional - used by munin-config) -# -# Magick markers (optional): -#%# family=auto -#%# capabilities=autoconf -# config example for /etc/munin/plugin-conf.d/munin-node -#[apache_log] -#user www-data -#env.logfile /home/newsite/logs/errors.log /var/log/php/otherlog.log -# - - + +: << =cut + +=head1 NAME + +Plugin to monitor error.log from apache server + +=head1 CONFIGURATION + +[apache_log] + user www-data + env.logfile /home/newsite/logs/errors.log /var/log/php/otherlog.log + +=head1 AUTHOR + +Raphaël Droz + +Revision 0.2 2016/03/23 22:00:00 Raphaël Droz +Revision 0.1 2011/06/17 12:00:00 Ulrich Lusseau + +=head1 MAGICK MARKERS + + #%# family=auto + #%# capabilities=autoconf + +=cut + + +. $MUNIN_LIBDIR/plugins/plugin.sh + LOGS=${logfile:-/var/log/apache2/error.log} -if [ "$1" = "autoconf" ]; then +if [[ $1 == autoconf ]]; then for LOG in $LOGS; do if [[ ! -r $LOGS ]]; then echo no @@ -34,7 +44,7 @@ if [ "$1" = "autoconf" ]; then exit 0 fi -if [ "$1" = "config" ]; then +if [[ $1 == config ]]; then echo 'graph_title PHP Errors from ' $LOGS echo 'graph_args --base 1000 -l 0' echo 'graph_vlabel Errors' @@ -44,10 +54,13 @@ if [ "$1" = "config" ]; then echo 'LogFile.label File does not exist errors' exit 0 fi - -awk 'BEGIN{c["LogWarning"]=0;c["LogNotice"]=0;c["LogFatal"]=0;c["LogFile"]=0; } - /PHP Warning/{c["LogWarning"]++} - /PHP Notice/{c["LogNotice"]++} - /PHP Fatal error/{c["LogFatal"]++} - /File does not exist/{c["LogFile"]++} - END{for(i in c){print i".value " c[i]} }' $LOGS + +awk -f - $LOGS < Date: Wed, 23 Mar 2016 23:10:03 -0300 Subject: [PATCH 3/4] php_errors plugin is multi-instance compatible --- plugins/php/{php_errors => php_errors_} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/php/{php_errors => php_errors_} (100%) diff --git a/plugins/php/php_errors b/plugins/php/php_errors_ similarity index 100% rename from plugins/php/php_errors rename to plugins/php/php_errors_ From edd681a891f2257eb1325989b71aee2917c1eb62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= Date: Mon, 4 Apr 2016 13:17:51 -0300 Subject: [PATCH 4/4] fixed usage example --- plugins/php/php_errors_ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/php/php_errors_ b/plugins/php/php_errors_ index 4e7efe8e..e8788368 100644 --- a/plugins/php/php_errors_ +++ b/plugins/php/php_errors_ @@ -8,7 +8,7 @@ Plugin to monitor error.log from apache server =head1 CONFIGURATION -[apache_log] +[php_errors_newsite] user www-data env.logfile /home/newsite/logs/errors.log /var/log/php/otherlog.log