How to measure req/sec by analyzing apache logs

16,120

Solution 1

In real time you could use mod_status. You could also count the lines in your access.log over a given period and work out the rate from that. Something like this

#!/bin/bash
LOGFILE=/var/log/apache2/access.log
STATFILE=/var/tmp/apachestats
START=$(wc -l "$LOGFILE" | awk '{print $1}')
PERIOD=10
PRECISION=2
sleep "$PERIOD"
while true
do
    HITSPERSECOND=0
    HITS=$(wc -l "$LOGFILE" | awk '{print $1}')
    NEWHITS=$(( HITS - START ))
    if [[ "$NEWHITS" > 0 ]]
    then
        START=$HITS
        HITSPERSECOND=$(echo -e "scale=$PRECISION\n$NEWHITS / $PERIOD" | bc -l )
    fi
    echo "$(date) rate was $HITSPERSECOND" >>"$STATFILE"
    sleep "$PERIOD"
done

Solution 2

This great article helped me a lot...

http://www.inmotionhosting.com/support/website/server-usage/view-level-of-traffic-with-apache-access-log

I had created a set of prepered commands that I am using to analyze apache log:

request per hour
cat access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c

request per hour by date
grep "23/Jan" access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c

request per hour by IP
grep "XX.XX.XX.XX" access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c

requests per minute:
cat access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

requests per minute for date:
grep "02/Nov/2017" access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

requests per minute for url:
grep "[url]" access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

per IP per minute
grep "XX.XX.XX.XX" access.log | cut -d[ -f2 | cut -d] -f1 | awk -F: '{print $2":"$3}' | sort -nk1 -nk2 | uniq -c

hopes it will help anyone who's looking for it...

Solution 3

How about using a tool like awstat.

To do manually, you can count the log entries (requests) and then divide them by the number of seconds between the first and last request. So, you get the average req/sec.

Solution 4

If you want to run relatively short performance tests, you can keep your eye on reqs or bytes/sec in real-time with apachetop. It's like top command in Linux and Unix, but provides a view to your Apache. It works by tailing the access log file.

I don't know if it's accurate enough for your purposes, but it definitely gives you some nice ballpark figures.

Share:
16,120

Related videos on Youtube

freddiefujiwra
Author by

freddiefujiwra

Updated on September 17, 2022

Comments

  • freddiefujiwra
    freddiefujiwra almost 2 years

    I want to measure the justify stress-test result on production env.

    How to measure req/sec by analyzing apache logs?

    apache2.2

    LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %D" combined
    

    Can I do with %t and %D parameters?

  • Jeff Clayton
    Jeff Clayton almost 6 years
    My system required quoting the bracket delimiters to make these work ( '[' and ']' ) but works fine -- example: (request per hour) cat access.log | cut -d'[' -f2 | cut -d']' -f1 | awk -F: '{print $2":00"}' | sort -n | uniq -c
  • Daviz
    Daviz over 3 years
    @JeffClayton in my case i just had to add a space between the "d" and the "[": cut -d [ -f2 | cut -d] -f1
  • Jeff Clayton
    Jeff Clayton over 3 years
    @Daviz thank you, you never know what slight differences occur between systems. I am certain someone else will find your adjustment handy as well.
  • dannysauer
    dannysauer over 2 years
    Minor nit pick... This is "requests grouped by clock hour" and similar, not exactly "requests per hour". Requests/minute won't show 100 when 50 come in ten seconds before the minute change and 50 come in ten seconds after, it will show two separate minutes with 50 connections/minute each. That's a subtle but important distinction to be aware of.