Created
May 26, 2021 20:21
-
-
Save elijahchancey/eac75e5a2048a78fb93fa57b9ed9d838 to your computer and use it in GitHub Desktop.
Script to counts the number of requests, received bytes and sent bytes from an ELB log file.
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 | |
# This script parses a single ELB log file and counts the number of requests, received bytes and sent bytes. | |
# It expects this log format: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html | |
# 1. aws s3 sync s3://elb-log-bucket/environment-name/ . | |
# 2. cd into the directory that represents a day of logs | |
# 3. gunzip *.log | |
# 4. cat *.log > combined.log | |
# 5. ./elb-logs-sum.sh | |
log_file='combined.log' | |
number_of_requests=0 | |
total_received_bytes=0 | |
total_sent_bytes=0 | |
IFS=$'\n' | |
for line in `cat $log_file` ; do | |
#echo $line | |
received_bytes=$(echo $line | awk '{print $11}') | |
sent_bytes=$(echo $line | awk '{print $12}') | |
#echo " $received_bytes" | |
#echo " $sent_bytes" | |
#echo "" | |
number_of_requests=$((number_of_requests+1)) | |
total_received_bytes=$(($total_received_bytes+$received_bytes)) | |
total_sent_bytes=$(($total_sent_bytes+$sent_bytes)) | |
done | |
echo "number_of_requests: $number_of_requests" | |
echo "total_received_bytes: $total_received_bytes" | |
echo "total_sent_bytes: $total_sent_bytes" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment