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