Skip to content
Snippets Groups Projects
Commit 8ebf97b3 authored by Tibo's avatar Tibo
Browse files

implement job throttling

parent 7bc61949
No related branches found
No related tags found
No related merge requests found
Pipeline #19722 passed
...@@ -3,12 +3,13 @@ ...@@ -3,12 +3,13 @@
namespace App; namespace App;
use App\Jobs\RunAgent; use App\Jobs\RunAgent;
use App\Server;
use App\Sensor\StatusChangeDetector; use App\Sensor\StatusChangeDetector;
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\File;
use Illuminate\Support\LazyCollection; use Illuminate\Support\LazyCollection;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Queue;
use Symfony\Component\Finder\SplFileInfo; use Symfony\Component\Finder\SplFileInfo;
/** /**
...@@ -110,10 +111,19 @@ class AgentScheduler ...@@ -110,10 +111,19 @@ class AgentScheduler
})->toArray(); })->toArray();
} }
public function throttlingTreshold() : int
{
return max(2, Server::count()) * 2 * $this->sensors()->count();
}
// ------------------ SCHEDULING of agents // ------------------ SCHEDULING of agents
public function notify(Record $record) public function notify(Record $record)
{ {
if (Queue::size() > $this->throttlingTreshold()) {
return;
}
$trigger_label = $record->label; $trigger_label = $record->label;
if (! isset($this->triggers[$trigger_label])) { if (! isset($this->triggers[$trigger_label])) {
......
@extends('layouts.app') @extends('layouts.app')
@php
$scheduler = \App\AgentScheduler::get();
@endphp
@section('title', 'Status') @section('title', 'Status')
@section('content') @section('content')
...@@ -7,11 +11,29 @@ ...@@ -7,11 +11,29 @@
<h1>Status</h1> <h1>Status</h1>
<h2>Jobs</h2> <h2>Jobs</h2>
<p>Jobs in queue: {{ Queue::size() }}</p> <p>Analysis jobs in queue: {{ Queue::size() }}</p>
<p>
Throttling threshold: {{ $scheduler->throttlingTreshold() }}
</p>
<p class="text-muted">
<i class="fas fa-question-circle"></i> When queue size reaches threshold, any new analysis job will be discarded
until the queue size falls below threshold.
</p>
<h2>Database</h2> <h2>Database</h2>
<p>Servers : {{ \App\Server::count() }}</p> <p>Servers : {{ \App\Server::count() }}</p>
<p>Records : {{ \App\Record::count() }}</p> <p>Records : {{ \App\Record::count() }}</p>
<p>Reports : {{ \App\Report::count() }}</p> <p>Reports : {{ \App\Report::count() }}</p>
<h2>Agents</h2>
<p>Autodiscovered <b>{{ $scheduler->sensors()->count() }}</b> analysis agents</p>
<table class="table table-sm">
@foreach ($scheduler->sensors() as $sensor)
<tr>
<td>{{ get_class($sensor) }}</td>
</tr>
@endforeach
</table>
</div> </div>
@endsection @endsection
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment