feat: add aggregated resource usage chart to dashboard
This commit is contained in:
@@ -173,6 +173,29 @@ class MonitoringService
|
||||
);
|
||||
}
|
||||
|
||||
public function getAggregatedHistoricalMetrics(array $serverIds, int $hours = 24): array
|
||||
{
|
||||
if (empty($serverIds)) {
|
||||
return [];
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($serverIds), '?'));
|
||||
$params = $serverIds;
|
||||
$params[] = $hours;
|
||||
return $this->db->fetchAll(
|
||||
"SELECT
|
||||
DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:00') as time_bucket,
|
||||
AVG(cpu_usage) as avg_cpu,
|
||||
AVG(ram_usage) as avg_ram,
|
||||
AVG(disk_usage) as avg_disk
|
||||
FROM monitoring_history
|
||||
WHERE server_id IN ({$placeholders})
|
||||
AND created_at >= DATE_SUB(NOW(), INTERVAL ? HOUR)
|
||||
GROUP BY time_bucket
|
||||
ORDER BY time_bucket ASC",
|
||||
$params
|
||||
);
|
||||
}
|
||||
|
||||
public function getDashboardStats(?array $serverIds = null): array
|
||||
{
|
||||
$where = '';
|
||||
|
||||
Reference in New Issue
Block a user