mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 22:25:23 +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:
parent
375621b4ba
commit
37a7317c1d
1 changed files with 8 additions and 3 deletions
|
@ -95,10 +95,15 @@ http_codes[502]='Bad Gateway'
|
||||||
http_codes[503]='Service Unavailable'
|
http_codes[503]='Service Unavailable'
|
||||||
|
|
||||||
do_ () { # Fetch
|
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
|
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
|
echo "error$k.value ${line_counts[$k]:-0}"
|
||||||
value=`awk -v k=$k '{if ($9 == k) { i += 1 }} END { print i }' $log` # this is much better
|
|
||||||
echo "error$k.value ${value:-0}"
|
|
||||||
done
|
done
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue