Dan*_*ira 21 linux apache monitoring
在Windows for ASP中,你可以得到它perfmon,但是......
如何在Linux中获取Apache的"每秒请求数"?
Ada*_*nco 25
这是一个简短的bash脚本,我用来对请求率进行采样(根据dicroce建议wc -l在日志文件中使用).
#!/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
Run Code Online (Sandbox Code Playgroud)
Gun*_*nny 16
实时,还是可以使用mod_status?
Wto*_*wer 11
总而言之,您可以使用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}'
Run Code Online (Sandbox Code Playgroud)
替换为您感兴趣的日期和小时,并使用日志文件的正确pathfilename.
它将打印出如下内容:
1913 12:47
226 12:48
554 12:49
918 12:50
Run Code Online (Sandbox Code Playgroud)
这里有一篇很好的文章,有更多选项可以使用awk,cut和uniq命令的组合来获得类型的快速统计数据.