PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Monitor Web Traffic From Linux Bash

Go down

Monitor Web Traffic From Linux Bash Empty Monitor Web Traffic From Linux Bash

Post by jamied_uk 1st October 2016, 13:28



Use freq of time for example 60 seconds!

I came across this on google search and wanted to try it out
Code Update Link For Example

app.box.com/s/y3agimth51ceh8b7n4e8tw8rps29qxy9

Code:
#!/bin/sh
#
# ./run.sh -f 60 -l /var/log/apache2/access.log
#
# ./run.sh -f 60 -l 1.txt
#
# /var/log/apache2/access.log
#
##############################################################################
# This script will monitor the number of lines in a log file to determine the
# number of requests per second.
#
# Example usage:
# reqs-per-sec -f 15 -i /var/www/http/access.log
#
# Author: Adam Franco
# Date: 2009-12-11
# License: http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
##############################################################################
#
# ./run.sh -f 60
#l='/var/log/apache2/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" |bc -l)
 echo $rate
 lastCount=$newCount
 sleep $frequency
done


From stackoverflow.com/questions/345546/how-to-get-requests-per-second-for-apache-in-linux


Last edited by jamied_uk on 1st October 2016, 14:25; edited 1 time in total
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Monitor Web Traffic From Linux Bash Empty Re: Monitor Web Traffic From Linux Bash

Post by jamied_uk 1st October 2016, 13:45

Also I Found This

You can use the formatting switches as follows:




You can mix and match the switches as required.
If you want to add a new line as part of the format string use the newline character as follows:

Code:
time -f "Elapsed Time = %E, Inputs %I, Outputs %O" <command>


You can mix and match the switches as required.
If you want to add a new line as part of the format string use the newline character as follows:

Code:
time -f "Elapsed Time = %E \n Inputs %I \n Outputs %O" <command>





linux.about.com/od/commands/fl/Run-A-Command-And-Return-Time-Statistics-Using-The-time-Command.htm
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Monitor Web Traffic From Linux Bash Empty Re: Monitor Web Traffic From Linux Bash

Post by jamied_uk 1st October 2016, 14:05

Even More

google.co.uk/#safe=off&q=linux+time+command



google.co.uk/#safe=off&q=using+bash+script++to+find+decent+rate+from+travel+time
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Monitor Web Traffic From Linux Bash Empty Re: Monitor Web Traffic From Linux Bash

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum