Created
June 14, 2020 11:24
-
-
Save turicas/c982584ef28b4bf4cb8143046dcfb139 to your computer and use it in GitHub Desktop.
Process all nginx logs for a specific website through goaccess using docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Process all nginx logs for a specific website through goaccess using docker | |
# <https://goaccess.io/> | |
set -e | |
cat_site_logs() { | |
sitename="$1" | |
log_path="/var/log/nginx/" | |
find "$log_path" -type f -name "${sitename}-*" ! -name "*.gz" | \ | |
xargs cat | \ | |
gzip - | \ | |
zcat - $(find "$log_path" -type f -name "${sitename}*.gz") | |
} | |
create_log_analytics() { | |
docker run --rm -i -e LANG=$LANG allinurl/goaccess -a -o html --log-format COMBINED - | |
} | |
if [ -z "$2" ]; then | |
echo "ERROR - Usage: $0 <site-name> <output>" >&2 | |
echo " <output> can be an S3 URI (s3cmd will be used)" >&2 | |
exit 1 | |
fi | |
sitename="$1" | |
output="$2" | |
if [[ "$output" == "s3://"* ]]; then | |
# Create temp file and upload it to s3 | |
filename=$(mktemp) | |
cat_site_logs "$sitename" | create_log_analytics > "$filename" | |
s3cmd put "$filename" "$output" | |
rm "$filename" | |
else | |
cat_site_logs "$sitename" | create_log_analytics > "$output" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment