在Windows for ASP中,您可以获得它的性能,但...
如何在Linux中获取Apache的“每秒请求数”?
发布于 2008-12-05 23:58:53
实时的,或者你可以使用mod_status
很明显,有一个版本的top for apache...
发布于 2009-12-12 06:03:43
下面是我编写的一个简短的bash脚本,用于采样请求速率(基于对日志文件使用wc -l
的dicroce's suggestion )。
#!/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
发布于 2014-10-29 21:50:50
总而言之,您可以使用mod_status和apachetop。
或者,您可以使用Adam Franco和Jon Daniel的优秀脚本来实时查看。
如果您想要查看分区日期和小时,可以发出以下小命令:
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}'
替换为您感兴趣的日期和小时,也替换为日志文件的正确路径文件名。
它将打印出如下内容:
1913 12:47
226 12:48
554 12:49
918 12:50
有一篇很好的文章here,里面有更多关于使用awk、cut和uniq命令的组合来快速获取这类统计数据的选项。
https://stackoverflow.com/questions/345546
复制相似问题