|
|
@@ -2,7 +2,6 @@
|
|
|
<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>
|
|
|
@@ -13,7 +12,6 @@
|
|
|
<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>
|
|
|
@@ -30,117 +28,25 @@
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>Dashboard de Sistema</title>
|
|
|
+ <link rel="icon" href="{{ url_for('static', filename=page_icon) }}" type="image/x-icon">
|
|
|
+ <script src="https://cdn.tailwindcss.com"></script>
|
|
|
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
|
|
<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;
|
|
|
- }
|
|
|
-
|
|
|
+ @keyframes progress { 0% { stroke-dasharray: 0 100; } }
|
|
|
+ .circle-animation { animation: progress 1s ease-out forwards; }
|
|
|
+ .main-tab-content, .tab-content { display: none; }
|
|
|
+ .main-tab-content.active, .tab-content.active { display: block; animation: fadeIn 0.5s ease; }
|
|
|
+ @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
|
|
|
.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;
|
|
|
+ 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); } }
|
|
|
+ .value-change { animation: pulse 1s; }
|
|
|
+ @keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
|
|
|
</style>
|
|
|
</head>
|
|
|
|
|
|
@@ -148,211 +54,92 @@
|
|
|
<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">
|
|
|
+ <button id="dashboardTab" class="main-tab-btn active relative overflow-hidden 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">
|
|
|
+ <button id="cacheTab" class="main-tab-btn relative overflow-hidden 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>
|
|
|
+ <button id="networkTab" class="main-tab-btn relative overflow-hidden py-3 px-6 font-medium text-gray-500 hover:text-blue-600">
|
|
|
+ <i class="fas fa-network-wired mr-2"></i>Tráfico de Red
|
|
|
+ </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 viewBox="0 0 36 36" class="block mx-auto">
|
|
|
+ <path class="fill-none stroke-red-100 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-animation fill-none stroke-linecap-round stroke-red-500 stroke-[3.5]" stroke-dasharray="0,100" 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" />
|
|
|
+ <text id="cpu-value" x="18" y="18" class="text-[0.5rem] fill-gray-500" text-anchor="middle" dominant-baseline="middle">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-xs mt-1 bg-red-500 text-white px-2 py-0.5 rounded-full font-medium">
|
|
|
- {{ system_info.cpu.physical_cores }} núcleos</p>
|
|
|
+ <p class="text-xs mt-1 bg-red-500 text-white px-2 py-0.5 rounded-full 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 viewBox="0 0 36 36" class="block mx-auto">
|
|
|
+ <path class="fill-none stroke-blue-100 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-animation fill-none stroke-linecap-round stroke-blue-600 stroke-[3.5]" stroke-dasharray="0,100" 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" />
|
|
|
+ <text id="ram-used" x="18" y="18" class="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-xs mt-1 bg-blue-500 text-white px-2 py-0.5 rounded-full font-medium">
|
|
|
- {{ system_info.ram.total }}</p>
|
|
|
+ <p class="text-xs mt-1 bg-blue-500 text-white px-2 py-0.5 rounded-full 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 viewBox="0 0 36 36" class="block mx-auto">
|
|
|
+ <path class="fill-none stroke-emerald-100 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-animation fill-none stroke-linecap-round stroke-emerald-500 stroke-[3.5]" stroke-dasharray="0,100" 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" />
|
|
|
+ <text id="swap-used" x="18" y="18" class="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-xs mt-1 bg-emerald-500 text-white px-2 py-0.5 rounded-full font-medium">
|
|
|
- {{ system_info.swap.total }}</p>
|
|
|
+ <p class="text-xs mt-1 bg-emerald-500 text-white px-2 py-0.5 rounded-full font-medium">{{ system_info.swap.total }}</p>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 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 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>
|
|
|
+ <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>
|
|
|
</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 class="tab-content active">
|
|
|
- <div class="h-80">
|
|
|
- <canvas id="cpuChart"></canvas>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div class="tab-content hidden">
|
|
|
- <div class="h-80">
|
|
|
- <canvas id="ramChart"></canvas>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div class="tab-content hidden">
|
|
|
- <div class="h-80">
|
|
|
- <canvas id="swapChart"></canvas>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </section>
|
|
|
-
|
|
|
- <!-- Sección de gráfica de red (ancho de banda) -->
|
|
|
- <section class="bg-white rounded-xl shadow-lg p-6 mb-12">
|
|
|
- <div class="flex items-center mb-6">
|
|
|
- <i class="fas fa-network-chart text-2xl text-blue-600 mr-3"></i>
|
|
|
- <h2 class="text-xl font-bold text-gray-800">Estadísticas de Ancho de Banda</h2>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div class="h-80">
|
|
|
- <canvas id="networkChart"></canvas>
|
|
|
+ <button class="tab-btn active py-3 px-6 font-medium border-b-2 border-blue-600 text-blue-600 transition-all duration-300 ease-in-out hover:bg-slate-100">CPU</button>
|
|
|
+ <button class="tab-btn py-3 px-6 font-medium text-gray-500 hover:text-blue-600 transition-all duration-300 ease-in-out hover:bg-slate-100">RAM</button>
|
|
|
+ <button class="tab-btn py-3 px-6 font-medium text-gray-500 hover:text-blue-600 transition-all duration-300 ease-in-out hover:bg-slate-100">SWAP</button>
|
|
|
</div>
|
|
|
+ <div class="tab-content active"><div class="h-80"><canvas id="cpuChart"></canvas></div></div>
|
|
|
+ <div class="tab-content"><div class="h-80"><canvas id="ramChart"></canvas></div></div>
|
|
|
+ <div class="tab-content"><div class="h-80"><canvas id="swapChart"></canvas></div></div>
|
|
|
</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">
|
|
|
@@ -360,144 +147,41 @@
|
|
|
<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="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.'
|
|
|
- ) }}
|
|
|
+ {{ 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.') }}
|
|
|
+ {{ 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.') }}
|
|
|
+ {% if cache_stats.fs_space_total and cache_stats.fs_space_total > 0 %}
|
|
|
+ {% 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) }}
|
|
|
+ {% else %}
|
|
|
+ {{ 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='<p class="text-xl text-red-600">No disponible</p>') }}
|
|
|
+ {% endif %}
|
|
|
+ {% 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) }}
|
|
|
+ {{ 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é.') }}
|
|
|
+ {{ 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>
|
|
|
+ </section>
|
|
|
+ </div>
|
|
|
|
|
|
- <!-- 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="h-80">
|
|
|
- <canvas id="cacheUsageChart"></canvas>
|
|
|
- </div>
|
|
|
+ <div id="networkContent" class="main-tab-content">
|
|
|
+ <section class="bg-white rounded-xl shadow-lg p-6">
|
|
|
+ <div class="flex items-center mb-6">
|
|
|
+ <i class="fas fa-network-wired text-2xl text-blue-600 mr-3"></i>
|
|
|
+ <h2 class="text-xl font-bold text-gray-800">Tráfico de Red</h2>
|
|
|
</div>
|
|
|
+ <div class="h-80"><canvas id="networkChart"></canvas></div>
|
|
|
</section>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<script>
|
|
|
- // Registrar el plugin de datalabels
|
|
|
Chart.register(ChartDataLabels);
|
|
|
|
|
|
- // Variables globales optimizadas
|
|
|
- let systemDataHistory = { cpu: [], ram: [], swap: [], cache: [], network_up: [], network_down: [] };
|
|
|
let maxRamBytes = 0, maxSwapBytes = 0;
|
|
|
- let cpuBuffer = [], ramBuffer = [], swapBuffer = [], netUpBuffer = [], netDownBuffer = [];
|
|
|
- const historySize = 20;
|
|
|
- let minuteLabels = [], cpuMinuteData = [], ramMinuteData = [], swapMinuteData = [], networkUpMinuteData = [], networkDownMinuteData = [];
|
|
|
-
|
|
|
- // Utilidades de persistencia optimizadas
|
|
|
- const storage = {
|
|
|
- get: (key, fallback) => {
|
|
|
- const val = sessionStorage.getItem(key);
|
|
|
- return val ? JSON.parse(val) : fallback;
|
|
|
- },
|
|
|
- set: (key, arr) => sessionStorage.setItem(key, JSON.stringify(arr)),
|
|
|
- setAll: () => {
|
|
|
- ['cpuMinuteData', 'ramMinuteData', 'swapMinuteData', 'networkUpMinuteData', 'networkDownMinuteData', 'minuteLabels']
|
|
|
- .forEach(key => storage.set(key, eval(key)));
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- // Inicialización optimizada
|
|
|
- function initializeData() {
|
|
|
- const initialCpu = parseFloat("{{ system_info.cpu.usage|replace('%','') }}");
|
|
|
- const initialRam = sizeToBytes("{{ system_info.ram.used }}");
|
|
|
- const initialSwap = sizeToBytes("{{ system_info.swap.used }}");
|
|
|
- const initialNetUp = parseFloat("{{ network_stats.up_mbps|default('0') }}");
|
|
|
- const initialNetDown = parseFloat("{{ network_stats.down_mbps|default('0') }}");
|
|
|
-
|
|
|
- cpuMinuteData = storage.get('cpuMinuteData', Array(historySize).fill(initialCpu));
|
|
|
- ramMinuteData = storage.get('ramMinuteData', Array(historySize).fill(initialRam));
|
|
|
- swapMinuteData = storage.get('swapMinuteData', Array(historySize).fill(initialSwap));
|
|
|
- networkUpMinuteData = storage.get('networkUpMinuteData', Array(historySize).fill(initialNetUp));
|
|
|
- networkDownMinuteData = storage.get('networkDownMinuteData', Array(historySize).fill(initialNetDown));
|
|
|
-
|
|
|
- minuteLabels = storage.get('minuteLabels', (() => {
|
|
|
- const now = new Date();
|
|
|
- return Array.from({ length: historySize }, (_, i) => {
|
|
|
- const t = new Date(now.getTime() - (historySize - 1 - i) * 60000);
|
|
|
- return formatTime(t);
|
|
|
- });
|
|
|
- })());
|
|
|
- }
|
|
|
- initializeData();
|
|
|
-
|
|
|
- // Función para formatear hora en formato 12h
|
|
|
+ const historySize = 720;
|
|
|
+
|
|
|
+ // --- FUNCIONES ORIGINALES (COMPLETAS Y RESTAURADAS) ---
|
|
|
function formatTime(date) {
|
|
|
let hours = date.getHours();
|
|
|
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
@@ -505,525 +189,126 @@
|
|
|
hours = hours % 12 || 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-content').forEach(content => content.classList.remove('active'));
|
|
|
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 => {
|
|
|
+ document.getElementById('networkTab').addEventListener('click', () => openMainTab('network'));
|
|
|
+ document.querySelectorAll('.tab-btn').forEach((button, index) => {
|
|
|
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');
|
|
|
+ document.querySelectorAll('.tab-content').forEach(content => content.classList.remove('active'));
|
|
|
+ document.querySelectorAll('.tab-content')[index].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'
|
|
|
- }]
|
|
|
+ const chartOptions = {
|
|
|
+ responsive: true, maintainAspectRatio: false, tension: 0.3, fill: true, pointRadius: 2,
|
|
|
+ scales: {
|
|
|
+ x: { grid: { color: 'rgba(0, 0, 0, 0.05)' } },
|
|
|
+ y: { beginAtZero: true, grid: { color: 'rgba(0, 0, 0, 0.05)' } }
|
|
|
},
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // Gráfico de red (ancho de banda)
|
|
|
- const networkCtx = document.getElementById('networkChart').getContext('2d');
|
|
|
- const networkChart = new Chart(networkCtx, {
|
|
|
- type: 'line',
|
|
|
- data: {
|
|
|
- labels: minuteLabels,
|
|
|
- datasets: [
|
|
|
- {
|
|
|
- label: 'Subida (Mbps)',
|
|
|
- data: networkUpMinuteData,
|
|
|
- borderColor: '#06b6d4',
|
|
|
- backgroundColor: 'rgba(6,182,212,0.1)',
|
|
|
- tension: 0.3,
|
|
|
- fill: true,
|
|
|
- pointRadius: 4,
|
|
|
- pointBackgroundColor: '#06b6d4'
|
|
|
- },
|
|
|
- {
|
|
|
- label: 'Bajada (Mbps)',
|
|
|
- data: networkDownMinuteData,
|
|
|
- borderColor: '#f59e42',
|
|
|
- backgroundColor: 'rgba(245,158,66,0.1)',
|
|
|
- tension: 0.3,
|
|
|
- fill: true,
|
|
|
- pointRadius: 4,
|
|
|
- pointBackgroundColor: '#f59e42'
|
|
|
- }
|
|
|
- ]
|
|
|
- },
|
|
|
- options: {
|
|
|
- responsive: true,
|
|
|
- maintainAspectRatio: false,
|
|
|
- scales: {
|
|
|
- y: {
|
|
|
- beginAtZero: true,
|
|
|
- title: { display: true, text: 'Mbps' },
|
|
|
- grid: { color: 'rgba(0, 0, 0, 0.05)' }
|
|
|
- },
|
|
|
- x: { grid: { color: 'rgba(0, 0, 0, 0.05)' } }
|
|
|
- },
|
|
|
- plugins: { legend: { display: true }, datalabels: { display: false } }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 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`;
|
|
|
+ plugins: { legend: { display: true }, datalabels: { display: false } }
|
|
|
+ };
|
|
|
+ const cpuChart = new Chart('cpuChart', { type: 'line', data: { labels: [], datasets: [{ label: 'Uso de CPU (%)', data: [], borderColor: '#ef4444', backgroundColor: 'rgba(239, 68, 68, 0.1)', pointBackgroundColor: '#ef4444' }] }, options: { ...chartOptions, scales: { ...chartOptions.scales, y: { ...chartOptions.scales.y, max: 100, title: { display: true, text: '%' } } } } });
|
|
|
+ const ramChart = new Chart('ramChart', { type: 'line', data: { labels: [], datasets: [{ label: 'RAM Usada', data: [], borderColor: '#3b82f6', backgroundColor: 'rgba(59, 130, 246, 0.1)', pointBackgroundColor: '#3b82f6' }] }, options: { ...chartOptions, scales: { ...chartOptions.scales, y: { ...chartOptions.scales.y, title: { display: true, text: 'Bytes' }, ticks: { callback: formatSizeCompact } } }, plugins: { ...chartOptions.plugins, tooltip: { callbacks: { label: ctx => 'RAM Usada: ' + formatSizeCompact(ctx.raw) } } } } });
|
|
|
+ const swapChart = new Chart('swapChart', { type: 'line', data: { labels: [], datasets: [{ label: 'Swap Usada', data: [], borderColor: '#10b981', backgroundColor: 'rgba(16, 185, 129, 0.1)', pointBackgroundColor: '#10b981' }] }, options: { ...chartOptions, scales: { ...chartOptions.scales, y: { ...chartOptions.scales.y, title: { display: true, text: 'Bytes' }, ticks: { callback: formatSizeCompact } } }, plugins: { ...chartOptions.plugins, tooltip: { callbacks: { label: ctx => 'SWAP Usada: ' + formatSizeCompact(ctx.raw) } } } } });
|
|
|
+ const networkChart = new Chart('networkChart', { type: 'line', data: { labels: [], datasets: [ { label: 'Subida (Mbps)', data: [], borderColor: '#06b6d4', backgroundColor: 'rgba(6,182,212,0.1)', pointBackgroundColor: '#06b6d4' }, { label: 'Bajada (Mbps)', data: [], borderColor: '#f59e42', backgroundColor: 'rgba(245,158,66,0.1)', pointBackgroundColor: '#f59e42' }] }, options: { ...chartOptions, scales: { ...chartOptions.scales, y: { ...chartOptions.scales.y, title: { display: true, text: 'Mbps' } } } } });
|
|
|
+ function formatSizeCompact(bytes) { if (bytes === 0) return '0 B'; const units = ['B', 'KB', 'MB', 'GB']; const i = Math.floor(Math.log(bytes) / Math.log(1024)); return `${parseFloat((bytes / Math.pow(1024, i)).toFixed(i === 0 ? 0 : 1))} ${units[i]}`; }
|
|
|
+ function parseSize(sizeStr) { if (!sizeStr) return { value: 0, unit: 'B' }; const parts = sizeStr.trim().split(' '); return { value: parseFloat(parts[0]) || 0, unit: parts.length > 1 ? parts[1].charAt(0) : 'B' }; }
|
|
|
+ function sizeToBytes(sizeStr) { const { value, unit } = parseSize(sizeStr); const multipliers = { 'G': 1024 * 1024 * 1024, 'M': 1024 * 1024, 'K': 1024 }; return value * (multipliers[unit] || 1); }
|
|
|
+ function updateRings(info) { const cpuPercent = parseFloat(info.cpu.usage.replace('%', '')); document.getElementById('cpu-ring').setAttribute('stroke-dasharray', `${cpuPercent},100`); document.getElementById('cpu-value').textContent = `${cpuPercent.toFixed(1)}%`; const ramUsedInfo = parseSize(info.ram.used); document.getElementById('ram-used').textContent = `${ramUsedInfo.value.toFixed(1)}${ramUsedInfo.unit}`; document.getElementById('ram-ring').setAttribute('stroke-dasharray', `${parseFloat(info.ram.percent.replace('%', ''))},100`); const swapUsedInfo = parseSize(info.swap.used); document.getElementById('swap-used').textContent = `${swapUsedInfo.value.toFixed(1)}${swapUsedInfo.unit}`; document.getElementById('swap-ring').setAttribute('stroke-dasharray', `${parseFloat(info.swap.percent.replace('%', '') || 0)},100`); }
|
|
|
+ function updateSystemInfo(info) { document.getElementById('hostname').textContent = info.hostname; document.getElementById('ip-addresses').innerHTML = info.ips.map(ip => ip.ip).join('<br>'); document.getElementById('os-info').textContent = info.os; document.getElementById('uptime').textContent = info.uptime; document.getElementById('local-time').textContent = info.local_time; }
|
|
|
+ function updateCard(statId, value, isSize = false) { const element = document.querySelector(`[data-stat="${statId}"]`); if (!element) return; let formattedValue = value; if (isSize) { const bytes = parseFloat(value); formattedValue = (bytes / (1024 * 1024) < 1) ? `${Math.round(bytes / 1024)} MB` : `${(bytes / (1024 * 1024)).toFixed(2)} GB`; } if (element.textContent !== formattedValue.toString()) { element.textContent = formattedValue; element.classList.add('value-change'); setTimeout(() => element.classList.remove('value-change'), 1000); } }
|
|
|
+ function updateCacheStats(stats) { updateCard('entradas_almacenadas', stats.store_entries); updateCard('uso_de_capacidad', stats.capacity_used); updateCard('espacio_total', stats.fs_space_total, true); updateCard('espacio_usado', stats.fs_space_used, true); updateCard('eliminación', stats.removal_policy); updateCard('edad_lru', `${stats.lru_age_days} días`); }
|
|
|
+
|
|
|
+ // --- AÑADIDO: Carga de datos históricos desde la API ---
|
|
|
+ function loadHistoricData() {
|
|
|
+ fetch('/api/metrics/today')
|
|
|
+ .then(response => response.json())
|
|
|
+ .then(data => {
|
|
|
+ if (!data || data.length === 0) { console.log("No hay historial de métricas para hoy."); return; }
|
|
|
+ const labels = [], cpuData = [], ramData = [], swapData = [], netUpData = [], netDownData = [];
|
|
|
+ data.forEach(metric => {
|
|
|
+ labels.push(formatTime(new Date(metric.timestamp)));
|
|
|
+ cpuData.push(parseFloat(metric.cpu_usage).toFixed(1));
|
|
|
+ ramData.push(metric.ram_usage_bytes);
|
|
|
+ swapData.push(metric.swap_usage_bytes);
|
|
|
+ netUpData.push(((metric.net_sent_bytes_sec * 8) / 1000000).toFixed(2));
|
|
|
+ netDownData.push(((metric.net_recv_bytes_sec * 8) / 1000000).toFixed(2));
|
|
|
+ });
|
|
|
+ const charts = [cpuChart, ramChart, swapChart, networkChart];
|
|
|
+ const chartData = [cpuData, ramData, swapData, [netUpData, netDownData]];
|
|
|
+ charts.forEach((chart, chartIndex) => {
|
|
|
+ chart.data.labels = [...labels];
|
|
|
+ if (chartIndex === 3) {
|
|
|
+ chart.data.datasets[0].data = chartData[chartIndex][0];
|
|
|
+ chart.data.datasets[1].data = chartData[chartIndex][1];
|
|
|
} else {
|
|
|
- element.textContent = `${(bytes / (1024 * 1024)).toFixed(2)} GB`;
|
|
|
+ chart.data.datasets[0].data = chartData[chartIndex];
|
|
|
}
|
|
|
- } else {
|
|
|
- element.textContent = value;
|
|
|
- }
|
|
|
-
|
|
|
- // Quitar la clase de animación después de completarse
|
|
|
- setTimeout(() => {
|
|
|
- element.classList.remove('value-change');
|
|
|
- }, 1000);
|
|
|
- }
|
|
|
- });
|
|
|
+ chart.update();
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(error => console.error('Error al cargar historial de métricas:', error));
|
|
|
}
|
|
|
|
|
|
- // Función optimizada para agregar datos minuto a minuto
|
|
|
- function addMinuteData(cpu, ram, swap, netUp, netDown) {
|
|
|
- const dataArrays = [cpuMinuteData, ramMinuteData, swapMinuteData, networkUpMinuteData, networkDownMinuteData, minuteLabels];
|
|
|
- const newValues = [cpu, ram, swap, netUp, netDown, formatTime(new Date())];
|
|
|
-
|
|
|
- // Actualizar todos los arrays eficientemente
|
|
|
- dataArrays.forEach((arr, i) => {
|
|
|
- arr.push(newValues[i]);
|
|
|
- if (arr.length > historySize) arr.shift();
|
|
|
- });
|
|
|
-
|
|
|
- // Actualizar todos los gráficos
|
|
|
- const charts = [cpuChart, ramChart, swapChart, networkChart];
|
|
|
- const chartData = [
|
|
|
- [cpuMinuteData],
|
|
|
- [ramMinuteData],
|
|
|
- [swapMinuteData],
|
|
|
- [networkUpMinuteData, networkDownMinuteData]
|
|
|
- ];
|
|
|
-
|
|
|
- charts.forEach((chart, i) => {
|
|
|
- chart.data.labels = [...minuteLabels];
|
|
|
- if (i === 3) { // networkChart tiene 2 datasets
|
|
|
- chart.data.datasets[0].data = [...chartData[i][0]];
|
|
|
- chart.data.datasets[1].data = [...chartData[i][1]];
|
|
|
- } else {
|
|
|
- chart.data.datasets[0].data = [...chartData[i][0]];
|
|
|
- }
|
|
|
- chart.update();
|
|
|
- });
|
|
|
-
|
|
|
- storage.setAll();
|
|
|
- }
|
|
|
-
|
|
|
- // Conectar a WebSocket
|
|
|
const socket = io();
|
|
|
-
|
|
|
- // Manejo optimizado de actualizaciones del sistema
|
|
|
socket.on('system_update', function (data) {
|
|
|
updateRings(data.system_info);
|
|
|
updateSystemInfo(data.system_info);
|
|
|
updateCacheStats(data.cache_stats);
|
|
|
|
|
|
- // Obtener y acumular datos
|
|
|
- const newData = [
|
|
|
- parseFloat(data.system_info.cpu.usage.replace('%', '')),
|
|
|
- sizeToBytes(data.system_info.ram.used),
|
|
|
- sizeToBytes(data.system_info.swap.used),
|
|
|
- data.network_stats ? parseFloat(data.network_stats.up_mbps) : 0,
|
|
|
- data.network_stats ? parseFloat(data.network_stats.down_mbps) : 0
|
|
|
- ];
|
|
|
+ // --- MODIFICADO: Lógica para añadir datos en vivo a las gráficas ---
|
|
|
+ function appendLiveData(chart, label, newData) {
|
|
|
+ chart.data.labels.push(label);
|
|
|
+ chart.data.datasets.forEach((dataset, index) => {
|
|
|
+ const dataPoint = Array.isArray(newData) ? newData[index] : newData;
|
|
|
+ dataset.data.push(dataPoint);
|
|
|
+ });
|
|
|
+ while (chart.data.labels.length > historySize) {
|
|
|
+ chart.data.labels.shift();
|
|
|
+ chart.data.datasets.forEach(dataset => dataset.data.shift());
|
|
|
+ }
|
|
|
+ chart.update('none');
|
|
|
+ }
|
|
|
|
|
|
- [cpuBuffer, ramBuffer, swapBuffer, netUpBuffer, netDownBuffer].forEach((buf, i) => {
|
|
|
- buf.push(newData[i]);
|
|
|
- });
|
|
|
+ // --- CORREGIDO: Se usa el timestamp del servidor para la etiqueta en vivo ---
|
|
|
+ const newLabel = formatTime(new Date(data.system_info.timestamp_utc));
|
|
|
|
|
|
- // Procesar cada minuto (12 muestras de 5 segundos)
|
|
|
- if (cpuBuffer.length >= 12) {
|
|
|
- const avg = arr => arr.reduce((a, b) => a + b, 0) / arr.length;
|
|
|
- addMinuteData(
|
|
|
- avg(cpuBuffer),
|
|
|
- ramBuffer.at(-1),
|
|
|
- swapBuffer.at(-1),
|
|
|
- avg(netUpBuffer),
|
|
|
- avg(netDownBuffer)
|
|
|
- );
|
|
|
-
|
|
|
- // Limpiar buffers
|
|
|
- [cpuBuffer, ramBuffer, swapBuffer, netUpBuffer, netDownBuffer].forEach(buf => buf.length = 0);
|
|
|
+ appendLiveData(cpuChart, newLabel, parseFloat(data.system_info.cpu.usage.replace('%','')));
|
|
|
+ appendLiveData(ramChart, newLabel, sizeToBytes(data.system_info.ram.used));
|
|
|
+ appendLiveData(swapChart, newLabel, sizeToBytes(data.system_info.swap.used));
|
|
|
+ if (data.network_stats) {
|
|
|
+ appendLiveData(networkChart, newLabel, [ data.network_stats.up_mbps, data.network_stats.down_mbps ]);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- // 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 }}"
|
|
|
- }
|
|
|
+ document.addEventListener('DOMContentLoaded', function() {
|
|
|
+ maxRamBytes = sizeToBytes("{{ system_info.ram.total }}");
|
|
|
+ maxSwapBytes = sizeToBytes("{{ system_info.swap.total }}");
|
|
|
+ ramChart.options.scales.y.max = maxRamBytes;
|
|
|
+ swapChart.options.scales.y.max = maxSwapBytes;
|
|
|
+ updateRings({
|
|
|
+ cpu: { usage: "{{ system_info.cpu.usage }}", percent: "{{ system_info.cpu.usage }}" },
|
|
|
+ ram: { used: "{{ system_info.ram.used }}", percent: "{{ system_info.ram.percent }}" },
|
|
|
+ swap: { used: "{{ system_info.swap.used }}", percent: "{{ system_info.swap.percent }}" }
|
|
|
+ });
|
|
|
+ loadHistoricData();
|
|
|
});
|
|
|
-
|
|
|
</script>
|
|
|
</body>
|
|
|
-
|
|
|
</html>
|