@extends('layouts.app')
@section('title', 'Dashboard chi tiết')
@section('page_title', 'Dashboard chi tiết')
@section('breadcrumb')
Chi tiết
@endsection
@push('styles')
@endpush
@section('content')
@if ($hasFilter)
@if ($servers->isEmpty())
Domain này chưa có IP nào.
Thêm IP để bắt đầu giám sát.
@elseif (empty($days))
Domain này chưa có dữ liệu giám sát nào.
@else
@php
$metricRows = [
['label' => 'RAM', 'field' => 'ram_usage_pct'],
['label' => 'CPU', 'field' => 'cpu_usage_pct'],
['label' => 'DISK', 'field' => 'disk_usage_pct'],
];
$displayTz = config('app.display_timezone');
$now = \Carbon\Carbon::now($displayTz);
// Build dataset cho Chart.js — chỉ làm 1 lần ở PHP side, JS chỉ render.
$chartData = [];
foreach ($days as $day) {
$dayItem = [
'dateKey' => $day['date']->format('Ymd'),
'labels' => collect($day['slots'])->map(fn ($s) => $s->format('H:i'))->all(),
'servers' => [],
];
foreach ($servers as $server) {
$ram = $cpu = $disk = [];
foreach ($day['slots'] as $slot) {
$key = $server->id.'|'.$slot->format('Y-m-d H:i:s');
$metric = $day['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;
}
$dayItem['servers'][] = [
'id' => $server->id,
'ram' => $ram,
'cpu' => $cpu,
'disk' => $disk,
];
}
$chartData[] = $dayItem;
}
@endphp
@foreach ($days as $day)
@php
$date = $day['date'];
$slots = $day['slots'];
$metrics = $day['metrics'];
$collapseId = 'day-'.$date->format('Ymd');
$currentSlotIndex = $now->isSameDay($date)
? $now->hour * 2 + ($now->minute >= 30 ? 1 : 0)
: -1;
@endphp
| IP |
Chỉ số |
@foreach ($slots as $slotIdx => $slot)
{{ $slot->format('H:i') }}
|
@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)
|
{{ $server->ip_address }}
|
@endif
{{ $row['label'] }} |
@foreach ($slots as $slotIdx => $slot)
@php
$key = $server->id.'|'.$slot->format('Y-m-d H:i:s');
$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
{{ $value !== null ? $value.'%' : '—' }}
|
@endforeach
@endforeach
@endforeach
@foreach ($servers as $server)
{{ $server->ip_address }}
@endforeach
@endforeach
@endif
@endif
@endsection
@push('scripts')
@if ($hasFilter && ! empty($days ?? []))
@endif
@endpush