views:

2156

answers:

5

In Windows for ASP, you can get it perfmon, but...

How to get "requests per second" for Apache in Linux?

+2  A: 

I think mod_status can do it ...

http://httpd.apache.org/docs/2.0/mod/mod_status.html

You can also use zenoss to collect data from mod_status using the community apache plugin.

http://www.zenoss.com/

benlumley
+4  A: 

In realtime, or can you use mod_status?

And apparently, there is a version of top for apache...

Gunny
+1  A: 

You can use 'wc -l' on the access log to get the number of lines (which roughly corresponds to the number of requests...) Do that every minute and subtract the last value to get the delta...

dicroce
A: 

Here is a short bash script I made up to sample the request rate (based on dicroce's suggestion of using wc -l on the log file).

#!/bin/sh

##############################################################################
# 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)
##############################################################################

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
Adam Franco
A: 

Thanks a lot for sharing this Adam. Great script.