authorize('viewAny', [Metric::class, $server]); return Inertia::render('monitoring/index', [ 'lastMetric' => $server->metrics()->latest()->first(), 'dataRetention' => $server->monitoring()?->type_data['data_retention'] ?? 30, 'hasMonitoringService' => $server->monitoring()?->status === ServiceStatus::READY, ]); } #[Get('/json', name: 'monitoring.json')] public function json(Request $request, Server $server): JsonResponse { $this->authorize('viewAny', [Metric::class, $server]); $metrics = app(GetMetrics::class)->filter($server, $request->input()); return response()->json($metrics); } #[Get('/{metric}', name: 'monitoring.show')] public function show(Server $server, string $metric): Response { if (! in_array($metric, ['load', 'memory', 'disk'])) { abort(404); } $this->authorize('viewAny', [Metric::class, $server]); return Inertia::render('monitoring/show', [ 'metric' => $metric, ]); } #[Patch('/update', name: 'monitoring.update')] public function update(Request $request, Server $server): RedirectResponse { /** @var ?Service $monitoring */ $monitoring = $server->monitoring(); if (! $monitoring) { abort(404); } $this->authorize('update', $monitoring); app(UpdateMetricSettings::class)->update($server, $request->input()); return back()->with('success', 'Settings updated!'); } #[Delete('/reset', name: 'monitoring.destroy')] public function destroy(Server $server): RedirectResponse { /** @var ?Service $monitoring */ $monitoring = $server->monitoring(); if (! $monitoring) { abort(404); } $this->authorize('update', $monitoring); $server->metrics()->delete(); return back()->with('success', 'All metrics deleted!'); } }