-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from NottingHack/instrumentaion-status
Instrumentation: add status and events page
- Loading branch information
Showing
10 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/HMS/Repositories/Instrumentation/Doctrine/DoctrineEventRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace HMS\Repositories\Instrumentation\Doctrine; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use HMS\Entities\Instrumentation\Event; | ||
use HMS\Entities\Instrumentation\Service; | ||
use HMS\Repositories\Instrumentation\EventRepository; | ||
use LaravelDoctrine\ORM\Pagination\PaginatesFromRequest; | ||
|
||
class DoctrineEventRepository extends EntityRepository implements EventRepository | ||
{ | ||
use PaginatesFromRequest; | ||
|
||
/** | ||
* @param Service $service | ||
* @param int $perPage | ||
* @param string $pageName | ||
* | ||
* @return \Illuminate\Pagination\LengthAwarePaginator | ||
*/ | ||
public function paginateByService(Service $service, $perPage = 50, $pageName = 'page') | ||
{ | ||
$q = parent::createQueryBuilder('event') | ||
->where('event.value = :service_name') | ||
->orderBy('event.time', 'DESC'); | ||
|
||
$q = $q->setParameter('service_name', $service->getName())->getQuery(); | ||
|
||
return $this->paginate($q, $perPage, $pageName); | ||
} | ||
|
||
/** | ||
* save Event to the DB. | ||
* @param Event $event | ||
*/ | ||
public function save(Event $event) | ||
{ | ||
$this->_em->persist($event); | ||
$this->_em->flush(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/HMS/Repositories/Instrumentation/Doctrine/DoctrineServiceRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace HMS\Repositories\Instrumentation\Doctrine; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use HMS\Entities\Instrumentation\Service; | ||
use HMS\Repositories\Instrumentation\ServiceRepository; | ||
|
||
class DoctrineServiceRepository extends EntityRepository implements ServiceRepository | ||
{ | ||
/** | ||
* Finds all entities in the repository. | ||
* | ||
* @return array The entities. | ||
*/ | ||
public function findAll() | ||
{ | ||
return parent::findAll(); | ||
} | ||
|
||
/** | ||
* save Service to the DB. | ||
* @param Service $service | ||
*/ | ||
public function save(Service $service) | ||
{ | ||
$this->_em->persist($service); | ||
$this->_em->flush(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace HMS\Repositories\Instrumentation; | ||
|
||
use HMS\Entities\Instrumentation\Event; | ||
use HMS\Entities\Instrumentation\Service; | ||
|
||
interface EventRepository | ||
{ | ||
/** | ||
* @param Service $service | ||
* @param int $perPage | ||
* @param string $pageName | ||
* | ||
* @return \Illuminate\Pagination\LengthAwarePaginator | ||
*/ | ||
public function paginateByService(Service $service, $perPage = 15, $pageName = 'page'); | ||
|
||
/** | ||
* save Event to the DB. | ||
* @param Event $event | ||
*/ | ||
public function save(Event $event); | ||
} |
21 changes: 21 additions & 0 deletions
21
app/HMS/Repositories/Instrumentation/ServiceRepository.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace HMS\Repositories\Instrumentation; | ||
|
||
use HMS\Entities\Instrumentation\Service; | ||
|
||
interface ServiceRepository | ||
{ | ||
/** | ||
* Finds all entities in the repository. | ||
* | ||
* @return array The entities. | ||
*/ | ||
public function findAll(); | ||
|
||
/** | ||
* save Service to the DB. | ||
* @param Service $service | ||
*/ | ||
public function save(Service $service); | ||
} |
57 changes: 57 additions & 0 deletions
57
app/Http/Controllers/Instrumentation/ServiceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Instrumentation; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use HMS\Entities\Instrumentation\Service; | ||
use HMS\Repositories\Instrumentation\EventRepository; | ||
use HMS\Repositories\Instrumentation\ServiceRepository; | ||
|
||
class ServiceController extends Controller | ||
{ | ||
/** | ||
* @var ServiceRepository | ||
*/ | ||
protected $serviceRepository; | ||
|
||
/** | ||
* @var EventRepository | ||
*/ | ||
protected $eventRepository; | ||
|
||
/** | ||
* Construct a new Controller. | ||
* | ||
* @param ServiceRepository $serviceRepository | ||
*/ | ||
public function __construct( | ||
ServiceRepository $serviceRepository, | ||
EventRepository $eventRepository | ||
) { | ||
$this->serviceRepository = $serviceRepository; | ||
$this->eventRepository = $eventRepository; | ||
} | ||
|
||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function status() | ||
{ | ||
$services = $this->serviceRepository->findAll(); | ||
|
||
return view('instrumentation.status') | ||
->with('services', $services); | ||
} | ||
|
||
public function eventsForService(Service $service, Request $request) | ||
{ | ||
$events = $this->eventRepository->paginateByService($service); | ||
|
||
return view('instrumentation.eventsForService') | ||
->with('service', $service) | ||
->with('events', $events); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
resources/views/instrumentation/eventsForService.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
@extends('layouts.app') | ||
|
||
@section('pageTitle', 'Events for ' . $service->getName()) | ||
|
||
@section('content') | ||
<div class="container"> | ||
<div class="table-responsive"> | ||
<table class="table table-striped table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Time</th> | ||
<th>Type</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($events as $event) | ||
<tr> | ||
<td class="text-monospace">{{ $event->getTime()->toDateTimeString() }}</td> | ||
<td>{{ $event->getType() }}</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
<div class="container"> | ||
{{ $events->links() }} | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@extends('layouts.app') | ||
|
||
@section('pageTitle', 'Instrumentaion Services') | ||
|
||
@section('content') | ||
<div class="container"> | ||
<div class="table-responsive no-more-tables"> | ||
<table class="table table-striped table-hover"> | ||
<thead> | ||
<tr> | ||
<th>Service</th> | ||
<th>Status</th> | ||
<th>Last response</th> | ||
<th>Last restart</th> | ||
<th>Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach($services as $service) | ||
<tr class="{{ $service->getStatus() != 1 ? 'bg-danger text-white' : '' }}"> | ||
<td data-title="Service">{{ $service->getName() }}</td> | ||
<td data-title="Status">{{ $service->getStatusString() }}</td> | ||
<td data-title="Last response">{{ $service->getReplyTime()->toDateTimeString() }}</td> | ||
<td data-title="Last restart">{{ $service->getRestartTime() ? $service->getRestartTime()->toDateTimeString() : '(unknown)' }}</td> | ||
<td class="actions"><a class="btn btn-primary btn-sm btn-sm-spacing" href="{{ route('instrumentation.service.events', $service->getName() ) }}"><i class="far fa-eye" aria-hidden="true"></i> View Events</a> | ||
</td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters