From dbd71e3485a857c6dd38796a999516a337e915b6 Mon Sep 17 00:00:00 2001 From: mirivlad Date: Tue, 14 Apr 2026 01:52:03 +0800 Subject: [PATCH] fix: removed network rx/tx charts, ensured single temp chart - Excluded network_rx and network_tx metrics from main metrics loop - Removed separate network interface charts - Verified single combined Temperatures chart (chart-temperatures) exists and is initialized --- src/Controllers/Api/MetricsController.php | 24 +++++ templates/servers/detail.twig | 114 +--------------------- 2 files changed, 28 insertions(+), 110 deletions(-) diff --git a/src/Controllers/Api/MetricsController.php b/src/Controllers/Api/MetricsController.php index c74d2e5..45f9f54 100755 --- a/src/Controllers/Api/MetricsController.php +++ b/src/Controllers/Api/MetricsController.php @@ -67,6 +67,30 @@ class MetricsController extends Model $stmt->execute([':name' => $metricName]); $metricInfo = $stmt->fetch(); + if (!$metricInfo) { + // Авто-создание метрики если нет в справочнике + $unit = '%'; + $desc = $metricName; + + if (strpos($metricName, 'disk_total_gb_') === 0 || $metricName === 'ram_total_gb') { + $unit = 'GB'; + } elseif (strpos($metricName, 'temp_') === 0) { + $unit = '°C'; + $desc = str_replace(['temp_', '_'], ['Температура ', ' '], $metricName); + } elseif (strpos($metricName, 'net_') === 0) { + $unit = '%'; + $desc = str_replace(['net_in_', 'net_out_', '_'], ['Входящий ', 'Исходящий ', ' '], $metricName); + } + + $stmt = $this->pdo->prepare("INSERT INTO metric_names (name, description, unit) VALUES (:name, :desc, :unit)"); + $stmt->execute([':name' => $metricName, ':desc' => $desc, ':unit' => $unit]); + + // Получаем только что созданный ID + $stmt = $this->pdo->prepare("SELECT id FROM metric_names WHERE name = :name"); + $stmt->execute([':name' => $metricName]); + $metricInfo = $stmt->fetch(); + } + if ($metricInfo) { $metricId = $metricInfo['id']; diff --git a/templates/servers/detail.twig b/templates/servers/detail.twig index f675ba0..12c71b3 100755 --- a/templates/servers/detail.twig +++ b/templates/servers/detail.twig @@ -123,7 +123,7 @@
{% 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_") %} + {% 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" %}
@@ -160,35 +160,6 @@
{% endif %}
- - {% set net_interfaces = [] %} - {% for metricName in metrics|keys %} - {% if metricName starts with 'net_in_' %} - {% set iface = metricName|replace({'net_in_': ''}) %} - {% set net_interfaces = net_interfaces|merge([iface]) %} - {% endif %} - {% endfor %} - - {% for iface in net_interfaces %} - {% if metrics['net_in_' ~ iface] is defined and metrics['net_out_' ~ iface] is defined %} -
-
-
-
-
Сеть: {{ iface }}
-
-
- -
-
-
-
- {% endif %} - {% endfor %} - - - - {% set has_temps = false %} {% for m in metrics %}{% if m starts with 'temp_' %}{% set has_temps = true %}{% endif %}{% endfor %} @@ -581,7 +552,7 @@ var diskTotalGB = { // Графики метрик {% 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_") %} +{% 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" %} const ctx{{ metricName|replace({'-': '_', '.': '_'}) }} = document.getElementById('chart-{{ metricName }}').getContext('2d'); // Подготовка данных для графика @@ -755,7 +726,7 @@ chart{{ metricName|replace({'-': '_', '.': '_'}) }}.canvas.addEventListener('mou // Глобальный обработчик для скрытия тултипов при уходе курсора за пределы canvas document.addEventListener('mousemove', function(e) { {% 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_") %} +{% 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" %} (function() { var canvas = chart{{ metricName|replace({'-': '_', '.': '_'}) }}.canvas; var rect = canvas.getBoundingClientRect(); @@ -777,83 +748,6 @@ document.addEventListener('mousemove', function(e) { -// Графики сетевых интерфейсов (две линии: In зелёная, Out красная) -{% set net_interfaces = [] %} -{% for metricName in metrics|keys %} - {% if metricName starts with 'net_in_' %} - {% set net_interfaces = net_interfaces|merge([metricName|replace({'net_in_': ''})]) %} - {% endif %} -{% endfor %} - -{% for iface in net_interfaces %} -{% if metrics['net_in_' ~ iface] is defined and metrics['net_out_' ~ iface] is defined %} -(function() { - var ctx = document.getElementById('chart-net-{{ iface }}'); - if (!ctx) return; - - var labels = []; - var inData = []; - var outData = []; - -{% for m in metrics['net_in_' ~ iface]|slice(0, 500)|reverse %} - labels.push('{{ m.created_at|date("d.m H:i") }}'); - inData.push({{ m.value }}); -{% endfor %} - -{% set outMetrics = metrics['net_out_' ~ iface]|slice(0, 500)|reverse %} -{% for m in outMetrics %} - outData.push({{ m.value }}); -{% endfor %} - - new Chart(ctx.getContext('2d'), { - type: 'line', - data: { - labels: labels, - datasets: [ - { - label: 'Входящий (In)', - data: inData, - borderColor: 'rgba(25, 135, 84, 1)', - backgroundColor: 'rgba(25, 135, 84, 0.1)', - fill: true, - tension: 0.1, - pointRadius: 0, - borderWidth: 1.5 - }, - { - label: 'Исходящий (Out)', - data: outData, - borderColor: 'rgba(220, 53, 69, 1)', - backgroundColor: 'rgba(220, 53, 69, 0.1)', - fill: true, - tension: 0.1, - pointRadius: 0, - borderWidth: 1.5 - } - ] - }, - options: { - responsive: true, - maintainAspectRatio: false, - interaction: { mode: 'index', intersect: false }, - plugins: { - legend: { display: true, position: 'top' }, - tooltip: { enabled: true, mode: 'index', intersect: false }, - zoom: { - zoom: { wheel: { enabled: true }, pinch: { enabled: true }, mode: 'x' }, - pan: { enabled: true, mode: 'x' } - } - }, - scales: { - y: { beginAtZero: true, ticks: { callback: function(v) { return v + '%'; } } } - } - } - }); -})(); -{% endif %} -{% endfor %} - - // График температур {% set temp_metrics = [] %} {% for m in metrics %}{% if m starts with 'temp_' %}{% set temp_metrics = temp_metrics|merge([m]) %}{% endif %}{% endfor %} @@ -948,7 +842,7 @@ document.addEventListener('mousemove', function(e) { // Сбросить зум на всех графиках function resetAllZoom() { {% 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_") %} +{% 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" %} if (typeof chart{{ metricName|replace({'-': '_', '.': '_'}) }} !== 'undefined') { chart{{ metricName|replace({'-': '_', '.': '_'}) }}.resetZoom(); }