From 0e864944d76b19278d82a602aca850c0d91ac51a Mon Sep 17 00:00:00 2001 From: Lars Kruse Date: Sat, 20 Jan 2018 01:25:14 +0100 Subject: [PATCH] nginx_error: improve readability of array accesses --- plugins/nginx/nginx_error | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/plugins/nginx/nginx_error b/plugins/nginx/nginx_error index 1d6244cd..667aef2c 100755 --- a/plugins/nginx/nginx_error +++ b/plugins/nginx/nginx_error @@ -103,34 +103,30 @@ http_codes[503]='Service Unavailable' # parse error counts from log file do_ () { - local k values + local count status_code declare -A line_counts - values=$(awk '{print $9}' "$log" | sort | uniq -c) - if [ -n "$values" ]; then - while read -r line; do - read -r -a tmp <<< "$line" - line_counts[${tmp[1]}]=${tmp[0]} - done <<< "$values" - fi + while read -r count status_code; do + line_counts[$status_code]=$count + done <<< "$(awk '{print $9}' "$log" | sort | uniq -c)" - for k in "${!http_codes[@]}"; do - echo "error$k.value ${line_counts[$k]:-0}" + for status_code in "${!http_codes[@]}"; do + echo "error${status_code}.value ${line_counts[$status_code]:-0}" done exit 0 } do_config () { - local k + local status_code echo "graph_title $(basename "$log") - Nginx errors per minute" echo "graph_vlabel pages with http error codes / \${graph_period}" echo "graph_category webserver" 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]}" + for status_code in "${!http_codes[@]}"; do + echo "error${status_code}.type DERIVE" + echo "error${status_code}.min 0" + echo "error${status_code}.label $status_code ${http_codes[$status_code]}" done exit 0 }