Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

i have written a munin-plugin to count the http-statuscodes of lighttpd. The script:

#!/bin/bash

######################################
# Munin-Script: Lighttpd-Statuscodes #
######################################

##Config
# path to  lighttpd access.log
LIGHTTPD_ACCESS_LOG_PATH="/var/log/lighttpd/access.log"
# rows to parse in logfile (higher value incrase time to run plugin. if value to low you may get bad counting)
LOG_ROWS="200000"
#
#munin
case $1 in
   autoconf) # check config
        AVAILABLE=`ls $LIGHTTPD_ACCESS_LOG_PATH`
        if [ "$AVAILABLE" = "$LIGHTTPD_ACCESS_LOG_PATH" ]; then
           echo "yes"
        else
           echo "No: "$AVAILABLE
           echo "Please check your config!"
        fi
        exit 0;;
   config) # graph config
        cat <<'EOM'
graph_title Lighhtpd Statuscodes
graph_vlabel http-statuscodes / min
graph_category lighttpd
1xx.label 1xx
2xx.label 2xx
3xx.label 3xx
4xx.label 4xx
5xx.label 5xx
EOM
        exit 0;;
esac

## calculate
AVAILABLE=`ls $LIGHTTPD_ACCESS_LOG_PATH`
if [ "$AVAILABLE" = "$LIGHTTPD_ACCESS_LOG_PATH" ]; then
   TIME_NOW=`date`
   CODE_1xx="0"
   CODE_2xx="0"
   CODE_3xx="0"
   CODE_4xx="0"
   CODE_5xx="0"
   for i in 1 2 3 4 5; do
        TIME5=`date +%d/%b/%Y:%k:%M --date "$TIME_NOW -"$i"min"`
        CODE_1xx=$(( $CODE_1xx + `tail -n $LOG_ROWS $LIGHTTPD_ACCESS_LOG_PATH | grep "$TIME5" | grep 'HTTP/1.1" 1' | grep -c " "` ))
        CODE_2xx=$(( $CODE_2xx + `tail -n $LOG_ROWS $LIGHTTPD_ACCESS_LOG_PATH | grep "$TIME5" | grep 'HTTP/1.1" 2' | grep -c " "` ))
        CODE_3xx=$(( $CODE_3xx + `tail -n $LOG_ROWS $LIGHTTPD_ACCESS_LOG_PATH | grep "$TIME5" | grep 'HTTP/1.1" 3' | grep -c " "` ))
        CODE_4xx=$(( $CODE_4xx + `tail -n $LOG_ROWS $LIGHTTPD_ACCESS_LOG_PATH | grep "$TIME5" | grep 'HTTP/1.1" 4' | grep -c " "` ))
        CODE_5xx=$(( $CODE_5xx + `tail -n $LOG_ROWS $LIGHTTPD_ACCESS_LOG_PATH | grep "$TIME5" | grep 'HTTP/1.1" 5' | grep -c " "` ))
   done
        CODE_1xx=$(( $CODE_1xx / 5 ))
        CODE_2xx=$(( $CODE_2xx / 5 ))
        CODE_3xx=$(( $CODE_3xx / 5 ))
        CODE_4xx=$(( $CODE_4xx / 5 ))
        CODE_5xx=$(( $CODE_5xx / 5 ))

        echo "1xx.value "$CODE_1xx
        echo "2xx.value "$CODE_2xx
        echo "3xx.value "$CODE_3xx
        echo "4xx.value "$CODE_4xx
        echo "5xx.value "$CODE_5xx
else
        echo "1xx.value U"
        echo "2xx.value U"
        echo "3xx.value U"
        echo "4xx.value U"
        echo "5xx.value U"
fi

If i run the script on local machine it runs perfectly:

