Created
July 13, 2013 02:56
-
-
Save i97506051502/5989211 to your computer and use it in GitHub Desktop.
ab コマンドの結果をログり, 平均レスポンスタイムなどを返却します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! ruby -Ku | |
# -*- mode:ruby; coding:utf-8 -*- | |
$KCODE='u' | |
require 'jcode' | |
# ToDo | |
# ---------------------------------------------------------------------- | |
# ファイルを変数に。複数に。 | |
# 入力値のバリデーション | |
# ファイルから 1 行ずつ読み込む | |
#open("./ad-dsp_130.1.36.1_response_time-20130629.log") { |file| | |
open("./ad-dsp_130.1.27.1_response_time-20130713.log") { |file| | |
# 計算用配列の作成 | |
#res_times = Array.new(10,0) | |
res_times = Array.new | |
print 'res_times の中身 ' | |
p res_times | |
file.each { |line| | |
# 読み込んだ行を空白を区切り文字とし配列に格納 | |
elements = line.split(nil) | |
print 'elements[9] の中身 ' | |
puts elements[9] | |
# 読み込んだ行のレスポンスタイムを取得 | |
res_time = elements[9].to_f | |
print 'res_time の中身 ' | |
p res_time | |
# 読み込んだ行のレスポンスタイムを計算用配列に格納 | |
res_times.push(res_time) | |
print 'res_times の中身 ' | |
p res_times | |
#res_time = elements[9] | |
#sum_res_time = res_time + elements[9] | |
#puts sum_res_time | |
#puts line | |
} | |
sum_time = res_times.inject(:+) | |
print 'sum_time の中身 ' | |
puts sum_time | |
ele_num = res_times.length.to_i | |
print 'ele_num の中身 ' | |
puts ele_num | |
print 'sum_time の平均値 ' | |
avg_time = sum_time / ele_num | |
puts avg_time | |
print 'sum_time の平均値 ' | |
puts sprintf("%.2f", avg_time) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment