Nginx error: log files may be empty

This commit is contained in:
Filippo Tessarotto 2018-10-17 08:44:02 +02:00 committed by GitHub
parent a2ebe02412
commit caf3b6c90f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -122,9 +122,13 @@ http_codes[503]='Service Unavailable'
do_fetch () {
local count status_code
declare -A line_counts
while read -r count status_code; do
values="$(awk '{print $9}' "$log" | sort | uniq -c)"
# Log files may be empty due to logrotation
if [ -n "$values" ]; then
while read -r count status_code; do
line_counts[$status_code]=$count
done <<< "$(awk '{print $9}' "$log" | sort | uniq -c)"
done <<< "$values"
fi
for status_code in "${!http_codes[@]}"; do
echo "error${status_code}.value ${line_counts[$status_code]:-0}"