Created
October 9, 2012 10:07
-
-
Save sandfox/3857762 to your computer and use it in GitHub Desktop.
log file lines inserted per $period counter
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/sh | |
############################################################################## | |
# This script will monitor the number of lines in a log file to determine the | |
# number of requests per second. | |
# | |
# Example usage: | |
# ./logs_rps.sh -f 15 -i /var/www/http/access.log | |
############################################################################## | |
usage="Usage: `basename $0` -f <frequency in seconds, min 1, default 60> -l <log file>" | |
# Set up options | |
while getopts ":l:f:" options; do | |
case $options in | |
l ) logFile=$OPTARG;; | |
f ) frequency=$OPTARG;; | |
\? ) echo -e $usage | |
exit 1;; | |
* ) echo -e $usage | |
exit 1;; | |
esac | |
done | |
# Test for logFile | |
if [ ! -n "$logFile" ] | |
then | |
echo -e $usage | |
exit 1 | |
fi | |
# Test for frequency | |
if [ ! -n "$frequency" ] | |
then | |
frequency=60 | |
fi | |
# Test that frequency is an integer | |
if [ $frequency -eq $frequency 2> /dev/null ] | |
then | |
: | |
else | |
echo -e $usage | |
exit 3 | |
fi | |
# Test that frequency is an integer | |
if [ $frequency -lt 1 ] | |
then | |
echo -e $usage | |
exit 3 | |
fi | |
if [ ! -e "$logFile" ] | |
then | |
echo "$logFile does not exist." | |
echo | |
echo -e $usage | |
exit 2 | |
fi | |
lastCount=`wc -l $logFile | sed 's/\([0-9]*\).*/\1/'` | |
while true | |
do | |
newCount=`wc -l $logFile | sed 's/\([0-9]*\).*/\1/'` | |
diff=$(( newCount - lastCount )) | |
rate=$(echo "$(($diff / $frequency))") | |
echo $rate | |
lastCount=$newCount | |
sleep $frequency | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment