Fix query and display metrics
- Remove LIMIT 200000 from SQL - GROUP BY handles aggregation - Pass displayMetrics to template - Replace hardcoded filters with visibleMetrics array - If displayMetrics is set in server settings, show only selected metrics - Otherwise show default metrics (backward compatibility)
This commit is contained in:
parent
393edebee6
commit
c4f3a1388d
|
|
@ -146,24 +146,20 @@ class ServerDetailController extends Model
|
||||||
|
|
||||||
// Запрос с агрегацией если нужно
|
// Запрос с агрегацией если нужно
|
||||||
if ($groupBy) {
|
if ($groupBy) {
|
||||||
// Оптимизированный запрос с подзапросом и LIMIT для больших периодов
|
// GROUP BY автоматически агрегирует до нужного количества точек (500 для любого периода)
|
||||||
$sql = "
|
$sql = "
|
||||||
SELECT
|
SELECT
|
||||||
AVG(sm.value) as value,
|
AVG(sm.value) as value,
|
||||||
mn.name,
|
mn.name,
|
||||||
mn.unit,
|
mn.unit,
|
||||||
DATE_FORMAT(sm.created_at, '{$bucketFormat}') as time_bucket
|
DATE_FORMAT(sm.created_at, '{$bucketFormat}') as time_bucket
|
||||||
FROM (
|
FROM server_metrics sm
|
||||||
SELECT sm_inner.value, sm_inner.metric_name_id, sm_inner.created_at
|
FORCE INDEX (idx_server_metric_time)
|
||||||
FROM server_metrics sm_inner
|
|
||||||
FORCE INDEX (idx_server_metric_time)
|
|
||||||
WHERE sm_inner.server_id = :id
|
|
||||||
AND sm_inner.created_at >= :start_date
|
|
||||||
AND sm_inner.created_at <= :end_date
|
|
||||||
LIMIT 200000
|
|
||||||
) sm
|
|
||||||
INNER JOIN metric_names mn ON mn.id = sm.metric_name_id
|
INNER JOIN metric_names mn ON mn.id = sm.metric_name_id
|
||||||
WHERE 1=1 {$metricsFilter}
|
WHERE sm.server_id = :id
|
||||||
|
AND sm.created_at >= :start_date
|
||||||
|
AND sm.created_at <= :end_date
|
||||||
|
AND 1=1 {$metricsFilter}
|
||||||
{$groupBy}
|
{$groupBy}
|
||||||
ORDER BY time_bucket ASC
|
ORDER BY time_bucket ASC
|
||||||
";
|
";
|
||||||
|
|
@ -299,6 +295,7 @@ class ServerDetailController extends Model
|
||||||
'title' => 'Сервер: ' . $server['name'],
|
'title' => 'Сервер: ' . $server['name'],
|
||||||
'server' => $server,
|
'server' => $server,
|
||||||
'metrics' => $groupedMetrics,
|
'metrics' => $groupedMetrics,
|
||||||
|
'displayMetrics' => $displayMetrics,
|
||||||
'allMetricTypes' => $allMetricTypes,
|
'allMetricTypes' => $allMetricTypes,
|
||||||
'existingThresholds' => $existingThresholds,
|
'existingThresholds' => $existingThresholds,
|
||||||
'allServices' => $allServices,
|
'allServices' => $allServices,
|
||||||
|
|
|
||||||
|
|
@ -153,8 +153,9 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{% set visibleMetrics = displayMetrics ?: ['cpu_load', 'ram_used', 'disk_used_root', 'disk_used_home', 'disk_used_boot', 'temp_cpu', 'temp_disk_sda', 'temp_disk_sdb', 'temp_disk_sdc'] %}
|
||||||
{% for metricName, metricData in metrics %}
|
{% for metricName, metricData in metrics %}
|
||||||
{% if metricName!="top_cpu_proc" and metricName!="top_ram_proc" and metricName!="disk_used" and not (metricName starts with "disk_used_") and not (metricName starts with "disk_total_gb_") and metricName!="ram_total_gb" and not (metricName starts with "net_in_") and not (metricName starts with "net_out_") and metricName!="network_rx" and metricName!="network_tx" and not (metricName starts with "temp_") %}
|
{% if metricName in visibleMetrics %}
|
||||||
<div class="col-12 mb-4">
|
<div class="col-12 mb-4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
|
|
@ -666,8 +667,9 @@ var diskTotalGB = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Графики метрик
|
// Графики метрик
|
||||||
|
{% set visibleMetrics = displayMetrics ?: ['cpu_load', 'ram_used', 'disk_used_root', 'disk_used_home', 'disk_used_boot', 'temp_cpu', 'temp_disk_sda', 'temp_disk_sdb', 'temp_disk_sdc'] %}
|
||||||
{% for metricName, metricData in metrics %}
|
{% for metricName, metricData in metrics %}
|
||||||
{% if metricName!="top_cpu_proc" and metricName!="top_ram_proc" and metricName!="disk_used" and not (metricName starts with "disk_used_") and not (metricName starts with "disk_total_gb_") and metricName!="ram_total_gb" and not (metricName starts with "net_in_") and not (metricName starts with "net_out_") and metricName!="network_rx" and metricName!="network_tx" and not (metricName starts with "temp_") and metricName!="uptime" %}
|
{% if metricName in visibleMetrics and metricName != 'uptime' %}
|
||||||
const ctx{{ metricName|replace({'-': '_', '.': '_'}) }} = document.getElementById('chart-{{ metricName }}').getContext('2d');
|
const ctx{{ metricName|replace({'-': '_', '.': '_'}) }} = document.getElementById('chart-{{ metricName }}').getContext('2d');
|
||||||
|
|
||||||
// Подготовка данных для графика
|
// Подготовка данных для графика
|
||||||
|
|
@ -893,8 +895,9 @@ chart{{ metricName|replace({'-': '_', '.': '_'}) }}.canvas.addEventListener('mou
|
||||||
// Глобальный обработчик mousemove для скрытия тултипов при уходе курсора за пределы canvas
|
// Глобальный обработчик mousemove для скрытия тултипов при уходе курсора за пределы canvas
|
||||||
// Глобальный обработчик для скрытия тултипов при уходе курсора за пределы canvas
|
// Глобальный обработчик для скрытия тултипов при уходе курсора за пределы canvas
|
||||||
document.addEventListener('mousemove', function(e) {
|
document.addEventListener('mousemove', function(e) {
|
||||||
|
{% set visibleMetrics = displayMetrics ?: ['cpu_load', 'ram_used', 'disk_used_root', 'disk_used_home', 'disk_used_boot', 'temp_cpu', 'temp_disk_sda', 'temp_disk_sdb', 'temp_disk_sdc'] %}
|
||||||
{% for metricName, metricData in metrics %}
|
{% for metricName, metricData in metrics %}
|
||||||
{% if metricName!="top_cpu_proc" and metricName!="top_ram_proc" and metricName!="disk_used" and not (metricName starts with "disk_used_") and not (metricName starts with "disk_total_gb_") and metricName!="ram_total_gb" and not (metricName starts with "net_in_") and not (metricName starts with "net_out_") and metricName!="network_rx" and metricName!="network_tx" and not (metricName starts with "temp_") and metricName!="uptime" %}
|
{% if metricName in visibleMetrics and metricName != 'uptime' %}
|
||||||
(function() {
|
(function() {
|
||||||
var canvas = chart{{ metricName|replace({'-': '_', '.': '_'}) }}.canvas;
|
var canvas = chart{{ metricName|replace({'-': '_', '.': '_'}) }}.canvas;
|
||||||
var rect = canvas.getBoundingClientRect();
|
var rect = canvas.getBoundingClientRect();
|
||||||
|
|
@ -1114,8 +1117,9 @@ document.addEventListener('mousemove', function(e) {
|
||||||
|
|
||||||
// Сбросить зум на всех графиках
|
// Сбросить зум на всех графиках
|
||||||
function resetAllZoom() {
|
function resetAllZoom() {
|
||||||
|
{% set visibleMetrics = displayMetrics ?: ['cpu_load', 'ram_used', 'disk_used_root', 'disk_used_home', 'disk_used_boot', 'temp_cpu', 'temp_disk_sda', 'temp_disk_sdb', 'temp_disk_sdc'] %}
|
||||||
{% for metricName, metricData in metrics %}
|
{% for metricName, metricData in metrics %}
|
||||||
{% if metricName!="top_cpu_proc" and metricName!="top_ram_proc" and metricName!="disk_used" and not (metricName starts with "disk_used_") and not (metricName starts with "disk_total_gb_") and metricName!="ram_total_gb" and not (metricName starts with "net_in_") and not (metricName starts with "net_out_") and metricName!="network_rx" and metricName!="network_tx" and not (metricName starts with "temp_") %}
|
{% if metricName in visibleMetrics and metricName != 'uptime' %}
|
||||||
if (typeof chart{{ metricName|replace({'-': '_', '.': '_'}) }} !== 'undefined') {
|
if (typeof chart{{ metricName|replace({'-': '_', '.': '_'}) }} !== 'undefined') {
|
||||||
chart{{ metricName|replace({'-': '_', '.': '_'}) }}.resetZoom();
|
chart{{ metricName|replace({'-': '_', '.': '_'}) }}.resetZoom();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue