Increase status polling interval to 5 seconds across Proxmox views; update layout styles and add new CSS for improved UI elements and animations.
This commit is contained in:
@@ -57,48 +57,46 @@ class Server extends Component
|
||||
// Cache for 15 minutes to avoid recalculating for every server
|
||||
return Cache::remember('bandwidth_threshold_95_' . Carbon::now()->format('Y-m'), 900, function () {
|
||||
$startOfMonth = Carbon::now()->startOfMonth();
|
||||
|
||||
// Get all servers
|
||||
$allServers = ServerModel::all();
|
||||
|
||||
if ($allServers->isEmpty()) {
|
||||
|
||||
// Use 2 aggregate queries instead of N+1 (was 2*N+1 queries)
|
||||
$firstStats = ServerStatistics::selectRaw('server_id, MIN(netin) as first_netin, MIN(netout) as first_netout')
|
||||
->where('DateTime', '>=', $startOfMonth)
|
||||
->groupBy('server_id')
|
||||
->pluck(null, 'server_id');
|
||||
|
||||
$latestStats = ServerStatistics::selectRaw('server_id, MAX(netin) as last_netin, MAX(netout) as last_netout')
|
||||
->where('DateTime', '>=', $startOfMonth)
|
||||
->groupBy('server_id')
|
||||
->pluck(null, 'server_id');
|
||||
|
||||
if ($firstStats->isEmpty()) {
|
||||
return 10; // Minimum threshold of 10 GiB
|
||||
}
|
||||
|
||||
|
||||
$trafficValues = [];
|
||||
|
||||
foreach ($allServers as $server) {
|
||||
// Get the earliest and latest statistics for this month for each server
|
||||
$firstStat = ServerStatistics::where('server_id', $server->id)
|
||||
->where('DateTime', '>=', $startOfMonth)
|
||||
->orderBy('DateTime', 'asc')
|
||||
->first();
|
||||
|
||||
$latestStat = ServerStatistics::where('server_id', $server->id)
|
||||
->where('DateTime', '>=', $startOfMonth)
|
||||
->orderBy('DateTime', 'desc')
|
||||
->first();
|
||||
|
||||
if ($firstStat && $latestStat) {
|
||||
// Calculate total traffic (in + out) for the month
|
||||
$netinDiff = max(0, $latestStat->netin - $firstStat->netin);
|
||||
$netoutDiff = max(0, $latestStat->netout - $firstStat->netout);
|
||||
$totalBytes = $netinDiff + $netoutDiff;
|
||||
|
||||
// Convert to GiB and collect
|
||||
$trafficValues[] = $totalBytes / (1024 * 1024 * 1024);
|
||||
|
||||
foreach ($firstStats as $serverId => $first) {
|
||||
$latest = $latestStats->get($serverId);
|
||||
if (!$latest) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$netinDiff = max(0, $latest->last_netin - $first->first_netin);
|
||||
$netoutDiff = max(0, $latest->last_netout - $first->first_netout);
|
||||
$totalBytes = $netinDiff + $netoutDiff;
|
||||
|
||||
$trafficValues[] = $totalBytes / (1024 * 1024 * 1024);
|
||||
}
|
||||
|
||||
|
||||
if (empty($trafficValues)) {
|
||||
return 10; // Minimum threshold of 10 GiB
|
||||
}
|
||||
|
||||
|
||||
// Calculate actual 95th percentile by sorting and taking the value at the 95th rank
|
||||
sort($trafficValues);
|
||||
$index = (int) ceil(0.95 * count($trafficValues)) - 1;
|
||||
$threshold95Percent = $trafficValues[$index];
|
||||
|
||||
|
||||
// Return the maximum of 95th percentile or 10 GiB minimum
|
||||
return round(max($threshold95Percent, 10), 2);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user