FEATURE #2389 @2h: add request detail into profiler

This commit is contained in:
Michal Kváček
2017-03-24 01:28:21 +01:00
parent 52e02d67c6
commit 05c9e56973
11 changed files with 273 additions and 90 deletions
@@ -1,15 +1,28 @@
<?php namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller;
use Illuminate\Support\Facades\Input;
use Modules\Profiler\Entities\HttpLog;
class ProfilerController extends Controller
{
public function index()
{
$filters = [];
$httpLog = HttpLog::orderBy('created_at', 'DESC')
->with('queries')
->paginate(25);
->with('queries');
if (Input::get('method')) {
$filters[] = 'method';
$httpLog = $httpLog->where('method', Input::get('method'));
}
if (Input::get('url')) {
$filters[] = 'url';
$httpLog = $httpLog->where('url', Input::get('url'));
}
$httpLog = $httpLog->paginate(25);
return view('profiler::index', compact('httpLog'));
}
@@ -0,0 +1,23 @@
<?php
namespace Modules\Profiler\Http\Controllers;
use App\Http\Controllers\Admin\Controller;
use Modules\Profiler\Entities\HttpLog;
class RequestController extends Controller
{
public function detail(HttpLog $httpLog)
{
$sameRequests = HttpLog::where('url', $httpLog->url)
->where('method', $httpLog->method)
->get();
$times = [
'avg' => $sameRequests->avg('time'),
'min' => $sameRequests->min('time'),
'max' => $sameRequests->max('time')
];
return view('profiler::request.detail', compact('httpLog', 'sameRequests', 'times'));
}
}
+11 -5
View File
@@ -1,14 +1,20 @@
<?php
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'namespace' => 'Modules\Profiler\Http\Controllers'
'prefix' => LaravelLocalization::setLocale(),
'namespace' => 'Modules\Profiler\Http\Controllers'
], function () {
Route::group([
'middleware' => ['admin'],
'prefix' => 'profiler'
'prefix' => 'admin/profiler'
], function () {
Route::get('/', 'ProfilerController@index')->name('profiler.index');
Route::get('{httpLog}/queries', 'QueryController@index')->name('queries.index');
Route::get('/', 'ProfilerController@index')
->name('profiler.index');
Route::get('{httpLog}', 'RequestController@detail')
->name('request.detail');
Route::get('{httpLog}/queries', 'QueryController@index')
->name('queries.index');
});
});
@@ -11,5 +11,15 @@ return [
'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',
'sameRequests' => 'Ostatní volání'
],
'graphs' => [
'responseTime' => 'Doba odezvy'
]
];
@@ -0,0 +1,55 @@
<table class="item-list content-overview full-width table striped">
<thead>
<tr>
<td>@lang('profiler::module.index.createdAt')</td>
<td>@lang('profiler::module.index.httpMethod')</td>
<td>@lang('profiler::module.index.url')</td>
<td>@lang('profiler::module.index.time')</td>
<td>@lang('profiler::module.index.systemLoad')</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach($requests as $request)
<tr>
<td>{{$request->created_at->format('d.m.Y G:i')}}</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, 3)}} ms</td>
<td>{{$request->load_1}}, {{$request->load_5}}, {{$request->load_15}}</td>
<td>
<div class="item-actions-dropdown">
<a class="item-actions-toggle-btn">
<span class="inactive">
<i class="fa fa-cog"></i>
</span>
<span class="active">
<i class="fa fa-chevron-circle-right"></i>
</span>
</a>
<div class="item-actions-block">
<ul class="item-actions-list">
<li>
<a href="{{route('request.detail', ['httpLog' => $request])}}" data-toggle="tooltip"
title="@lang('profiler::module.request.info')">
<i class="fa fa-info"></i>
</a>
</li>
<li>
<a href="{{route('queries.index', ['httpLog' => $request])}}" data-toggle="tooltip"
title="@lang('profiler::module.request.sql')">
<i class="fa fa-database"></i></a>
</li>
</ul>
</div>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
@@ -4,34 +4,12 @@
@section('content')
<table class="table stripped">
<thead>
<tr>
<td>@lang('profiler::module.index.createdAt')</td>
<td>@lang('profiler::module.index.httpMethod')</td>
<td>@lang('profiler::module.index.url')</td>
<td>@lang('profiler::module.index.time')</td>
<td>@lang('profiler::module.index.systemLoad')</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach($httpLog as $request)
<tr>
<td>{{$request->created_at->format('d.m.Y G:i')}}</td>
<td>{{$request->method}}</td>
<td>{{$request->url}}</td>
<td>{{number_format($request->time, 3)}} ms</td>
<td>{{$request->load_1}}, {{$request->load_5}}, {{$request->load_15}}</td>
<td>
<a href="{{route('queries.index', ['httpLog' => $request])}}">SQL</a>
</td>
</tr>
@endforeach
</tbody>
</table>
{!! $httpLog->render() !!}
<div class="card">
<div class="card-block">
@include('profiler::_partials.requestList', ['requests' => $httpLog])
</div>
<div class="card-footer">
{!! $httpLog->render() !!}
</div>
</div>
@stop
@@ -4,30 +4,34 @@
@section('content')
<table class="table stripped">
<thead>
<tr>
<td>@lang('profiler::module.queries.createdAt')</td>
<td>@lang('profiler::module.queries.sql')</td>
<td>@lang('profiler::module.queries.binding')</td>
<td>@lang('profiler::module.queries.time')</td>
<td></td>
</tr>
</thead>
<tbody>
<div class="card">
<div class="card-block">
<table class="table stripped">
<thead>
<tr>
<td>@lang('profiler::module.queries.sql')</td>
<td>@lang('profiler::module.queries.time')</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach($queries as $query)
<tr>
<td>{{$query->created_at->format('d.m.Y G:i')}}</td>
<td>{{$query->query}}</td>
<td>
@foreach($queries as $query)
<tr>
<td>
@php $sql = $query->query; @endphp
@foreach($query->bindings as $value)
@php $sql = preg_replace('/\?/', $value, $sql, 1); @endphp
@endforeach
{{var_export($query->bindings)}}
</td>
<td>{{number_format($query->time, 3)}} ms</td>
</tr>
@endforeach
</tbody>
</table>
{{$sql}}
</td>
<td>{{number_format($query->time, 3)}} ms</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
@@ -0,0 +1,92 @@
@extends('admin.layoutWithNavigation')
@section('pageHeading', trans('profiler::module.name'))
@section('content')
<div class="row">
<div class="col-md-5">
<div class="card">
<div class="card-header">
<div class="header-block">
<p class="title">@lang('profiler::module.request.detail')</p>
</div>
</div>
<div class="card-block">
<div class="row">
<ul>
<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.time'): {{number_format($httpLog->time, 2)}}</li>
<li>@lang('profiler::module.index.systemLoad'): {{$httpLog->load_1}}, {{$httpLog->load_5}}
, {{$httpLog->load_15}}</li>
</ul>
</div>
<div class="row text-center">
<div class="col-sm-3"><h3>{{count($sameRequests)}} &times;</h3> volano</div>
<div class="col-sm-3"><h3>{{number_format($times['min'], 2)}} ms</h3> min</div>
<div class="col-sm-3"><h3>{{number_format($times['max'], 2)}} ms</h3> max</div>
<div class="col-sm-3"><h3>{{number_format($times['avg'], 2)}} ms</h3> prumer</div>
</div>
</div>
</div>
</div>
<div class="col-md-7">
<div class="card">
<div class="card-header">
<div class="header-block">
<p class="title">@lang('profiler::module.graphs.responseTime')</p>
</div>
</div>
<div class="card-block">
<canvas id="responseTimeHistory" height="100"></canvas>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header">
<div class="header-block">
<p class="title">@lang('profiler::module.request.sameRequests')</p>
</div>
</div>
<div class="card-block">
@include('profiler::_partials.requestList', ['requests' => $sameRequests])
</div>
</div>
@endsection
@section('javascripts')
<script>
var ctx = $ ("#responseTimeHistory");
var myChart = new Chart (ctx, {
type: 'bubble',
data: {
datasets: [
{
label: '@lang('profiler::module.graphs.responseTime')',
data: [
@foreach($sameRequests as $i => $request)
{
x: '{{$i}}',
y: '{{number_format($request->time, 2)}}',
r: 5
},
@endforeach
],
backgroundColor: "#413e39",
hoverBackgroundColor: "#515151",
}]
}
});
</script>
@endsection