Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 0 additions & 35 deletions app/Actions/Ookla/EvaluateResultHealth.php

This file was deleted.

12 changes: 11 additions & 1 deletion app/Filament/Resources/ResultResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public static function form(Form $form): Form
Forms\Components\Placeholder::make('server_host')
->content(fn (Result $result): ?string => $result->server_host),
Forms\Components\Checkbox::make('scheduled'),
Forms\Components\Checkbox::make('healthy'),
])
->columns(1)
->columnSpan([
Expand Down Expand Up @@ -315,6 +316,11 @@ public static function table(Table $table): Table
->toggleable()
->toggledHiddenByDefault()
->alignment(Alignment::Center),
Tables\Columns\IconColumn::make('healthy')
->boolean()
->toggleable()
->toggledHiddenByDefault()
->alignment(Alignment::Center),
Tables\Columns\TextColumn::make('created_at')
->dateTime(config('app.datetime_format'))
->timezone(config('app.display_timezone'))
Expand Down Expand Up @@ -347,7 +353,7 @@ public static function table(Table $table): Table
})
->attribute('data->interface->externalIp'),
Tables\Filters\TernaryFilter::make('scheduled')
->placeholder('-')
->nullable()
->trueLabel('Only scheduled speedtests')
->falseLabel('Only manual speedtests')
->queries(
Expand All @@ -358,6 +364,10 @@ public static function table(Table $table): Table
Tables\Filters\SelectFilter::make('status')
->multiple()
->options(ResultStatus::class),
Tables\Filters\TernaryFilter::make('healthy')
->nullable()
->trueLabel('Only healthy speedtests')
->falseLabel('Only unhealthy speedtests'),
])
->actions([
Tables\Actions\ActionGroup::make([
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function bitrate(float|int $bytes, array $benchmark): bool
return true;
}

return Bitrate::bytesToBits($bytes) < Bitrate::normalizeToBits($value.$unit);
return Bitrate::bytesToBits($bytes) >= Bitrate::normalizeToBits($value.$unit);
}

/**
Expand All @@ -35,6 +35,6 @@ public static function ping(float|int $ping, array $benchmark): bool
return true;
}

return $ping >= $value;
return $ping < $value;
}
}
34 changes: 25 additions & 9 deletions app/Jobs/Ookla/BenchmarkSpeedtestJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace App\Jobs\Ookla;

use App\Actions\Ookla\EvaluateResultHealth;
use App\Enums\ResultStatus;
use App\Events\SpeedtestBenchmarking;
use App\Helpers\Benchmark;
use App\Models\Result;
use App\Settings\ThresholdSettings;
use Illuminate\Bus\Batchable;
Expand All @@ -16,6 +16,8 @@ class BenchmarkSpeedtestJob implements ShouldQueue
{
use Batchable, Queueable;

public bool $healthy = true;

/**
* Create a new job instance.
*/
Expand All @@ -28,13 +30,9 @@ public function __construct(
*/
public function handle(): void
{
if ($this->batch()->cancelled()) {
return;
}

$settings = app(ThresholdSettings::class);

if ($settings->absolute_enabled === false) {
if ($this->batch()->cancelled() || $settings->absolute_enabled == false) {
return;
}

Expand All @@ -44,47 +42,65 @@ public function handle(): void

SpeedtestBenchmarking::dispatch($this->result);

$benchmarks = $this->buildBenchmarks($settings);
$benchmarks = $this->benchmark(
result: $this->result,
settings: $settings,
);

if (! count($benchmarks)) {
return;
}

$this->result->update([
'benchmarks' => $benchmarks,
'healthy' => EvaluateResultHealth::run($this->result, $benchmarks),
'healthy' => $this->healthy,
]);
}

private function buildBenchmarks(ThresholdSettings $settings): array
private function benchmark(Result $result, ThresholdSettings $settings): array
{
$benchmarks = [];

if (! blank($settings->absolute_download) && $settings->absolute_download > 0) {
$benchmarks = Arr::add($benchmarks, 'download', [
'bar' => 'min',
'passed' => Benchmark::bitrate($result->download, ['value' => $settings->absolute_download, 'unit' => 'mbps']),
'type' => 'absolute',
'value' => $settings->absolute_download,
'unit' => 'mbps',
]);

if (Arr::get($benchmarks, 'download.passed') == false) {
$this->healthy = false;
}
}

if (! blank($settings->absolute_upload) && $settings->absolute_upload > 0) {
$benchmarks = Arr::add($benchmarks, 'upload', [
'bar' => 'min',
'passed' => filter_var(Benchmark::bitrate($result->upload, ['value' => $settings->absolute_upload, 'unit' => 'mbps']), FILTER_VALIDATE_BOOLEAN),
'type' => 'absolute',
'value' => $settings->absolute_upload,
'unit' => 'mbps',
]);

if (Arr::get($benchmarks, 'upload.passed') == false) {
$this->healthy = false;
}
}

if (! blank($settings->absolute_ping) && $settings->absolute_ping > 0) {
$benchmarks = Arr::add($benchmarks, 'ping', [
'bar' => 'max',
'passed' => Benchmark::ping($result->ping, ['value' => $settings->absolute_ping]),
'type' => 'absolute',
'value' => $settings->absolute_ping,
'unit' => 'ms',
]);

if (Arr::get($benchmarks, 'ping.passed') == false) {
$this->healthy = false;
}
}

return $benchmarks;
Expand Down
1 change: 0 additions & 1 deletion app/Jobs/Ookla/ProcessSpeedtestBatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Jobs\Ookla;

use App\Jobs\CheckForInternetConnectionJob;
use App\Jobs\SkipSpeedtestJob;
use App\Models\Result;
use Illuminate\Bus\Batch;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Jobs;
namespace App\Jobs\Ookla;

use App\Actions\GetExternalIpAddress;
use App\Enums\ResultStatus;
Expand Down