1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

Read file one time and sort counts into array instead of reading log file for each status code again

This commit is contained in:
Daniel Schmitz 2015-02-05 13:44:53 +08:00
parent 375621b4ba
commit 37a7317c1d

View file

@ -95,10 +95,15 @@ http_codes[502]='Bad Gateway'
http_codes[503]='Service Unavailable'
do_ () { # Fetch
declare -A line_counts
values=`awk '{print $6}' $log | sort | uniq -c`
while read -r line; do
read -a tmp <<< "$line";
line_counts[${tmp[1]}]=${tmp[0]};
done <<< "$values"
for k in ${!http_codes[@]}; do
#value=`awk -v k=$k '{if ($9 == k) { print $9 }}' $log | wc -l` # this is very slow and ugly
value=`awk -v k=$k '{if ($9 == k) { i += 1 }} END { print i }' $log` # this is much better
echo "error$k.value ${value:-0}"
echo "error$k.value ${line_counts[$k]:-0}"
done
exit 0
}