【问题标题】:how to calculate quality of http request served如何计算服务的 http 请求的质量
【发布时间】:2015-03-30 18:03:37
【问题描述】:

我有一个 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
}

【问题讨论】:

  • 这不是正确的方法得到下面的正确方法

标签: linux apache shell httprequest


【解决方案1】:

正确的函数

计算(){

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

如果 [ -f "/tmp/log/tps_access/access$today_date.log" ] 然后 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) percent_500E=$( printf "%.2f" $(echo "scale=5; $total_500E_request/$total_request * 100" | bc) ) 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 ); 打印四舍五入 }') 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)] ); 打印四舍五入 } ' ) 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) quality_per_sec=$( awk -F"\"" -v val=$second '$NF '$threshold | bc -l ) 如果 [ $value -eq 1 ] 然后 echo "500 个错误请求的百分比增加,因此向团队发送邮件:" 发送邮件错误 别的 echo "将所有统计信息写入文件并等待下一次运行:" 全部发送邮件 出口 菲

fi }

【讨论】:

    【解决方案2】:

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

    https://app.logmatic.io/ http://www.fluentd.org/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      • 2020-09-30
      • 2016-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多