root@server1 /etc/munin/plugins # ll
lrwxrwxrwx 1 root root   45 2011-12-19 15:23 lighttpd_statuscodes -> /usr/share/munin/plugins/lighttpd_statuscodes*
root@server1 /etc/munin/plugins # ./lighttpd_statuscodes autoconf
yes
root@server1 /etc/munin/plugins # ./lighttpd_statuscodes config
graph_title Lighhtpd Statuscodes
graph_vlabel http-statuscodes / min
graph_category lighttpd
1xx.label 1xx
2xx.label 2xx
3xx.label 3xx
4xx.label 4xx
5xx.label 5xx 
root@server1 /etc/munin/plugins #./lighttpd_statuscodes
1xx.value 0
2xx.value 5834
3xx.value 1892
4xx.value 0
5xx.value 0 

But Munin shows no graph: http://s1.directupload.net/images/111219/3psgq3vb.jpg

I have tested the Plugin from munin-server via telnet:

root@munin-server /etc/munin/plugins/ # telnet 123.123.123.123 4949
Trying 123.123.123.123...
Connected to 123.123.123.123.
Escape character is '^]'.
# munin node at server1.cluster1
fetch lighttpd_statuscodes
1xx.value U
2xx.value U
3xx.value U
4xx.value U
5xx.value U
.
Connection closed by foreign host.

You can see in the script that value = U only printed, when the script can't check the lighttpd's access.log. But why can't script do it, when running via munin, and when running on local machine all is ok?

Is there a bug in my bash-script? I have no Idea. Thanks for helping!

share|improve this question

3 Answers 3

up vote 2 down vote accepted

Do not check munin scripts with just direct scripts running. It's wrong way. There is special perl script munin-run that executes scripts exactly the same way as it runs during munin update and you'll able to find all errors. May be you'll need define special settings for you script. You can do it in /etc/munin/plugin-conf.d/munin-node file next way:

[script_file_mask_*]
user USER_FOR_YOR_SCRIPT
env.VARIABLE some_variable

In your case seems that script just hasn't tighr to read log file. So add

[lighttpd_*]
user root

in /etc/munin/plugin-conf.d/munin-node and restart munin-node. It should help.

share|improve this answer
    
Thank You, this solved the Problem. –  FTV Admin Dec 20 '11 at 9:26
    
well... now i get the correct output when fetching plugin via telnet but the graph don't run correcty and furthermore looks like the picture in my 1st post. "munin-run lighttpd_statuscodes"'s Output is ok. In "munin-update.log" i have a [WARNING]: "2011/12/20 11:20:02 [WARNING] Service ip_176_9_21_130 on server1.cluster1/123.123.123.123:4949 returned no data for label out". Any idea? –  FTV Admin Dec 20 '11 at 10:26

I don't know if you ever managed to fix this yourself, but I did and I thought I'd share my solution.

Rush was right in suggesting to run it as root, but the real error seems to be with your choice of name for your fields (1xx, 2xx, 3xx, ...). As per this wiki page:

Each data source in a plugin must be identified by a field name. The following describes the name of the field:
* The characters must be [a-zA-Z0-9_], while the first character must be [a-zA-Z_].

This is why you only ever saw 5xx in your graph and no results. While creating the rdd files munin replaced the numbers with an underscore (like _xx), which meant the data was overwritten for each of the 5 fields. The easy fix is to add a letter to your field names like so:

graph_category lighttpd
T1xx.label 1xx
T2xx.label 2xx
T3xx.label 3xx
T4xx.label 4xx
T5xx.label 5xx
EOM

        echo "T1xx.value "$CODE_1xx
        echo "T2xx.value "$CODE_2xx
        echo "T3xx.value "$CODE_3xx
        echo "T4xx.value "$CODE_4xx
        echo "T5xx.value "$CODE_5xx
else
        echo "T1xx.value U"
        echo "T2xx.value U"
        echo "T3xx.value U"
        echo "T4xx.value U"
        echo "T5xx.value U"
fi

Like this I got your script working perfectly.

share|improve this answer

Check in /etc/munin/munin-node.conf what username under munin runs, and if that user can read the lighttpd log files.

share|improve this answer
    
munin node runs under root –  FTV Admin Dec 20 '11 at 10:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.