首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Linux中获取Apache的“每秒请求数”?

如何在Linux中获取Apache的“每秒请求数”?
EN

Stack Overflow用户
提问于 2008-12-05 23:56:33
回答 9查看 57.1K关注 0票数 23

在Windows for ASP中,您可以获得它的性能,但...

如何在Linux中获取Apache的“每秒请求数”

EN

回答 9

Stack Overflow用户

回答已采纳

发布于 2008-12-05 23:58:53

实时的,或者你可以使用mod_status

很明显,有一个版本的top for apache...

票数 16
EN

Stack Overflow用户

发布于 2009-12-12 06:03:43

下面是我编写的一个简短的bash脚本,用于采样请求速率(基于对日志文件使用wc -ldicroce's suggestion )。

代码语言:javascript
复制
#!/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
票数 27
EN

Stack Overflow用户

发布于 2014-10-29 21:50:50

总而言之,您可以使用mod_statusapachetop

或者,您可以使用Adam Franco和Jon Daniel的优秀脚本来实时查看。

如果您想要查看分区日期和小时,可以发出以下小命令:

代码语言:javascript
复制
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}'

替换为您感兴趣的日期和小时,也替换为日志文件的正确路径文件名。

它将打印出如下内容:

代码语言:javascript
复制
1913 12:47
 226 12:48
 554 12:49
 918 12:50

有一篇很好的文章here,里面有更多关于使用awk、cut和uniq命令的组合来快速获取这类统计数据的选项。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/345546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档