FEATURE #2389 @2h: group http request by url

This commit is contained in:
Michal Kváček
2017-03-28 00:27:31 +02:00
parent 848fa7b7cb
commit aa55ffe46a
6 changed files with 127 additions and 25 deletions
@@ -1,6 +1,7 @@
<?php namespace Modules\Profiler\Http\Controllers; <?php namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller; use App\Http\Controllers\Admin\Controller;
use Carbon\Carbon;
use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Input;
use Modules\Profiler\Entities\HttpLog; use Modules\Profiler\Entities\HttpLog;
@@ -9,21 +10,36 @@ class ProfilerController extends Controller
public function index() public function index()
{ {
$filters = []; $filters = [];
$httpLog = HttpLog::orderBy('created_at', 'DESC') $pastDays = Input::get('pastDays', session('profilerPastDays', 0));
->with('queries'); $httpLog = HttpLog::query();
if (is_numeric($pastDays) && $pastDays >= 0) {
$httpLog = $httpLog->where('created_at', '>=', Carbon::today()
->subDays($pastDays));
}
session(['profilerPastDays' => $pastDays]);
if (Input::get('method')) { if (Input::get('method')) {
$filters[] = 'method'; $filters[] = 'method';
$httpLog = $httpLog->where('method', Input::get('method')); $httpLog = $httpLog->where('method', Input::get('method'));
} }
$displayGrouped = false;
if (Input::get('url')) { if (Input::get('url')) {
$filters[] = 'url'; $httpLog = $httpLog->where('url', Input::get('url'))
$httpLog = $httpLog->where('url', Input::get('url')); ->with('queries');
} else {
$displayGrouped = true;
$httpLog = $httpLog->groupBy('url', 'method')
->select(\DB::raw('*'), \DB::raw('COUNT(url) as total'), \DB::raw('AVG(time) as time_avg'))
->orderBy('total', 'DESC');
} }
$httpLog = $httpLog->paginate(25); $httpLog = $httpLog->paginate(25);
return view('profiler::index', compact('httpLog')); $filter = Input::all();
return view('profiler::index', compact('httpLog', 'displayGrouped', 'filter', 'pastDays'));
} }
} }
+25 -9
View File
@@ -2,24 +2,40 @@
return [ return [
'name' => 'Profiler', 'name' => 'Profiler',
'index' => [ 'index' => [
'createdAt' => 'Datum', 'createdAt' => 'Datum',
'httpMethod' => 'HTTP metoda', 'httpMethod' => 'HTTP metoda',
'url' => 'URL', 'url' => 'URL',
'time' => 'Čas', 'time' => 'Čas',
'systemLoad' => 'Load serveru' 'timeAvg' => 'Průměrný čas',
'timeMin' => 'Minimální čas',
'timeMax' => 'Maximální čas',
'systemLoad' => 'Load serveru',
'calledTotal' => 'Volání',
'pastDays' => [
'today' => 'Dnes',
'overall' => 'Vše',
'days' => '1 den|:count dny|:count dní'
]
], ],
'settings' => [ 'settings' => [
'useProfilerInVisitorArea' => 'Zapnout měření ve veřejné části?', 'useProfilerInVisitorArea' => 'Zapnout měření ve veřejné části?',
'useProfilerInAdmin' => 'Zapnout měření v administraci?' 'useProfilerInAdmin' => 'Zapnout měření v administraci?'
], ],
'request' => [ 'request' => [
'info' => 'Detaily requestu', 'info' => 'Detaily requestu',
'sql' => 'SQL dotazy', 'sql' => 'SQL dotazy',
'detail' => 'Detail požadavku', 'detail' => 'Detail požadavku',
'sameRequests' => 'Ostatní volání' 'sameRequests' => 'Ostatní volání'
], ],
'graphs' => [ 'graphs' => [
'responseTime' => 'Doba odezvy' 'responseTime' => 'Doba odezvy'
] ],
'queries' => [
'sql' => 'SQL dotaz',
'time' => 'Čas dotazu'
],
'listDescription' => 'Seznam HTTP požadavků na tuto aplikaci.',
'groupedListDescription' => 'Seznam HTTP požadavků na tuto aplikaci.',
'requestDetail' => 'Detail HTTP požadavku'
]; ];
@@ -0,0 +1,27 @@
<table class="item-list content-overview full-width table striped">
<thead>
<tr>
<td>@lang('profiler::module.index.calledTotal')</td>
<td>@lang('profiler::module.index.httpMethod')</td>
<td>@lang('profiler::module.index.url')</td>
<td>@lang('profiler::module.index.timeAvg')</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach($requests as $request)
<tr>
<td>{{$request->total}}</td>
<td><a href="{{route('profiler.index', ['method' => $request->method])}}">{{$request->method}}</a></td>
<td><a href="{{route('profiler.index', ['url' => $request->url])}}">{{$request->url}}</a></td>
<td>{{number_format($request->time_avg, 2)}} ms</td>
<td>
<a href="{{route('request.detail', ['httpLog' => $request])}}" data-toggle="tooltip"
title="@lang('profiler::module.request.info')">
<i class="fa fa-info"></i>
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
@@ -2,14 +2,43 @@
@section('pageHeading', trans('profiler::module.name')) @section('pageHeading', trans('profiler::module.name'))
@section('headerButtons')
@if($displayGrouped == false)
<a class="btn btn-sm rounded btn-primary" href="{{route('profiler.index')}}"><i class="fa fa-list"></i></a>
@endif
<div class="pull-right">
@foreach(['0' => 'today', '7' => 'days', '30' => 'days', 'inf' => 'overall'] as $pastDay => $name)
@php $filter['pastDays'] = $pastDay; @endphp
<a class="btn btn-sm rounded @if($pastDays === (string)$pastDay) btn-primary @else btn-secondary @endif"
href="{{route('profiler.index', $filter)}}">{{trans_choice('profiler::module.index.pastDays.'.$name, $pastDay)}}</a>
@endforeach
</div>
@endsection
@if($displayGrouped == false)
@section('pageDescription', trans('profiler::module.listDescription'))
@else
@section('pageDescription', trans('profiler::module.groupedListDescription'))
@endif
@section('content') @section('content')
<div class="card"> <div class="card">
<div class="card-block"> <div class="card-block">
@include('profiler::_partials.requestList', ['requests' => $httpLog])
@if ($displayGrouped == true)
@include('profiler::_partials.groupedRequestList', ['requests' => $httpLog])
@else
@include('profiler::_partials.requestList', ['requests' => $httpLog])
@endif
</div> </div>
<div class="card-footer"> <div class="card-footer">
{!! $httpLog->render() !!} {!! $httpLog->render() !!}
</div> </div>
</div> </div>
@stop @endsection
@@ -22,7 +22,11 @@
<td> <td>
@php $sql = $query->query; @endphp @php $sql = $query->query; @endphp
@foreach($query->bindings as $value) @foreach($query->bindings as $value)
@php $sql = preg_replace('/\?/', $value, $sql, 1); @endphp @php
if (is_array($value) && isset($value['date']))
{$value = \Carbon\Carbon::parse($value['date'])->toDateTimeString();}
$sql = preg_replace('/\?/', $value, $sql, 1);
@endphp
@endforeach @endforeach
{{$sql}} {{$sql}}
@@ -1,6 +1,11 @@
@extends('admin.layoutWithNavigation') @extends('admin.layoutWithNavigation')
@section('pageHeading', trans('profiler::module.name')) @section('pageHeading', trans('profiler::module.requestDetail'))
@section('headerButtons')
<a class="btn btn-sm rounded btn-primary" href="{{route('profiler.index')}}"><i class="fa fa-list"></i></a>
@endsection
@section('content') @section('content')
@@ -17,20 +22,25 @@
<div class="row"> <div class="row">
<ul> <ul>
<li>@lang('profiler::module.index.httpMethod'): {{$httpLog->method}}</li> <li>@lang('profiler::module.index.httpMethod'): {{$httpLog->method}}</li>
<li>@lang('profiler::module.index.url'): <a href="{{route('profiler.index', ['url' => $httpLog->url])}}">{{$httpLog->url}}</a></li> <li>@lang('profiler::module.index.url'): <a
<li>@lang('profiler::module.index.time'): {{number_format($httpLog->time, 2)}}</li> href="{{route('profiler.index', ['url' => $httpLog->url])}}">{{$httpLog->url}}</a>
</li>
<li>@lang('profiler::module.index.time'): {{number_format($httpLog->time, 2)}} ms</li>
<li>@lang('profiler::module.index.systemLoad'): {{$httpLog->load_1}}, {{$httpLog->load_5}} <li>@lang('profiler::module.index.systemLoad'): {{$httpLog->load_1}}, {{$httpLog->load_5}}
, {{$httpLog->load_15}}</li> , {{$httpLog->load_15}}</li>
</ul> </ul>
</div> </div>
<div class="row text-center"> <div class="row text-center">
<div class="col-sm-3"><h3>{{count($sameRequests)}} &times;</h3> volano</div> <div class="col-sm-3"><h5>
<div class="col-sm-3"><h3>{{number_format($times['min'], 2)}} ms</h3> min</div> {{count($sameRequests)}} &times;</h5> @lang('profiler::module.index.calledTotal')</div>
<div class="col-sm-3"><h3>{{number_format($times['max'], 2)}} ms</h3> max</div> <div class="col-sm-3"><h5>{{number_format($times['min'], 2)}}
<div class="col-sm-3"><h3>{{number_format($times['avg'], 2)}} ms</h3> prumer</div> ms</h5> @lang('profiler::module.index.timeMin')</div>
<div class="col-sm-3"><h5>{{number_format($times['max'], 2)}}
ms</h5> @lang('profiler::module.index.timeMax')</div>
<div class="col-sm-3"><h5>{{number_format($times['avg'], 2)}}
ms</h5> @lang('profiler::module.index.timeAvg')</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>