|
|
@@ -1,129 +1,1038 @@
|
|
|
-<section class="cache-stats">
|
|
|
-
|
|
|
- <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-10 max-w-[900px] mx-auto mt-10">
|
|
|
-
|
|
|
- <!-- Flip Card: Entradas almacenadas -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <!-- Front -->
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-database text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Entradas almacenadas</h3>
|
|
|
- <p class="text-xl text-blue-800">{{ cache_stats.store_entries }}</p>
|
|
|
+{% macro flip_card(icon, title, value, back_title, description, extra_html='') %}
|
|
|
+<div class="group w-full h-48 [perspective:1000px]">
|
|
|
+ <div
|
|
|
+ class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
+ <!-- Front -->
|
|
|
+ <div
|
|
|
+ class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
+ <i class="{{ icon }} text-3xl text-blue-600 mb-2"></i>
|
|
|
+ <h3 class="text-lg font-semibold text-gray-800">{{ title }}</h3>
|
|
|
+ {% if extra_html %}
|
|
|
+ {{ extra_html | safe }}
|
|
|
+ {% else %}
|
|
|
+ <p class="text-xl text-blue-800" data-stat="{{ title|replace(' ', '_')|lower }}">{{ value }}</p>
|
|
|
+ {% endif %}
|
|
|
+ </div>
|
|
|
+ <!-- Back -->
|
|
|
+ <div
|
|
|
+ class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
+ <h3 class="text-lg font-semibold mb-2">{{ back_title }}</h3>
|
|
|
+ <p class="text-sm">{{ description }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+</div>
|
|
|
+{% endmacro %}
|
|
|
+
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="es">
|
|
|
+
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Dashboard de Sistema</title>
|
|
|
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
|
+ <script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
|
|
|
+ <script src="https://cdn.socket.io/4.5.0/socket.io.min.js"></script>
|
|
|
+ <style>
|
|
|
+ /* Estilos base */
|
|
|
+ .circle {
|
|
|
+ stroke-linecap: round;
|
|
|
+ animation: progress 1s ease-out forwards;
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes progress {
|
|
|
+ 0% {
|
|
|
+ stroke-dasharray: 0 100;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .tab-btn {
|
|
|
+ transition: all 0.3s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ .tab-btn:hover {
|
|
|
+ background-color: #f1f5f9;
|
|
|
+ }
|
|
|
+
|
|
|
+ .cache-stats .group:hover .relative {
|
|
|
+ transform: rotateY(180deg);
|
|
|
+ }
|
|
|
+
|
|
|
+ .cache-stats .relative {
|
|
|
+ transition: transform 0.6s;
|
|
|
+ }
|
|
|
+
|
|
|
+ .cache-stats .absolute {
|
|
|
+ backface-visibility: hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ .main-tab-content {
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+
|
|
|
+ .main-tab-content.active {
|
|
|
+ display: block;
|
|
|
+ animation: fadeIn 0.5s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes fadeIn {
|
|
|
+ from {
|
|
|
+ opacity: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ to {
|
|
|
+ opacity: 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .main-tab-btn {
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+ }
|
|
|
+
|
|
|
+ .main-tab-btn.active::after {
|
|
|
+ content: '';
|
|
|
+ position: absolute;
|
|
|
+ bottom: 0;
|
|
|
+ left: 0;
|
|
|
+ right: 0;
|
|
|
+ height: 3px;
|
|
|
+ background-color: #3b82f6;
|
|
|
+ animation: underline 0.3s ease;
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes underline {
|
|
|
+ from {
|
|
|
+ transform: scaleX(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ to {
|
|
|
+ transform: scaleX(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Animación para cambios de valores */
|
|
|
+ .value-change {
|
|
|
+ animation: pulse 1s;
|
|
|
+ }
|
|
|
+
|
|
|
+ @keyframes pulse {
|
|
|
+ 0% {
|
|
|
+ transform: scale(1);
|
|
|
+ }
|
|
|
+
|
|
|
+ 50% {
|
|
|
+ transform: scale(1.1);
|
|
|
+ }
|
|
|
+
|
|
|
+ 100% {
|
|
|
+ transform: scale(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Estilos para textos dentro de los anillos */
|
|
|
+ .ring-percent {
|
|
|
+ text-anchor: middle;
|
|
|
+ dominant-baseline: central;
|
|
|
+ alignment-baseline: central;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Estilos para la gráfica de días */
|
|
|
+ .day-bar {
|
|
|
+ transition: all 0.5s ease;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+
|
|
|
+<body class="bg-gray-50">
|
|
|
+ <div class="max-w-7xl mx-auto px-4 py-8">
|
|
|
+ <h1 class="text-3xl font-bold text-center text-gray-800 mb-8">Dashboard de Estadísticas del Sistema</h1>
|
|
|
+
|
|
|
+ <!-- Pestañas principales -->
|
|
|
+ <div class="flex border-b mb-6">
|
|
|
+ <button id="dashboardTab" class="main-tab-btn active py-3 px-6 font-medium text-blue-600">
|
|
|
+ <i class="fas fa-tachometer-alt mr-2"></i>Dashboard del Sistema
|
|
|
+ </button>
|
|
|
+ <button id="cacheTab" class="main-tab-btn py-3 px-6 font-medium text-gray-500 hover:text-blue-600">
|
|
|
+ <i class="fas fa-database mr-2"></i>Estadísticas de Caché
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Contenido del Dashboard del Sistema (activo por defecto) -->
|
|
|
+ <div id="dashboardContent" class="main-tab-content active">
|
|
|
+ <!-- Sección de estadísticas e información del sistema -->
|
|
|
+ <section class="mb-12">
|
|
|
+ <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
|
|
|
+ <!-- Panel izquierdo: Estadísticas del sistema con anillos -->
|
|
|
+ <div class="bg-white rounded-xl shadow-lg p-6">
|
|
|
+ <div class="flex items-center mb-6">
|
|
|
+ <i class="fas fa-chart-pie text-2xl text-blue-600 mr-3"></i>
|
|
|
+ <h2 class="text-xl font-bold text-gray-800">Estadísticas del Sistema</h2>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Contenedor de anillos - Centrado verticalmente -->
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-6 items-center justify-center">
|
|
|
+ <!-- Anillo de Uso de CPU con información de núcleos -->
|
|
|
+ <div class="flex flex-col items-center justify-center">
|
|
|
+ <div class="relative w-36 h-36">
|
|
|
+ <svg viewBox="0 0 36 36" class="circular-chart block mx-auto">
|
|
|
+ <path class="circle-bg fill-none stroke-[#ffe5e5] stroke-[3.5]" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" />
|
|
|
+ <path id="cpu-ring" class="circle fill-none" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" fill="none" stroke="#ef4444" stroke-width="3.5"
|
|
|
+ stroke-dasharray="0,100" />
|
|
|
+ <!-- Texto centrado verticalmente -->
|
|
|
+ <text id="cpu-value" x="18" y="18"
|
|
|
+ class="ring-percent text-[0.5rem] fill-gray-500">0%</text>
|
|
|
+ </svg>
|
|
|
+ </div>
|
|
|
+ <h3 class="mt-2 font-semibold text-gray-700">CPU</h3>
|
|
|
+ <!-- Nueva etiqueta con información de núcleos del CPU - Color del anillo -->
|
|
|
+ <p
|
|
|
+ class="cores text-sm mt-1 bg-red-500 text-white px-2 py-0.5 rounded-full text-xs font-medium">
|
|
|
+ {{ system_info.cpu.physical_cores }} núcleos</p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Anillo de Uso de RAM con información de RAM total -->
|
|
|
+ <div class="flex flex-col items-center justify-center">
|
|
|
+ <div class="relative w-36 h-36">
|
|
|
+ <svg viewBox="0 0 36 36" class="circular-chart block mx-auto">
|
|
|
+ <path class="circle-bg fill-none stroke-[#dfedff] stroke-[3.5]" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" />
|
|
|
+ <path id="ram-ring" class="circle fill-none" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" fill="none" stroke="#3b82f6" stroke-width="3.5"
|
|
|
+ stroke-dasharray="0,100" />
|
|
|
+ <!-- Texto centrado verticalmente -->
|
|
|
+ <text id="ram-used" x="18" y="18"
|
|
|
+ class="ring-percent text-[0.5rem] fill-gray-500" text-anchor="middle"
|
|
|
+ dominant-baseline="middle">0G</text>
|
|
|
+ </svg>
|
|
|
+ </div>
|
|
|
+ <h3 class="mt-2 font-semibold text-gray-700">RAM</h3>
|
|
|
+ <!-- Nueva etiqueta con información de RAM total - Color del anillo -->
|
|
|
+ <p
|
|
|
+ class="ram text-sm mt-1 bg-blue-500 text-white px-2 py-0.5 rounded-full text-xs font-medium">
|
|
|
+ {{ system_info.ram.total }}</p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Anillo de Uso de Swap con información de swap total -->
|
|
|
+ <div class="flex flex-col items-center justify-center">
|
|
|
+ <div class="relative w-36 h-36">
|
|
|
+ <svg viewBox="0 0 36 36" class="circular-chart block mx-auto">
|
|
|
+ <path class="circle-bg fill-none stroke-[#d3f9e8] stroke-[3.5]" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" />
|
|
|
+ <path id="swap-ring" class="circle fill-none" d="M18 2.0845
|
|
|
+ a 15.9155 15.9155 0 0 1 0 31.831
|
|
|
+ a 15.9155 15.9155 0 0 1 0 -31.831" fill="none" stroke="#10b981"
|
|
|
+ stroke-width="3.5" stroke-dasharray="0,100" />
|
|
|
+ <text id="swap-used" x="18" y="18"
|
|
|
+ class="ring-percent text-[0.5rem] fill-gray-500" text-anchor="middle"
|
|
|
+ dominant-baseline="middle">0G</text>
|
|
|
+ </svg>
|
|
|
+ </div>
|
|
|
+ <h3 class="mt-2 font-semibold text-gray-700">SWAP</h3>
|
|
|
+ <!-- Nueva etiqueta con información de swap total - Color del anillo -->
|
|
|
+ <p
|
|
|
+ class="swap text-sm mt-1 bg-emerald-500 text-white px-2 py-0.5 rounded-full text-xs font-medium">
|
|
|
+ {{ system_info.swap.total }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- <!-- Back -->
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-xl font-bold mb-2">Entradas Almacenadas</h3>
|
|
|
- <p class="text-sm">Número de objetos actualmente en la caché de Squid.</p>
|
|
|
+
|
|
|
+ <!-- Panel derecho: Información del sistema -->
|
|
|
+ <div class="bg-white rounded-xl shadow-lg p-6">
|
|
|
+ <div class="flex items-center mb-6">
|
|
|
+ <i class="fas fa-info-circle text-2xl text-blue-600 mr-3"></i>
|
|
|
+ <h2 class="text-xl font-bold text-gray-800">Información del Sistema</h2>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fas fa-server text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Nombre del Host</h3>
|
|
|
+ <p id="hostname" class="text-gray-800">{{ system_info.hostname }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fas fa-network-wired text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Direcciones IP</h3>
|
|
|
+ <p id="ip-addresses" class="text-gray-800">
|
|
|
+ {% for ip in system_info.ips %}
|
|
|
+ {{ ip.ip }}<br>
|
|
|
+ {% endfor %}
|
|
|
+ </p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fab fa-linux text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Sistema Operativo</h3>
|
|
|
+ <p id="os-info" class="text-gray-800">{{ system_info.os }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fas fa-clock text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Tiempo Encendido</h3>
|
|
|
+ <p id="uptime" class="text-gray-800">{{ system_info.uptime }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Se eliminaron las secciones de memoria y swap como se solicitó -->
|
|
|
+ <!-- Esta información ahora está en los anillos con las nuevas etiquetas -->
|
|
|
+
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fas fa-globe text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Zona Horaria</h3>
|
|
|
+ <p id="timezone" class="text-gray-800">{{ system_info.timezone }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="flex items-start">
|
|
|
+ <i class="fas fa-clock text-gray-500 mt-1 mr-3"></i>
|
|
|
+ <div>
|
|
|
+ <h3 class="text-sm font-semibold text-gray-600">Hora Local</h3>
|
|
|
+ <p id="local-time" class="text-gray-800">{{ system_info.local_time }}</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- Flip Card: Uso de capacidad -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <!-- Front -->
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-chart-pie text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Uso de capacidad</h3>
|
|
|
- <p class="text-xl text-blue-800">{{ cache_stats.capacity_used }}%</p>
|
|
|
- </div>
|
|
|
- <!-- Back -->
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-lg font-semibold mb-2">Uso de capacidad</h3>
|
|
|
- <p class="text-sm">Porcentaje del almacenamiento de caché en uso actualmente.</p>
|
|
|
- </div>
|
|
|
+ </section>
|
|
|
+
|
|
|
+ <!-- Sección de gráficas con pestañas -->
|
|
|
+ <section class="bg-white rounded-xl shadow-lg p-6 mb-12">
|
|
|
+ <div class="flex border-b mb-6">
|
|
|
+ <button
|
|
|
+ class="tab-btn active py-3 px-6 font-medium border-b-2 border-blue-600 text-blue-600">CPU</button>
|
|
|
+ <button class="tab-btn py-3 px-6 font-medium text-gray-500 hover:text-blue-600">RAM</button>
|
|
|
+ <button class="tab-btn py-3 px-6 font-medium text-gray-500 hover:text-blue-600">SWAP</button>
|
|
|
</div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- Flip Card: Espacio total en disco -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-hdd text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Espacio total</h3>
|
|
|
- {% if (cache_stats.fs_space_total / 1024) < 1024 %} <p class="text-xl text-blue-800">{{
|
|
|
- (cache_stats.fs_space_total / 1024)|int }} MB</p>
|
|
|
- {% else %}
|
|
|
- <p class="text-xl text-blue-800">{{ (cache_stats.fs_space_total / 1024 / 1024)|round(2) }}
|
|
|
- GB</p>
|
|
|
- {% endif %}
|
|
|
- </div>
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-lg font-semibold mb-2">Espacio total</h3>
|
|
|
- <p class="text-sm">Tamaño total del disco asignado a la caché de Squid.</p>
|
|
|
+
|
|
|
+ <div class="tab-content active">
|
|
|
+ <div class="h-80">
|
|
|
+ <canvas id="cpuChart"></canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- Flip Card: Espacio usado en disco -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-folder-open text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Espacio usado</h3>
|
|
|
- {% if (cache_stats.fs_space_used / 1024) < 1024 %} <p class="text-xl text-blue-800">{{
|
|
|
- (cache_stats.fs_space_used / 1024 )|int }} MB</p>
|
|
|
- {% else %}
|
|
|
- <p class="text-xl text-blue-800">{{ (cache_stats.fs_space_used / 1024 / 1024 )|round(2) }}
|
|
|
- GB</p>
|
|
|
- {% endif %}
|
|
|
+
|
|
|
+ <div class="tab-content hidden">
|
|
|
+ <div class="h-80">
|
|
|
+ <canvas id="ramChart"></canvas>
|
|
|
</div>
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-lg font-semibold mb-2">Espacio usado</h3>
|
|
|
- <p class="text-sm">Cantidad de espacio de disco ya ocupado por objetos en caché.</p>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="tab-content hidden">
|
|
|
+ <div class="h-80">
|
|
|
+ <canvas id="swapChart"></canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- Flip Card: Política de eliminación -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-recycle text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Eliminación</h3>
|
|
|
- <p class="text-xl text-blue-800">{{ cache_stats.removal_policy }}</p>
|
|
|
+ </section>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- Contenido de Estadísticas de Caché (inicialmente oculto) -->
|
|
|
+ <div id="cacheContent" class="main-tab-content">
|
|
|
+ <section class="cache-stats">
|
|
|
+ <div class="bg-white rounded-xl shadow-lg p-6 mb-8">
|
|
|
+ <div class="flex items-center mb-6">
|
|
|
+ <i class="fas fa-database text-2xl text-blue-600 mr-3"></i>
|
|
|
+ <h2 class="text-2xl font-bold text-gray-800">Estadísticas de Caché</h2>
|
|
|
</div>
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-lg font-semibold mb-2">Política de eliminación</h3>
|
|
|
- <p class="text-sm">Método que Squid usa para eliminar objetos antiguos de la caché.</p>
|
|
|
+
|
|
|
+ <div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-8 max-w-[1000px] mx-auto">
|
|
|
+ <!-- Entradas almacenadas -->
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-database',
|
|
|
+ title='Entradas almacenadas',
|
|
|
+ value=cache_stats.store_entries,
|
|
|
+ back_title='Entradas Almacenadas',
|
|
|
+ description='Número de objetos actualmente en la caché de Squid.'
|
|
|
+ ) }}
|
|
|
+
|
|
|
+ <!-- Uso de capacidad -->
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-chart-pie',
|
|
|
+ title='Uso de capacidad',
|
|
|
+ value=cache_stats.capacity_used,
|
|
|
+ back_title='Uso de capacidad',
|
|
|
+ description='Porcentaje del almacenamiento de caché en uso actualmente.'
|
|
|
+ ) }}
|
|
|
+
|
|
|
+ <!-- Espacio total en disco -->
|
|
|
+ {% set total_space_html %}
|
|
|
+ {% if (cache_stats.fs_space_total / 1024) < 1024 %} <p class="text-xl text-blue-800"
|
|
|
+ data-stat="espacio_total">{{ (cache_stats.fs_space_total / 1024)|int }} MB</p>
|
|
|
+ {% else %}
|
|
|
+ <p class="text-xl text-blue-800" data-stat="espacio_total">{{ (cache_stats.fs_space_total /
|
|
|
+ 1024 / 1024)|round(2) }} GB</p>
|
|
|
+ {% endif %}
|
|
|
+ {% endset %}
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-hdd',
|
|
|
+ title='Espacio total',
|
|
|
+ back_title='Espacio total',
|
|
|
+ description='Tamaño total del disco asignado a la caché de Squid.',
|
|
|
+ extra_html=total_space_html
|
|
|
+ ) }}
|
|
|
+
|
|
|
+ <!-- Espacio usado en disco -->
|
|
|
+ {% set used_space_html %}
|
|
|
+ {% if (cache_stats.fs_space_used / 1024) < 1024 %} <p class="text-xl text-blue-800"
|
|
|
+ data-stat="espacio_usado">{{ (cache_stats.fs_space_used / 1024)|int }} MB</p>
|
|
|
+ {% else %}
|
|
|
+ <p class="text-xl text-blue-800" data-stat="espacio_usado">{{ (cache_stats.fs_space_used
|
|
|
+ / 1024 / 1024)|round(2) }} GB</p>
|
|
|
+ {% endif %}
|
|
|
+ {% endset %}
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-folder-open',
|
|
|
+ title='Espacio usado',
|
|
|
+ back_title='Espacio usado',
|
|
|
+ description='Cantidad de espacio de disco ya ocupado por objetos en caché.',
|
|
|
+ extra_html=used_space_html
|
|
|
+ ) }}
|
|
|
+
|
|
|
+ <!-- Política de eliminación -->
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-recycle',
|
|
|
+ title='Eliminación',
|
|
|
+ value=cache_stats.removal_policy,
|
|
|
+ back_title='Política de eliminación',
|
|
|
+ description='Método que Squid usa para eliminar objetos antiguos de la caché.'
|
|
|
+ ) }}
|
|
|
+
|
|
|
+ <!-- Edad LRU -->
|
|
|
+ {{ flip_card(
|
|
|
+ icon='fas fa-clock',
|
|
|
+ title='Edad LRU',
|
|
|
+ value=cache_stats.lru_age_days ~ ' días',
|
|
|
+ back_title='Edad LRU',
|
|
|
+ description='Tiempo desde que el objeto menos usado fue accedido por última vez.'
|
|
|
+ ) }}
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- Flip Card: Edad LRU -->
|
|
|
- <div class="group w-64 h-48 [perspective:1000px] mx-auto">
|
|
|
- <div
|
|
|
- class="relative h-full w-full rounded-xl shadow-xl transition-all duration-500 [transform-style:preserve-3d] group-hover:[transform:rotateY(180deg)]">
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-white shadow-md rounded-xl flex flex-col items-center justify-center [backface-visibility:hidden]">
|
|
|
- <i class="fas fa-clock text-3xl text-blue-600 mb-2"></i>
|
|
|
- <h3 class="text-lg font-semibold text-gray-800">Edad LRU</h3>
|
|
|
- <p class="text-xl text-blue-800">{{ cache_stats.lru_age_days }} días</p>
|
|
|
+
|
|
|
+ <!-- Gráfica de uso de caché por días -->
|
|
|
+ <div class="bg-white rounded-xl shadow-lg p-6">
|
|
|
+ <div class="flex items-center mb-6">
|
|
|
+ <i class="fas fa-chart-line text-2xl text-blue-600 mr-3"></i>
|
|
|
+ <h2 class="text-xl font-bold text-gray-800">Historial de Uso de Caché (Últimos 7 días)</h2>
|
|
|
</div>
|
|
|
- <div
|
|
|
- class="absolute inset-0 bg-blue-600 text-white rounded-xl px-4 py-6 text-center [transform:rotateY(180deg)] [backface-visibility:hidden]">
|
|
|
- <h3 class="text-lg font-semibold mb-2">Edad LRU</h3>
|
|
|
- <p class="text-sm">Tiempo desde que el objeto menos usado fue accedido por última vez.</p>
|
|
|
+
|
|
|
+ <div class="h-80">
|
|
|
+ <canvas id="cacheUsageChart"></canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ </section>
|
|
|
</div>
|
|
|
-
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <script>
|
|
|
+ // Registrar el plugin de datalabels
|
|
|
+ Chart.register(ChartDataLabels);
|
|
|
+
|
|
|
+ // Variables para almacenar datos en tiempo real
|
|
|
+ let systemDataHistory = {
|
|
|
+ cpu: [],
|
|
|
+ ram: [],
|
|
|
+ swap: [],
|
|
|
+ cache: []
|
|
|
+ };
|
|
|
+
|
|
|
+ // Variables para almacenar los valores máximos de RAM y Swap
|
|
|
+ let maxRamBytes = 0;
|
|
|
+ let maxSwapBytes = 0;
|
|
|
+
|
|
|
+ // Buffers para acumular datos cada 5 segundos
|
|
|
+ let cpuBuffer = [];
|
|
|
+ let ramBuffer = [];
|
|
|
+ let swapBuffer = [];
|
|
|
+
|
|
|
+ // Variables para almacenar datos por minuto
|
|
|
+ const historySize = 20; // 20 minutos de historial
|
|
|
+
|
|
|
+ // ==============================================
|
|
|
+ // CAMBIO 1: Inicializar datos con valores actuales
|
|
|
+ // ==============================================
|
|
|
+ let cpuMinuteData = [];
|
|
|
+ let ramMinuteData = [];
|
|
|
+ let swapMinuteData = [];
|
|
|
+ let minuteLabels = [];
|
|
|
+
|
|
|
+ // Función para cargar datos persistentes
|
|
|
+ function loadPersistentData() {
|
|
|
+ // Intentar cargar datos desde sessionStorage
|
|
|
+ const savedCpu = sessionStorage.getItem('cpuMinuteData');
|
|
|
+ const savedRam = sessionStorage.getItem('ramMinuteData');
|
|
|
+ const savedSwap = sessionStorage.getItem('swapMinuteData');
|
|
|
+ const savedLabels = sessionStorage.getItem('minuteLabels');
|
|
|
+
|
|
|
+ // Si hay datos guardados, usarlos
|
|
|
+ if (savedCpu && savedRam && savedSwap && savedLabels) {
|
|
|
+ cpuMinuteData = JSON.parse(savedCpu);
|
|
|
+ ramMinuteData = JSON.parse(savedRam);
|
|
|
+ swapMinuteData = JSON.parse(savedSwap);
|
|
|
+ minuteLabels = JSON.parse(savedLabels);
|
|
|
+
|
|
|
+ // Convertir todas las etiquetas al nuevo formato
|
|
|
+ minuteLabels = minuteLabels.map(label => {
|
|
|
+ // Si ya está en formato 12h, mantenerlo
|
|
|
+ if (label.includes('AM') || label.includes('PM')) return label;
|
|
|
+
|
|
|
+ // Convertir formato 24h existente
|
|
|
+ const [hora, minuto] = label.split(':');
|
|
|
+ const horaNum = parseInt(hora, 10);
|
|
|
+ const ampm = horaNum >= 12 ? 'PM' : 'AM';
|
|
|
+ const hora12 = horaNum % 12 || 12;
|
|
|
+ return `${hora12}:${minuto} ${ampm}`;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ initializeWithCurrentValues();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para inicializar con valores actuales
|
|
|
+ function initializeWithCurrentValues() {
|
|
|
+ // Obtener valores actuales del sistema
|
|
|
+ const initialCpu = parseFloat("{{ system_info.cpu.usage|replace('%','') }}");
|
|
|
+ const initialRam = sizeToBytes("{{ system_info.ram.used }}");
|
|
|
+ const initialSwap = sizeToBytes("{{ system_info.swap.used }}");
|
|
|
+
|
|
|
+ // Crear arrays con valores actuales
|
|
|
+ cpuMinuteData = Array(historySize).fill(initialCpu);
|
|
|
+ ramMinuteData = Array(historySize).fill(initialRam);
|
|
|
+ swapMinuteData = Array(historySize).fill(initialSwap);
|
|
|
+
|
|
|
+ // Inicializar etiquetas de tiempo
|
|
|
+ initializeMinuteLabels();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para inicializar etiquetas de tiempo
|
|
|
+ function initializeMinuteLabels() {
|
|
|
+ const now = new Date();
|
|
|
+ minuteLabels = [];
|
|
|
+
|
|
|
+ for (let i = historySize - 1; i >= 0; i--) {
|
|
|
+ const time = new Date(now.getTime() - i * 60000);
|
|
|
+ minuteLabels.push(formatTime(time));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Cargar datos persistentes al iniciar
|
|
|
+ loadPersistentData();
|
|
|
+
|
|
|
+ // Función para guardar datos persistentes
|
|
|
+ function savePersistentData() {
|
|
|
+ sessionStorage.setItem('cpuMinuteData', JSON.stringify(cpuMinuteData));
|
|
|
+ sessionStorage.setItem('ramMinuteData', JSON.stringify(ramMinuteData));
|
|
|
+ sessionStorage.setItem('swapMinuteData', JSON.stringify(swapMinuteData));
|
|
|
+ sessionStorage.setItem('minuteLabels', JSON.stringify(minuteLabels));
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para formatear hora HH:MM
|
|
|
+ function formatTime(date) {
|
|
|
+ let hours = date.getHours();
|
|
|
+ const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
+ const ampm = hours >= 12 ? 'PM' : 'AM';
|
|
|
+ hours = hours % 12 || 12; // Convertir 0 a 12
|
|
|
+ return `${hours}:${minutes} ${ampm}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para manejar las pestañas principales
|
|
|
+ function openMainTab(tabName) {
|
|
|
+ // Ocultar todos los contenidos de pestañas
|
|
|
+ document.querySelectorAll('.main-tab-content').forEach(content => {
|
|
|
+ content.classList.remove('active');
|
|
|
+ });
|
|
|
+
|
|
|
+ // Remover clase activa de todos los botones
|
|
|
+ document.querySelectorAll('.main-tab-btn').forEach(btn => {
|
|
|
+ btn.classList.remove('active', 'text-blue-600');
|
|
|
+ btn.classList.add('text-gray-500');
|
|
|
+ });
|
|
|
+
|
|
|
+ // Mostrar la pestaña seleccionada
|
|
|
+ document.getElementById(tabName + 'Content').classList.add('active');
|
|
|
+
|
|
|
+ // Activar el botón de la pestaña seleccionada
|
|
|
+ const tabBtn = document.getElementById(tabName + 'Tab');
|
|
|
+ tabBtn.classList.add('active', 'text-blue-600');
|
|
|
+ tabBtn.classList.remove('text-gray-500');
|
|
|
+ }
|
|
|
+
|
|
|
+ // Configurar eventos para las pestañas principales
|
|
|
+ document.getElementById('dashboardTab').addEventListener('click', () => openMainTab('dashboard'));
|
|
|
+ document.getElementById('cacheTab').addEventListener('click', () => openMainTab('cache'));
|
|
|
+
|
|
|
+ // Función para manejar las pestañas internas
|
|
|
+ document.querySelectorAll('.tab-btn').forEach(button => {
|
|
|
+ button.addEventListener('click', () => {
|
|
|
+ // Remover clase activa de todos los botones
|
|
|
+ document.querySelectorAll('.tab-btn').forEach(btn => {
|
|
|
+ btn.classList.remove('active', 'text-blue-600', 'border-b-2', 'border-blue-600');
|
|
|
+ btn.classList.add('text-gray-500');
|
|
|
+ });
|
|
|
+
|
|
|
+ // Agregar clase activa al botón clickeado
|
|
|
+ button.classList.add('active', 'text-blue-600', 'border-b-2', 'border-blue-600');
|
|
|
+ button.classList.remove('text-gray-500');
|
|
|
+
|
|
|
+ // Ocultar todos los contenidos de pestañas
|
|
|
+ document.querySelectorAll('.tab-content').forEach(content => {
|
|
|
+ content.classList.add('hidden');
|
|
|
+ content.classList.remove('active');
|
|
|
+ });
|
|
|
+
|
|
|
+ // Mostrar el contenido correspondiente
|
|
|
+ const tabIndex = Array.from(document.querySelectorAll('.tab-btn')).indexOf(button);
|
|
|
+ document.querySelectorAll('.tab-content')[tabIndex].classList.remove('hidden');
|
|
|
+ document.querySelectorAll('.tab-content')[tabIndex].classList.add('active');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ // Función para formatear tamaños
|
|
|
+ function formatSizeCompact(bytes) {
|
|
|
+ const units = ['B', 'KB', 'MB', 'GB'];
|
|
|
+ let unitIndex = 0;
|
|
|
+
|
|
|
+ while (bytes >= 1024 && unitIndex < units.length - 1) {
|
|
|
+ bytes /= 1024;
|
|
|
+ unitIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+ return unitIndex === 0
|
|
|
+ ? `${bytes} ${units[unitIndex]}`
|
|
|
+ : `${bytes.toFixed(1)} ${units[unitIndex]}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Configuración de gráficos con Chart.js y datalabels
|
|
|
+ const cpuCtx = document.getElementById('cpuChart').getContext('2d');
|
|
|
+ const cpuChart = new Chart(cpuCtx, {
|
|
|
+ type: 'line',
|
|
|
+ data: {
|
|
|
+ labels: minuteLabels,
|
|
|
+ datasets: [{
|
|
|
+ label: 'Uso de CPU (%)',
|
|
|
+ data: cpuMinuteData,
|
|
|
+ borderColor: '#ef4444',
|
|
|
+ backgroundColor: 'rgba(239, 68, 68, 0.1)',
|
|
|
+ tension: 0.3,
|
|
|
+ fill: true,
|
|
|
+ pointRadius: 4,
|
|
|
+ pointBackgroundColor: '#ef4444'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ responsive: true,
|
|
|
+ maintainAspectRatio: false,
|
|
|
+ scales: {
|
|
|
+ y: {
|
|
|
+ beginAtZero: true,
|
|
|
+ max: 100,
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: 'Porcentaje (%)'
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ },
|
|
|
+ ticks: {
|
|
|
+ callback: function (value) {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ x: {
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins: {
|
|
|
+ legend: {
|
|
|
+ display: true
|
|
|
+ },
|
|
|
+ datalabels: {
|
|
|
+ display: false
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const ramCtx = document.getElementById('ramChart').getContext('2d');
|
|
|
+ const ramChart = new Chart(ramCtx, {
|
|
|
+ type: 'line',
|
|
|
+ data: {
|
|
|
+ labels: minuteLabels,
|
|
|
+ datasets: [{
|
|
|
+ label: 'RAM Usada',
|
|
|
+ data: ramMinuteData,
|
|
|
+ borderColor: '#3b82f6',
|
|
|
+ backgroundColor: 'rgba(59, 130, 246, 0.1)',
|
|
|
+ tension: 0.3,
|
|
|
+ fill: true,
|
|
|
+ pointRadius: 4,
|
|
|
+ pointBackgroundColor: '#3b82f6'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ responsive: true,
|
|
|
+ maintainAspectRatio: false,
|
|
|
+ scales: {
|
|
|
+ y: {
|
|
|
+ beginAtZero: true,
|
|
|
+ max: maxRamBytes,
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: 'Bytes'
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ },
|
|
|
+ ticks: {
|
|
|
+ callback: function (value) {
|
|
|
+ return formatSizeCompact(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ x: {
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins: {
|
|
|
+ legend: {
|
|
|
+ display: true
|
|
|
+ },
|
|
|
+ datalabels: {
|
|
|
+ display: false
|
|
|
+ },
|
|
|
+ tooltip: {
|
|
|
+ callbacks: {
|
|
|
+ label: function (context) {
|
|
|
+ return 'RAM Usada: ' + formatSizeCompact(context.raw)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const swapCtx = document.getElementById('swapChart').getContext('2d');
|
|
|
+ const swapChart = new Chart(swapCtx, {
|
|
|
+ type: 'line',
|
|
|
+ data: {
|
|
|
+ labels: minuteLabels,
|
|
|
+ datasets: [{
|
|
|
+ label: 'Swap Usada',
|
|
|
+ data: swapMinuteData,
|
|
|
+ borderColor: '#10b981',
|
|
|
+ backgroundColor: 'rgba(16, 185, 129, 0.1)',
|
|
|
+ tension: 0.3,
|
|
|
+ fill: true,
|
|
|
+ pointRadius: 4,
|
|
|
+ pointBackgroundColor: '#10b981'
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ responsive: true,
|
|
|
+ maintainAspectRatio: false,
|
|
|
+ scales: {
|
|
|
+ y: {
|
|
|
+ beginAtZero: true,
|
|
|
+ max: maxSwapBytes,
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: 'Bytes'
|
|
|
+ },
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ },
|
|
|
+ ticks: {
|
|
|
+ callback: function (value) {
|
|
|
+ return formatSizeCompact(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ x: {
|
|
|
+ grid: {
|
|
|
+ color: 'rgba(0, 0, 0, 0.05)'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins: {
|
|
|
+ legend: {
|
|
|
+ display: true
|
|
|
+ },
|
|
|
+ datalabels: {
|
|
|
+ display: false
|
|
|
+ },
|
|
|
+ tooltip: {
|
|
|
+ callbacks: {
|
|
|
+ label: function (context) {
|
|
|
+ return 'SWAP Usada: ' + formatSizeCompact(context.raw)
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Inicializar valores máximos con datos del backend
|
|
|
+ maxRamBytes = sizeToBytes("{{ system_info.ram.total }}");
|
|
|
+ maxSwapBytes = sizeToBytes("{{ system_info.swap.total }}");
|
|
|
+
|
|
|
+ // Actualizar gráficas con valores iniciales
|
|
|
+ ramChart.options.scales.y.max = maxRamBytes;
|
|
|
+ swapChart.options.scales.y.max = maxSwapBytes;
|
|
|
+ cpuChart.update();
|
|
|
+ ramChart.update();
|
|
|
+ swapChart.update();
|
|
|
+
|
|
|
+ // Función para extraer valor y unidad de un string de tamaño
|
|
|
+ function parseSize(sizeStr) {
|
|
|
+ if (!sizeStr) return { value: 0, unit: 'B' };
|
|
|
+ const parts = sizeStr.split(' ');
|
|
|
+ if (parts.length < 2) return { value: parseFloat(sizeStr) || 0, unit: 'B' };
|
|
|
+ return {
|
|
|
+ value: parseFloat(parts[0]),
|
|
|
+ unit: parts[1].charAt(0) // 'G', 'M', 'K'
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para convertir tamaño a bytes
|
|
|
+ function sizeToBytes(sizeStr) {
|
|
|
+ const { value, unit } = parseSize(sizeStr);
|
|
|
+ let multiplier = 1;
|
|
|
+ if (unit === 'G') {
|
|
|
+ multiplier = 1024 * 1024 * 1024;
|
|
|
+ } else if (unit === 'M') {
|
|
|
+ multiplier = 1024 * 1024;
|
|
|
+ } else if (unit === 'K') {
|
|
|
+ multiplier = 1024;
|
|
|
+ }
|
|
|
+ return value * multiplier;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para actualizar anillos con información adicional
|
|
|
+ function updateRings(systemInfo) {
|
|
|
+ // Actualizar anillo de CPU
|
|
|
+ const cpuPercent = parseFloat(systemInfo.cpu.usage.replace('%', ''));
|
|
|
+ document.getElementById('cpu-ring').setAttribute('stroke-dasharray', `${cpuPercent},100`);
|
|
|
+ document.getElementById('cpu-value').textContent = `${cpuPercent}%`;
|
|
|
+
|
|
|
+ // Obtener valores de RAM
|
|
|
+ const ramUsedInfo = parseSize(systemInfo.ram.used);
|
|
|
+ const ramUsedCompact = ramUsedInfo.value + ramUsedInfo.unit;
|
|
|
+ const ramPercent = parseFloat(systemInfo.ram.percent.replace('%', ''));
|
|
|
+
|
|
|
+ // Actualizar anillo de RAM
|
|
|
+ document.getElementById('ram-ring').setAttribute('stroke-dasharray', `${ramPercent},100`);
|
|
|
+
|
|
|
+ // Actualizar texto centrado con RAM usada
|
|
|
+ document.getElementById('ram-used').textContent = ramUsedCompact;
|
|
|
+
|
|
|
+ // Actualizar anillo de SWAP
|
|
|
+ const swapPercent = parseFloat(systemInfo.swap.percent.replace('%', '') || '0');
|
|
|
+ document.getElementById('swap-ring').setAttribute('stroke-dasharray', `${swapPercent},100`);
|
|
|
+
|
|
|
+ // Obtener valores de SWAP
|
|
|
+ const swapUsedInfo = parseSize(systemInfo.swap.used);
|
|
|
+ const swapUsedCompact = swapUsedInfo.value + swapUsedInfo.unit;
|
|
|
+
|
|
|
+ // Actualizar texto centrado con SWAP usada
|
|
|
+ document.getElementById('swap-used').textContent = swapUsedCompact;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para actualizar la información del sistema
|
|
|
+ function updateSystemInfo(systemInfo) {
|
|
|
+ // Actualizar hostname
|
|
|
+ document.getElementById('hostname').textContent = systemInfo.hostname;
|
|
|
+
|
|
|
+ // Actualizar IPs
|
|
|
+ const ipList = systemInfo.ips.map(ip => ip.ip).join('<br>');
|
|
|
+ document.getElementById('ip-addresses').innerHTML = ipList;
|
|
|
+
|
|
|
+ // Actualizar OS
|
|
|
+ document.getElementById('os-info').textContent = systemInfo.os;
|
|
|
+
|
|
|
+ // Actualizar uptime
|
|
|
+ document.getElementById('uptime').textContent = systemInfo.uptime;
|
|
|
+
|
|
|
+ // Actualizar hora local
|
|
|
+ document.getElementById('local-time').textContent = formatTime(new Date());
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para actualizar las flip cards
|
|
|
+ function updateCacheStats(cacheStats) {
|
|
|
+ // Entradas almacenadas
|
|
|
+ updateCard('entradas_almacenadas', cacheStats.store_entries);
|
|
|
+
|
|
|
+ // Uso de capacidad
|
|
|
+ updateCard('uso_de_capacidad', cacheStats.capacity_used);
|
|
|
+
|
|
|
+ // Espacio total
|
|
|
+ updateCard('espacio_total', cacheStats.fs_space_total, true);
|
|
|
+
|
|
|
+ // Espacio usado
|
|
|
+ updateCard('espacio_usado', cacheStats.fs_space_used, true);
|
|
|
+
|
|
|
+ // Política de eliminación
|
|
|
+ updateCard('eliminación', cacheStats.removal_policy);
|
|
|
+
|
|
|
+ // Edad LRU
|
|
|
+ updateCard('edad_lru', `${cacheStats.lru_age_days} días`);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Función para actualizar una tarjeta específica
|
|
|
+ function updateCard(statId, value, isSize = false) {
|
|
|
+ const elements = document.querySelectorAll(`[data-stat="${statId}"]`);
|
|
|
+
|
|
|
+ if (elements.length === 0) return;
|
|
|
+
|
|
|
+ elements.forEach(element => {
|
|
|
+ const currentValue = element.textContent;
|
|
|
+
|
|
|
+ // Solo actualizar si el valor cambió
|
|
|
+ if (currentValue !== value.toString()) {
|
|
|
+ // Aplicar animación de cambio
|
|
|
+ element.classList.add('value-change');
|
|
|
+
|
|
|
+ // Actualizar el valor
|
|
|
+ if (isSize) {
|
|
|
+ // Convertir bytes a MB o GB
|
|
|
+ const bytes = parseFloat(value);
|
|
|
+ if (bytes / (1024 * 1024) < 1) {
|
|
|
+ element.textContent = `${Math.round(bytes / 1024)} MB`;
|
|
|
+ } else {
|
|
|
+ element.textContent = `${(bytes / (1024 * 1024)).toFixed(2)} GB`;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ element.textContent = value;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Quitar la clase de animación después de completarse
|
|
|
+ setTimeout(() => {
|
|
|
+ element.classList.remove('value-change');
|
|
|
+ }, 1000);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // ==============================================
|
|
|
+ // CAMBIO 2: Función para agregar datos minuto a minuto
|
|
|
+ // con persistencia entre recargas
|
|
|
+ // ==============================================
|
|
|
+ function addMinuteData(cpu, ram, swap) {
|
|
|
+ // Desplazar todos los datos hacia la izquierda
|
|
|
+ cpuMinuteData.shift();
|
|
|
+ ramMinuteData.shift();
|
|
|
+ swapMinuteData.shift();
|
|
|
+
|
|
|
+ // Agregar nuevos datos al final
|
|
|
+ cpuMinuteData.push(cpu);
|
|
|
+ ramMinuteData.push(ram);
|
|
|
+ swapMinuteData.push(swap);
|
|
|
+
|
|
|
+ // Actualizar etiquetas: desplazar y agregar nueva hora
|
|
|
+ minuteLabels.shift();
|
|
|
+ const now = new Date();
|
|
|
+ minuteLabels.push(formatTime(new Date()));
|
|
|
+
|
|
|
+ // Actualizar gráficas
|
|
|
+ cpuChart.data.labels = [...minuteLabels];
|
|
|
+ cpuChart.data.datasets[0].data = [...cpuMinuteData];
|
|
|
+
|
|
|
+ ramChart.data.labels = [...minuteLabels];
|
|
|
+ ramChart.data.datasets[0].data = [...ramMinuteData];
|
|
|
+
|
|
|
+ swapChart.data.labels = [...minuteLabels];
|
|
|
+ swapChart.data.datasets[0].data = [...swapMinuteData];
|
|
|
+
|
|
|
+ cpuChart.update();
|
|
|
+ ramChart.update();
|
|
|
+ swapChart.update();
|
|
|
+
|
|
|
+ // Guardar datos persistentes
|
|
|
+ savePersistentData();
|
|
|
+ }
|
|
|
+
|
|
|
+ // Conectar a WebSocket
|
|
|
+ const socket = io();
|
|
|
+
|
|
|
+ // Manejar actualizaciones del sistema
|
|
|
+ socket.on('system_update', function (data) {
|
|
|
+ // Actualizar anillos con información adicional
|
|
|
+ updateRings(data.system_info);
|
|
|
+
|
|
|
+ // Actualizar información del sistema
|
|
|
+ updateSystemInfo(data.system_info);
|
|
|
+
|
|
|
+ // Actualizar estadísticas de caché
|
|
|
+ updateCacheStats(data.cache_stats);
|
|
|
+
|
|
|
+ // Obtener datos actuales
|
|
|
+ const cpuValue = parseFloat(data.system_info.cpu.usage.replace('%', ''));
|
|
|
+ const ramValue = sizeToBytes(data.system_info.ram.used);
|
|
|
+ const swapValue = sizeToBytes(data.system_info.swap.used);
|
|
|
+
|
|
|
+ // Agregar datos a los buffers
|
|
|
+ cpuBuffer.push(cpuValue);
|
|
|
+ ramBuffer.push(ramValue);
|
|
|
+ swapBuffer.push(swapValue);
|
|
|
+
|
|
|
+ // Cada 12 datos (60 segundos / 5 segundos) = 1 minuto
|
|
|
+ if (cpuBuffer.length >= 12) {
|
|
|
+ // Calcular promedio para CPU
|
|
|
+ const cpuAvg = cpuBuffer.reduce((a, b) => a + b, 0) / cpuBuffer.length;
|
|
|
+
|
|
|
+ // Tomar el último valor para RAM y SWAP
|
|
|
+ const ramLast = ramBuffer[ramBuffer.length - 1];
|
|
|
+ const swapLast = swapBuffer[swapBuffer.length - 1];
|
|
|
+
|
|
|
+ // Agregar datos a las gráficas minuto a minuto
|
|
|
+ addMinuteData(cpuAvg, ramLast, swapLast);
|
|
|
+
|
|
|
+ // Reiniciar buffers
|
|
|
+ cpuBuffer = [];
|
|
|
+ ramBuffer = [];
|
|
|
+ swapBuffer = [];
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // Actualizar anillos con datos actuales
|
|
|
+ updateRings({
|
|
|
+ cpu: {
|
|
|
+ usage: "{{ system_info.cpu.usage }}",
|
|
|
+ physical_cores: "{{ system_info.cpu.physical_cores }}",
|
|
|
+ current_freq: "{{ system_info.cpu.current_freq }}"
|
|
|
+ },
|
|
|
+ ram: {
|
|
|
+ percent: "{{ system_info.ram.percent }}",
|
|
|
+ used: "{{ system_info.ram.used }}",
|
|
|
+ total: "{{ system_info.ram.total }}"
|
|
|
+ },
|
|
|
+ swap: {
|
|
|
+ percent: "{{ system_info.swap.percent }}",
|
|
|
+ used: "{{ system_info.swap.used }}",
|
|
|
+ total: "{{ system_info.swap.total }}"
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
|
|
|
-</section>
|
|
|
+</html>
|