linux - 如何在 Linux 中为 Apache 获取 "requests per second"?

标签 linux apache monitoring

在 Windows for ASP 中,您可以获得它的 perfmon,但是...

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

最佳答案

这是我编写的一个简短的 bash 脚本,用于对请求率进行采样(基于在日志文件上使用 wc -ldicroce'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

关于linux - 如何在 Linux 中为 Apache 获取 "requests per second"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/345546/

相关文章:

java - NewRelic:如何忽略错误计数和警报的特定响应

linux - 无法连接到 PuTTY 和 WinSCP

c - 自动更改 RTS 以进行 RS-485 通信

mysql - 在端口 80 上运行 mamp 时建立数据库连接时出错

monitoring - 如何使用collectl获取磁盘使用信息?

java - 监控 Zip4J extractAll() 方法进度监视器

linux - 了解 ldd 输出 - 符号链接(symbolic link)

c - 在 Linux 虚拟机上编译 C 代码时出现两个错误

apache - .htaccess 文件重写超过应有的程度

Apache 和 IIS 共享相同的 SSL 证书