From aa55ffe46aeed9dfa99d521b9da1a5072334063c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Kv=C3=A1=C4=8Dek?= Date: Tue, 28 Mar 2017 00:27:31 +0200 Subject: [PATCH] FEATURE #2389 @2h: group http request by url --- .../Http/Controllers/ProfilerController.php | 26 +++++++++++--- modules/Profiler/Resources/lang/cs/module.php | 34 ++++++++++++++----- .../_partials/groupedRequestList.blade.php | 27 +++++++++++++++ .../Profiler/Resources/views/index.blade.php | 33 ++++++++++++++++-- .../Resources/views/queries/index.blade.php | 6 +++- .../Resources/views/request/detail.blade.php | 26 +++++++++----- 6 files changed, 127 insertions(+), 25 deletions(-) create mode 100644 modules/Profiler/Resources/views/_partials/groupedRequestList.blade.php diff --git a/modules/Profiler/Http/Controllers/ProfilerController.php b/modules/Profiler/Http/Controllers/ProfilerController.php index 9aa23e83..dbf84d07 100644 --- a/modules/Profiler/Http/Controllers/ProfilerController.php +++ b/modules/Profiler/Http/Controllers/ProfilerController.php @@ -1,6 +1,7 @@ with('queries'); + $pastDays = Input::get('pastDays', session('profilerPastDays', 0)); + $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')) { $filters[] = 'method'; $httpLog = $httpLog->where('method', Input::get('method')); } + $displayGrouped = false; + 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); - return view('profiler::index', compact('httpLog')); + $filter = Input::all(); + return view('profiler::index', compact('httpLog', 'displayGrouped', 'filter', 'pastDays')); } } \ No newline at end of file diff --git a/modules/Profiler/Resources/lang/cs/module.php b/modules/Profiler/Resources/lang/cs/module.php index 4abae6eb..2fae13b0 100644 --- a/modules/Profiler/Resources/lang/cs/module.php +++ b/modules/Profiler/Resources/lang/cs/module.php @@ -2,24 +2,40 @@ return [ 'name' => 'Profiler', 'index' => [ - 'createdAt' => 'Datum', - 'httpMethod' => 'HTTP metoda', - 'url' => 'URL', - 'time' => 'Čas', - 'systemLoad' => 'Load serveru' + 'createdAt' => 'Datum', + 'httpMethod' => 'HTTP metoda', + 'url' => 'URL', + 'time' => 'Čas', + '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' => [ 'useProfilerInVisitorArea' => 'Zapnout měření ve veřejné části?', 'useProfilerInAdmin' => 'Zapnout měření v administraci?' ], 'request' => [ - 'info' => 'Detaily requestu', - 'sql' => 'SQL dotazy', - 'detail' => 'Detail požadavku', + 'info' => 'Detaily requestu', + 'sql' => 'SQL dotazy', + 'detail' => 'Detail požadavku', 'sameRequests' => 'Ostatní volání' ], 'graphs' => [ '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' ]; \ No newline at end of file diff --git a/modules/Profiler/Resources/views/_partials/groupedRequestList.blade.php b/modules/Profiler/Resources/views/_partials/groupedRequestList.blade.php new file mode 100644 index 00000000..782000f5 --- /dev/null +++ b/modules/Profiler/Resources/views/_partials/groupedRequestList.blade.php @@ -0,0 +1,27 @@ + + + + + + + + + + + + @foreach($requests as $request) + + + + + + + + @endforeach + +
@lang('profiler::module.index.calledTotal')@lang('profiler::module.index.httpMethod')@lang('profiler::module.index.url')@lang('profiler::module.index.timeAvg')
{{$request->total}}{{$request->method}}{{$request->url}}{{number_format($request->time_avg, 2)}} ms + + + +
\ No newline at end of file diff --git a/modules/Profiler/Resources/views/index.blade.php b/modules/Profiler/Resources/views/index.blade.php index fca67c83..f59f90a8 100644 --- a/modules/Profiler/Resources/views/index.blade.php +++ b/modules/Profiler/Resources/views/index.blade.php @@ -2,14 +2,43 @@ @section('pageHeading', trans('profiler::module.name')) +@section('headerButtons') + @if($displayGrouped == false) + + + + @endif + +
+ @foreach(['0' => 'today', '7' => 'days', '30' => 'days', 'inf' => 'overall'] as $pastDay => $name) + @php $filter['pastDays'] = $pastDay; @endphp + + {{trans_choice('profiler::module.index.pastDays.'.$name, $pastDay)}} + @endforeach +
+ +@endsection + +@if($displayGrouped == false) + @section('pageDescription', trans('profiler::module.listDescription')) +@else + @section('pageDescription', trans('profiler::module.groupedListDescription')) +@endif + @section('content')
- @include('profiler::_partials.requestList', ['requests' => $httpLog]) + + @if ($displayGrouped == true) + @include('profiler::_partials.groupedRequestList', ['requests' => $httpLog]) + @else + @include('profiler::_partials.requestList', ['requests' => $httpLog]) + @endif
-@stop \ No newline at end of file +@endsection \ No newline at end of file diff --git a/modules/Profiler/Resources/views/queries/index.blade.php b/modules/Profiler/Resources/views/queries/index.blade.php index 6cc05e5f..2da5e5eb 100644 --- a/modules/Profiler/Resources/views/queries/index.blade.php +++ b/modules/Profiler/Resources/views/queries/index.blade.php @@ -22,7 +22,11 @@ @php $sql = $query->query; @endphp @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 {{$sql}} diff --git a/modules/Profiler/Resources/views/request/detail.blade.php b/modules/Profiler/Resources/views/request/detail.blade.php index 8722edf3..17ff6ace 100644 --- a/modules/Profiler/Resources/views/request/detail.blade.php +++ b/modules/Profiler/Resources/views/request/detail.blade.php @@ -1,6 +1,11 @@ @extends('admin.layoutWithNavigation') -@section('pageHeading', trans('profiler::module.name')) +@section('pageHeading', trans('profiler::module.requestDetail')) + +@section('headerButtons') + +@endsection + @section('content') @@ -17,20 +22,25 @@
-

{{count($sameRequests)}} ×

volano
-

{{number_format($times['min'], 2)}} ms

min
-

{{number_format($times['max'], 2)}} ms

max
-

{{number_format($times['avg'], 2)}} ms

prumer
+
+ {{count($sameRequests)}} ×
@lang('profiler::module.index.calledTotal')
+
{{number_format($times['min'], 2)}} + ms
@lang('profiler::module.index.timeMin')
+
{{number_format($times['max'], 2)}} + ms
@lang('profiler::module.index.timeMax')
+
{{number_format($times['avg'], 2)}} + ms
@lang('profiler::module.index.timeAvg')
-