@extends('layouts.app') @section('title', 'Dashboard tổng quan') @section('page_title', 'Dashboard tổng quan') @section('breadcrumb') @endsection @push('styles') @endpush @section('content') @php // Cột đang là "hiện tại" — index = giờ*2 + (phút >= 30 ? 1 : 0) $displayTz = config('app.display_timezone'); $now = \Carbon\Carbon::now($displayTz); $currentSlotIndex = $now->isSameDay($date) ? $now->hour * 2 + ($now->minute >= 30 ? 1 : 0) : -1; @endphp {{-- Info bar --}}
Dữ liệu hôm nay {{ $date->format('d/m/Y') }} — {{ $date->isoFormat('dddd') }}
Thông số < 60 xanh • 60 – 79 vàng • ≥ 80 đỏ
{{-- Domain cards --}} @if (empty($domains))
Chưa có domain nào có IP để hiển thị.
Thêm domain
@else @php $metricRows = [ ['label' => 'RAM', 'field' => 'ram_usage_pct'], ['label' => 'CPU', 'field' => 'cpu_usage_pct'], ['label' => 'DISK', 'field' => 'disk_usage_pct'], ]; // slotKeys tính 1 lần duy nhất, dùng lại cho cả chart data lẫn bảng dưới — tránh gọi // Carbon::format() lặp lại nhiều lần cho cùng 1 slot (trước đây tới 4 lần/slot/server). $slotKeys = array_map(fn ($s) => $s->format('Y-m-d H:i:s'), $slots); $chartLabels = array_map(fn ($s) => $s->format('H:i'), $slots); $chartData = []; foreach ($domains as $item) { $domainItem = ['domainId' => $item['domain']->id, 'servers' => []]; foreach ($item['servers'] as $server) { $ram = $cpu = $disk = []; foreach ($slotKeys as $slotKey) { $key = $server->id.'|'.$slotKey; $metric = $item['metrics']->get($key); $ram[] = $metric !== null ? $metric['ram_usage_pct'] : null; $cpu[] = $metric !== null ? $metric['cpu_usage_pct'] : null; $disk[] = $metric !== null ? $metric['disk_usage_pct'] : null; } $domainItem['servers'][] = [ 'id' => $server->id, 'ram' => $ram, 'cpu' => $cpu, 'disk' => $disk, ]; } $chartData[] = $domainItem; } @endphp
@foreach ($domains as $item) @php $domain = $item['domain']; $servers = $item['servers']; $metrics = $item['metrics']; $collapseId = 'domain-'.$domain->id; @endphp

{{ $domain->name }} {{ $servers->count() }} IP

@foreach ($chartLabels as $slotIdx => $label) @endforeach @foreach ($servers as $server) @foreach ($metricRows as $i => $row) $i === count($metricRows) - 1, 'ip-block-alt' => $loop->parent->iteration % 2 === 0, ])> @if ($i === 0) @endif @foreach ($slotKeys as $slotIdx => $slotKey) @php $key = $server->id.'|'.$slotKey; $metric = $metrics->get($key); $value = $metric !== null ? $metric[$row['field']] : null; $color = 'bg-empty'; if ($value !== null) { $color = $value < 60 ? 'bg-success' : ($value < 80 ? 'bg-warning' : 'bg-danger'); } @endphp @endforeach @endforeach @endforeach
IP Chỉ số {{ $label }}
{{ $server->ip_address }} {{ $row['label'] }} {{ $value !== null ? $value.'%' : '—' }}
@endforeach @endif @endsection @push('scripts') @if (! empty($domains)) @endif @endpush