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

nginx_error: improve readability of array accesses

This commit is contained in:
Lars Kruse 2018-01-20 01:25:14 +01:00
parent 8a68200a67
commit 0e864944d7

View File

@ -103,34 +103,30 @@ http_codes[503]='Service Unavailable'
# parse error counts from log file # parse error counts from log file
do_ () { do_ () {
local k values local count status_code
declare -A line_counts declare -A line_counts
values=$(awk '{print $9}' "$log" | sort | uniq -c) while read -r count status_code; do
if [ -n "$values" ]; then line_counts[$status_code]=$count
while read -r line; do done <<< "$(awk '{print $9}' "$log" | sort | uniq -c)"
read -r -a tmp <<< "$line"
line_counts[${tmp[1]}]=${tmp[0]}
done <<< "$values"
fi
for k in "${!http_codes[@]}"; do for status_code in "${!http_codes[@]}"; do
echo "error$k.value ${line_counts[$k]:-0}" echo "error${status_code}.value ${line_counts[$status_code]:-0}"
done done
exit 0 exit 0
} }
do_config () { do_config () {
local k local status_code
echo "graph_title $(basename "$log") - Nginx errors per minute" echo "graph_title $(basename "$log") - Nginx errors per minute"
echo "graph_vlabel pages with http error codes / \${graph_period}" echo "graph_vlabel pages with http error codes / \${graph_period}"
echo "graph_category webserver" echo "graph_category webserver"
echo "graph_period minute" echo "graph_period minute"
echo "graph_info This graph shows nginx error amount per minute" echo "graph_info This graph shows nginx error amount per minute"
for k in "${!http_codes[@]}"; do for status_code in "${!http_codes[@]}"; do
echo "error$k.type DERIVE" echo "error${status_code}.type DERIVE"
echo "error$k.min 0" echo "error${status_code}.min 0"
echo "error$k.label $k ${http_codes[$k]}" echo "error${status_code}.label $status_code ${http_codes[$status_code]}"
done done
exit 0 exit 0
} }