Method: WASP::WeaponAB#points

Defined in:
lib/wasp/stingab.rb

#points(report) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/wasp/stingab.rb', line 126

def points (report)
  return nil if report.nil?
  
  #puts report
  
  error_regex = []
  
  response = {}
  
  error_regex.push(/Too many open files/)
  error_regex.push(/Cannot use concurrency level greater than total number of requests/)
  error_regex.push(/Invalid Concurrency/)
  error_regex.push(/The timeout specified has expired/)
  
  error_regex.each do |reg|
    return nil if not report.match(reg).nil?
  end
    
  regex = /Concurrency Level:.*[\d]*/
  report.match(regex) do |data|
    response[:concurrency] = data.to_s.gsub!(/\D/, '')
    #puts response[:concurrency]
  end
  
  regex = /Time taken for tests:.*[\d]*.[\d]*.*seconds/
  report.match(regex) do |data|
    response[:time] = data.to_s.gsub!(/[a-zA-Z:\s]/, '')
    #puts response[:time]
  end
  
  regex = /Complete requests:.*[\d]*/
  report.match(regex) do |data|
    response[:complete] = data.to_s.gsub!(/\D/, '')
    #puts response[:complete]
  end
  
  regex = /Failed requests:.*[\d]*/
  report.match(regex) do |data|
    response[:failed] = data.to_s.gsub!(/\D/, '')
    #puts response[:failed]
  end
  
  regex = /Write errors:.*[\d]*/
  report.match(regex) do |data|
    response[:write_errors] = data.to_s.gsub!(/\D/, '')
    #puts response[:write_errors]
  end
  
  regex = /Non-2xx responses:.*/
  response[:non2xx] = 0
  report.match(regex) do |data|
    values = data.to_s.split(" ")
    response[:non2xx] = values[2] unless values.nil?
    #puts response[:transferred]
  end
  
  response[:ok] = response[:complete].to_i - response[:non2xx].to_i
  response[:ok] = 0 if response[:ok] < 0
  
  regex = /Total transferred:.*[\d]*.*bytes/
  report.match(regex) do |data|
    response[:transferred] = data.to_s.gsub!(/\D/, '')
    #puts response[:transferred]
  end
  
  regex = /HTML transferred:.*[\d]*.*bytes/
  report.match(regex) do |data|
    response[:html_transferred] = data.to_s.gsub!(/\D/, '')
    #puts response[:html_transferred]
  end
  
  regex = /Requests per second:.*[\d]*.[\d]*.*\[#\/sec\].*\(mean\)/
  report.match(regex) do |data|
    #response[:requests_per_second] = data.to_s.gsub!(/[a-zA-Z:#\s\[\/\]\(\)]/, '')
    response[:requests_per_second] = response[:ok].to_f / response[:time].to_f
    #puts response[:requests_per_second]
  end
  
  regex = /Time per request:.*[\d]*.[\d]*.*\[ms\].*\(mean\)/
  report.match(regex) do |data|
    response[:time_per_request] = data.to_s.gsub!(/[a-zA-Z:\s\[\]\(\)]/, '')
    #puts response[:time_per_request]
  end      
  
  regex = /Total:.*/
  report.match(regex) do |data|
    values = data.to_s.split(" ")
    response[:mean_per_request] = values[2] unless values.nil?
    response[:standard_deviation] = values[3] unless values.nil?
    #puts response[:mean_per_request]
    #puts response[:standard_deviation]
  end
  
  regex = /.*80\%.*[\d]*/
  report.match(regex) do |data|
    response[:eighty_percent] = data.to_s.gsub!(/\s*80\%\s*/, '')
    #puts response[:eighty_percent]
  end
  
  regex = /.*100\%.*[\d]*/
  report.match(regex) do |data|
    response[:hundred_percent] = data.to_s.gsub!(/\s*100\%\s*/, '')
    #puts response[:hundred_percent]
  end
  
  response
end