2
0
mirror of https://github.com/munin-monitoring/contrib.git synced 2018-11-08 00:59:34 +01:00
contrib-munin/plugins/nginx/nginx_error

143 lines
3.2 KiB
Plaintext
Raw Normal View History

2013-05-29 18:50:58 +02:00
#!/bin/bash
# -*- bash -*-
2013-06-02 22:49:38 +02:00
: <<=cut
2013-05-29 18:50:58 +02:00
=head1 NAME
nginx error - Munin plugin to monitor nginx error rates (http status codes per minute).
=head1 APPLICABLE SYSTEMS
Any Linux host, running nginx, with bash version > 4.0
=head1 CONFIGURATION
This shows the default configuration of this plugin. You can override
the log file path and the logpattern.
[nginx_error]
env.logpath /var/log/nginx
env.logpattern a.*.log
Nginx must also be configured to log accesses in "combined" log format (default)
=head1 USAGE
Link this plugin to /etc/munin/plugins/ and restart the munin-node.
This plugin also can be used like wildcard-plugin for monitoring particular virtual host log.
E.g.
ln -s /usr/share/munin/plugins/nginx_error /etc/munin/plugins/nginx_error_mydomaincom
will parse the log file /var/log/nginx/a.mydomaincom.log
You can change 'env.logpattern' using asterisk ('*') to match your logs filenames.
=head1 INTERPRETATION
The plugin shows nginx http "error" status rates by parsing access log.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 BUGS
None known.
=head1 VERSION
1.1 - 2018/01/20
* improve readability of symlink configuration code
1.0 - 2017/02/21
2013-05-29 18:50:58 +02:00
2013-05-29 18:50:58 +02:00
=head1 AUTHOR
vovansystems@gmail.com, 2013
=head1 LICENSE
GPLv3
=cut
# default environment variable values
logpath=${logpath:-/var/log/nginx}
2013-05-29 18:50:58 +02:00
# derive the name of the log file from a potential symlink-configured virtual host
script_name=$(basename "$0")
plugin_suffix=${script_name#nginx_error}
if [ -n "${plugin_suffix#_}" ]; then
# a domain was given via symlink configuration: adjust the logpattern
domain=${plugin_suffix#_}
# default logpattern for symlink configuration mode
logpattern=${logpattern:-a.*.log}
log_filename=${logpattern/\*/$domain}
2013-05-29 18:50:58 +02:00
else
log_filename='access.log'
2013-05-29 18:50:58 +02:00
fi
log="$logpath/$log_filename"
2013-05-29 18:50:58 +02:00
# declaring an array with http status codes, we are interested in
declare -A http_codes
http_codes[400]='Bad Request'
http_codes[401]='Unauthorized'
http_codes[403]='Forbidden'
http_codes[404]='Not Found'
http_codes[405]='Method Not Allowed'
http_codes[406]='Not Acceptable'
http_codes[408]='Request Timeout'
http_codes[429]='Too Many Requests'
http_codes[499]='Client Connection Terminated'
http_codes[500]='Internal Server Error'
http_codes[502]='Bad Gateway'
http_codes[503]='Service Unavailable'
do_ () { # Fetch
declare -A line_counts
values=`awk '{print $9}' $log | sort | uniq -c`
2017-02-21 17:28:44 +01:00
if [ -n "$values" ]; then
while read -r line; do
read -a tmp <<< "$line";
line_counts[${tmp[1]}]=${tmp[0]};
done <<< "$values"
fi
2013-05-29 18:50:58 +02:00
for k in ${!http_codes[@]}; do
echo "error$k.value ${line_counts[$k]:-0}"
2013-05-29 18:50:58 +02:00
done
exit 0
}
do_config () {
echo "graph_title $(basename "$log") - Nginx errors per minute"
2013-05-29 18:50:58 +02:00
echo 'graph_vlabel pages with http error codes / ${graph_period}'
echo "graph_category webserver"
2013-05-29 18:50:58 +02:00
echo "graph_period minute"
echo "graph_info This graph shows nginx error amount per minute"
for k in ${!http_codes[@]}; do
echo "error$k.type DERIVE"
echo "error$k.min 0"
echo "error$k.label $k ${http_codes[$k]}"
done
exit 0
}
do_autoconf () {
echo yes
exit 0
}
case $1 in
config|autoconf|'')
eval do_$1
esac
2013-06-02 22:49:38 +02:00
exit $?