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
This commit is contained in:
mirivlad 2026-04-14 01:52:03 +08:00
parent de34962360
commit dbd71e3485
2 changed files with 28 additions and 110 deletions

View File

@ -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'];

View File

@ -123,7 +123,7 @@
<div class="row">
{% 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" %}
<div class="col-12 mb-4">
<div class="card">
<div class="card-header">
@ -160,35 +160,6 @@
</div>
{% endif %}
</div>
<!-- Графики сетевых интерфейсов -->
{% 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 %}
<div class="row">
<div class="col-12 mb-4">
<div class="card">
<div class="card-header">
<h6 class="mb-0"><i class="fas fa-network-wired"></i> Сеть: {{ iface }}</h6>
</div>
<div class="card-body">
<canvas id="chart-net-{{ iface }}" width="100%" height="200"></canvas>
</div>
</div>
</div>
</div>
{% 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();
}