177def get_engines_stats(engine_name_list):
178 assert counter_storage is not None
179 assert histogram_storage is not None
180
181 list_time = []
182 max_time_total = max_result_count = None
183
184 for engine_name in engine_name_list:
185
186 sent_count = counter('engine', engine_name, 'search', 'count', 'sent')
187 if sent_count == 0:
188 continue
189
190 result_count = histogram('engine', engine_name, 'result', 'count').percentage(50)
191 result_count_sum = histogram('engine', engine_name, 'result', 'count').sum
192 successful_count = counter('engine', engine_name, 'search', 'count', 'successful')
193
194 time_total = histogram('engine', engine_name, 'time', 'total').percentage(50)
195 max_time_total = max(time_total or 0, max_time_total or 0)
196 max_result_count = max(result_count or 0, max_result_count or 0)
197
198 stats = {
199 'name': engine_name,
200 'total': None,
201 'total_p80': None,
202 'total_p95': None,
203 'http': None,
204 'http_p80': None,
205 'http_p95': None,
206 'processing': None,
207 'processing_p80': None,
208 'processing_p95': None,
209 'score': 0,
210 'score_per_result': 0,
211 'result_count': result_count,
212 }
213
214 if successful_count and result_count_sum:
215 score = counter('engine', engine_name, 'score')
216
217 stats['score'] = score
218 stats['score_per_result'] = score / float(result_count_sum)
219
220 time_http = histogram('engine', engine_name, 'time', 'http').percentage(50)
221 time_http_p80 = time_http_p95 = 0
222
223 if time_http is not None:
224
225 time_http_p80 = histogram('engine', engine_name, 'time', 'http').percentage(80)
226 time_http_p95 = histogram('engine', engine_name, 'time', 'http').percentage(95)
227
228 stats['http'] = round(time_http, 1)
229 stats['http_p80'] = round(time_http_p80, 1)
230 stats['http_p95'] = round(time_http_p95, 1)
231
232 if time_total is not None:
233
234 time_total_p80 = histogram('engine', engine_name, 'time', 'total').percentage(80)
235 time_total_p95 = histogram('engine', engine_name, 'time', 'total').percentage(95)
236
237 stats['total'] = round(time_total, 1)
238 stats['total_p80'] = round(time_total_p80, 1)
239 stats['total_p95'] = round(time_total_p95, 1)
240
241 stats['processing'] = round(time_total - (time_http or 0), 1)
242 stats['processing_p80'] = round(time_total_p80 - time_http_p80, 1)
243 stats['processing_p95'] = round(time_total_p95 - time_http_p95, 1)
244
245 list_time.append(stats)
246
247 return {
248 'time': list_time,
249 'max_time': math.ceil(max_time_total or 0),
250 'max_result_count': math.ceil(max_result_count or 0),
251 }
252
253