add data retention to the metrics

This commit is contained in:
Saeed Vaziry
2024-04-13 22:38:27 +02:00
parent ddacc32e64
commit 52d195710b
18 changed files with 346 additions and 140 deletions

View File

@ -3,7 +3,9 @@
namespace App\Http\Controllers;
use App\Actions\Monitoring\GetMetrics;
use App\Actions\Monitoring\UpdateMetricSettings;
use App\Facades\Toast;
use App\Helpers\HtmxResponse;
use App\Models\Server;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
@ -13,15 +15,30 @@ class MetricController extends Controller
{
public function index(Server $server, Request $request): View|RedirectResponse
{
if (! $server->service('monitoring')) {
Toast::error('You need to install monitoring service first');
return redirect()->route('servers.services', $server);
}
$this->checkIfMonitoringServiceInstalled($server);
return view('metrics.index', [
'server' => $server,
'data' => app(GetMetrics::class)->filter($server, $request->input()),
'lastMetric' => $server->metrics()->latest()->first(),
]);
}
public function settings(Server $server, Request $request): HtmxResponse
{
$this->checkIfMonitoringServiceInstalled($server);
app(UpdateMetricSettings::class)->update($server, $request->input());
Toast::success('Metric settings updated successfully');
return htmx()->back();
}
private function checkIfMonitoringServiceInstalled(Server $server): void
{
if (! $server->monitoring()) {
abort(404, 'Monitoring service is not installed on this server');
}
}
}