Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何计算所服务http请求的质量_Linux_Apache_Shell_Httprequest - Fatal编程技术网

Linux 如何计算所服务http请求的质量

Linux 如何计算所服务http请求的质量,linux,apache,shell,httprequest,Linux,Apache,Shell,Httprequest,我有一个shell脚本,它以百分比计算tps、平均响应时间和响应时间质量。但我认为质量响应公式不正确,请建议如何以95%的百分比计算响应时间的质量 calculation () { echo "starting calculation of the data in the files:" if [ -f "/tmp/log/tps_access/access$today_date.log" ] then total_request=$( cat /tmp/log/tps_access/

我有一个shell脚本,它以百分比计算tps、平均响应时间和响应时间质量。但我认为质量响应公式不正确,请建议如何以95%的百分比计算响应时间的质量

calculation () {
echo "starting calculation of the data in the files:" 
if [ -f "/tmp/log/tps_access/access$today_date.log" ]
then
    total_request=$( cat /tmp/log/tps_access/access$today_date.log | wc -l )
    total_500E_request=$( cat /tmp/log/tps_access/access$today_date.log | awk -F"\"" '{ print $3}' | awk -F" " '{ print $1}' | grep "^5[0-9][0-9]$" | wc -l)
    average_response_time=$( cat /tmp/log/tps_access/access$today_date.log | awk -F"\"" '{ print $9}' | awk '{sum+=$1; ++n} END { rounded = sprintf("%.2f", sum/n ); print rounded }')
    percentile=$( cut /tmp/log/tps_access/access$today_date.log -d '"' -f9 |sort -n| awk 'BEGIN{c=0} {total[c]=$1; c++;} END{ rounded = sprintf("%.2f", total[int((NR*0.95)-1)] ); print rounded } ' )
    head_time=$( head /tmp/log/tps_access/access$today_date.log | awk -F" " '{ print $4 }' | awk -F"[" '{ print $2 }' | awk -F"/" '{ print $1"-"$2"-"$3}' | awk -F":" '{ print $1" "$2":"$3":"$4}' | head -1 )
    tail_time=$( tail /tmp/log/tps_access/access$today_date.log | awk -F" " '{ print $4 }' | awk -F"[" '{ print $2 }' | awk -F"/" '{ print $1"-"$2"-"$3}' | awk -F":" '{ print $1" "$2":"$3":"$4}' | tail -1 )
    sec_old=$(date -d "$head_time" +%s)
    sec_new=$(date -d "$tail_time" +%s)
    DIFF=$(( (sec_new - sec_old) ))
    tps=$(echo "scale=2; $total_request/$DIFF * 1" | bc )
    request_servered_in_defined_sec=$( echo "scale=2; $total_request/$DIFF * $second" | bc )
    sum=$(cat /tmp/log/tps_access/access$today_date.log | awk -F"\"" '{ print $9}' | awk '{sum+=$1; ++n} END { print sum }')
    quality_per_sec=$( echo "scale=5; $sum/$total_request * $second" | bc )
    quality_score=$( echo "scale=5; $quality_per_sec/$sum * 100" | bc )
    if [ $total_500E_request -gt $threshold   ]
    then
            echo "Count of 500 error request increases so sending mail to the team:" 
            send_mail error
    else
            echo "Writing all the stats in a file and wait for the next run:" 
            send_mail all
            exit
    fi

fi
}
正确功能

算计{

echo开始计算文件中的数据:

if[-f/tmp/log/tps\u access/access$today\u date.log] 然后 请求总数=$cat/tmp/log/tps\u访问/访问$today\u date.log | wc-l 请求总数=$cat tmp/log/tps_访问/访问$today_date.log | awk-F\{print$3}'| awk-F{print$1}'| grep^5[0-9][0-9]$| wc-l 百分比_500E=$printf%.2f$echo scale=5;$total_500E_request/$total_request*100 | bc 平均响应时间=$cat/tmp/log/tps\u访问/访问$today\u date.log | awk-F\{print$9}'| awk'{sum+=1;++n}END{rounded=sprintf%.2f,sum/n;print rounded} 百分位数=$TUT/TMP/Log/TPSYAccess/Access $TayayAddia.log′-''-f9排序-n'AWK ''开始{C=0 }{{总数〕[C]=1;C++;} {{rnn==SaveTf%.2f,全部[tnnr*0.95-1;打印圆} ] head_time=$head/tmp/log/tps_access/access$today_date.log | awk-F{print$4}| awk-F[{print$2}| awk-F/{print$1-$2-$3}| awk-F:{print$1$2:$3:$4}| head 1-1 tail_time=$tail/tmp/log/tps_access/access$today_date.log | awk-F{print$4}| awk-F[{print$2}| awk-F/{print$1-$2-$3}| awk-F:{print$1$2:$3:$4}| tail-1 秒旧=$date-d$head\u时间+%s sec_new=$date-d$tail_time+%s 差异=$sec_新-sec_旧 tps=$echo scale=2;$total_request/$DIFF*1|bc 已定义的请求中的已服务请求秒=$echo scale=2;$total请求/$DIFF*$second | bc 质量每秒=$awk-F \-v val=$second'$NF'$threshold | bc-l 如果[$值-等式1] 然后 500个错误请求的回显百分比增加,因此向团队发送邮件: 发送邮件错误 其他的 回显将所有统计信息写入文件并等待下一次运行: 发送所有邮件 出口 fi

fi
}

我认为这是我使用的一个遗留代码,作为标准,我首先使用fluentd将日志发送到logmatic,在logmatic中,计算百分位数和所有内容都非常简单


这不是正确的方法。下面是正确的方法