How to get “requests per second” for Apache in Linux?

前端 未结 9 680
情书的邮戳
情书的邮戳 2021-01-30 17:53

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

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

相关标签:
9条回答
  • 2021-01-30 18:35

    In realtime, or can you use mod_status?

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

    0 讨论(0)
  • 2021-01-30 18:41

    I wrote a set of Perl scripts that show the average requests-per-second for the past 1, 5 and 15 minutes (like top). It's at https://gist.github.com/1040144 .

    0 讨论(0)
  • 2021-01-30 18:44

    To sum up, you can use mod_status and apachetop.

    Alternatively, you can use Adam Franco's and Jon Daniel's nice scripts to have a live look.

    If you would like to have a look at a partiular date and hour, you can issue this little command:

    grep "29/Oct/2014:12" /var/log/apache2/example.com.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c | awk '{ if ($1 > 10) print $0}'
    

    Replace with the date and hour you are interested and also with the proper pathfilename of the log file.

    It will print out something like:

    1913 12:47
     226 12:48
     554 12:49
     918 12:50
    

    There is a nice article here with more options on using a combination of awk, cut and uniq commands to get quick stats of the kind.

    0 讨论(0)
  • 2021-01-30 18:50

    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
    
    0 讨论(0)
  • 2021-01-30 18:50

    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/

    0 讨论(0)
  • 2021-01-30 18:53

    Script shows inconsistent numbers. -f parameter affects output a lot! and first reading is not accurate either.

    I ended up using:

    while true; do tail -n0 -f access.log>/tmp/tmp.log & sleep 2; kill $! ; wc -l /tmp/tmp.log | cut -c-2; done 2>/dev/null
    

    Found here.

    0 讨论(0)
提交回复
热议问题