2015-01-31 2 views
-1

У меня есть сценарий оболочки, который вычисляет tps, среднее время отклика и качество отклика в процентах. Но я думаю, что формула качества ответа неверна, пожалуйста, предложите, как рассчитать качество отклика в процентиле 95%.Как рассчитать качество HTTP-запроса

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 
} 
+0

Это не правильный способ получил правильный путь ниже –

ответ

0

Я думаю, что это унаследованный код я использовал. Просто, чтобы быть стандартным, я сначала использовал fluentd для отправки журналов в logmatic и в logmatic было очень легко вычислить процентили и все.

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

-1

правильная функция

расчет() {

эхо "начиная вычисление данных в файлах:"

если [-f «/ TMP/журнал/tps_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); 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}' | хвост -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 < val' /tmp/log/tps_access/access$today_date.log | wc -l) quality_score = $ (echo" scale = 1; ($ quality_per_sec * 100)/$ total_request "| bc) value = $ (echo $ percent_500E '>' $ threshold | bc -l) if [$ value -eq 1] then echo" PERCENTAGE из 500 запросов на ошибки увеличивается, поэтому отправка почты в команду :» send_mail ошибки еще эхо„Записывая всю статистику в файл и ждать следующего запуск:“ send_mail всех выхода фи

фи }

Смежные вопросы