Stitching things up
This commit is contained in:
68
templates/base.html
Normal file
68
templates/base.html
Normal file
@@ -0,0 +1,68 @@
|
||||
{% load static %}
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" data-theme="light">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Watcher Visio{% endblock %}</title>
|
||||
<link rel="stylesheet" href="{% static 'css/output.css' %}">
|
||||
{% block imports %}
|
||||
{% endblock %}
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<!-- Navbar -->
|
||||
<div class="navbar bg-base-100 shadow-lg">
|
||||
<div class="navbar-start">
|
||||
<a class="btn btn-ghost text-xl" href="{% url 'index' %}">Watcher Visio</a>
|
||||
</div>
|
||||
<div class="navbar-center hidden lg:flex">
|
||||
</div>
|
||||
<div class="navbar-end">
|
||||
<div class="px-1 flex gap-3 pr-10">
|
||||
<span class="badge badge-primary badge-lg">{{ region_name }}</span>
|
||||
<label class="swap swap-rotate">
|
||||
<input type="checkbox" class="theme-controller" value="dark" />
|
||||
<svg class="swap-off fill-current w-6 h-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M5.64,17l-.71.71a1,1,0,0,0,0,1.41,1,1,0,0,0,1.41,0l.71-.71A1,1,0,0,0,5.64,17ZM5,12a1,1,0,0,0-1-1H3a1,1,0,0,0,0,2H4A1,1,0,0,0,5,12Zm7-7a1,1,0,0,0,1-1V3a1,1,0,0,0-2,0V4A1,1,0,0,0,12,5ZM5.64,7.05a1,1,0,0,0,.7.29,1,1,0,0,0,.71-.29,1,1,0,0,0,0-1.41l-.71-.71A1,1,0,0,0,4.93,6.34Zm12,.29a1,1,0,0,0,.7-.29l.71-.71a1,1,0,1,0-1.41-1.41L17,5.64a1,1,0,0,0,0,1.41A1,1,0,0,0,17.66,7.34ZM21,11H20a1,1,0,0,0,0,2h1a1,1,0,0,0,0-2Zm-9,8a1,1,0,0,0-1,1v1a1,1,0,0,0,2,0V20A1,1,0,0,0,12,19ZM18.36,17A1,1,0,0,0,17,18.36l.71.71a1,1,0,0,0,1.41,0,1,1,0,0,0,0-1.41ZM12,6.5A5.5,5.5,0,1,0,17.5,12,5.51,5.51,0,0,0,12,6.5Zm0,9A3.5,3.5,0,1,1,15.5,12,3.5,3.5,0,0,1,12,15.5Z"/>
|
||||
</svg>
|
||||
<svg class="swap-on fill-current w-6 h-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path d="M21.64,13a1,1,0,0,0-1.05-.14,8.05,8.05,0,0,1-3.37.73A8.15,8.15,0,0,1,9.08,5.49a8.59,8.59,0,0,1,.25-2A1,1,0,0,0,8,2.36,10.14,10.14,0,1,0,22,14.05,1,1,0,0,0,21.64,13Zm-9.5,6.69A8.14,8.14,0,0,1,7.08,5.22v.27A10.15,10.15,0,0,0,17.22,15.63a9.79,9.79,0,0,0,2.1-.22A8.11,8.11,0,0,1,12.14,19.73Z"/>
|
||||
</svg>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Main Content -->
|
||||
<main class="container mx-auto px-4 py-8 min-h-screen">
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
</main>
|
||||
|
||||
<script>
|
||||
// Function to apply theme
|
||||
function applyTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
const checkbox = document.querySelector('.theme-controller');
|
||||
checkbox.checked = (theme === 'dark');
|
||||
|
||||
document.dispatchEvent(new Event("themechange"));
|
||||
}
|
||||
|
||||
// Load saved theme from localStorage
|
||||
const savedTheme = localStorage.getItem('theme') || 'light';
|
||||
applyTheme(savedTheme);
|
||||
|
||||
// Listen for toggle changes
|
||||
document.querySelector('.theme-controller').addEventListener('change', function() {
|
||||
const newTheme = this.checked ? 'dark' : 'light';
|
||||
applyTheme(newTheme);
|
||||
localStorage.setItem('theme', newTheme);
|
||||
});
|
||||
</script>
|
||||
{% block script %}
|
||||
{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
580
templates/index.html
Normal file
580
templates/index.html
Normal file
@@ -0,0 +1,580 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static mathfilters %}
|
||||
|
||||
{% block imports %}
|
||||
<script src="{% static 'js/utils.js' %}"></script>
|
||||
<script src="{% static 'js/chart.js' %}"></script>
|
||||
<script src="{% static 'js/chartjs-plugin-datalabels.min.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<!-- MAIN DASHBOARD -->
|
||||
<div class="p-4 space-y-4">
|
||||
<!-- QUICK STATS ROW -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4">
|
||||
<!-- CPU Utilization -->
|
||||
<div class="card bg-base-100 shadow-sm hover:shadow transition-shadow">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-base-content/70">CPU Utilization</h3>
|
||||
<div class="text-xs text-base-content/40 mt-0.5">{{ cpu_used }} / {{ cpu_used|add:cpu_free }} vCPU</div>
|
||||
</div>
|
||||
<div class="text-lg font-bold text-primary">{{ cpu_used_percentage|floatformat:1 }}%</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-base-content/60">Used</span>
|
||||
<span class="font-medium">{{ cpu_used }} vCPU</span>
|
||||
</div>
|
||||
<progress class="progress progress-primary w-full" value="{{ cpu_used_percentage }}" max="100"></progress>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-base-content/60">Free</span>
|
||||
<span class="font-medium">{{ cpu_free }} vCPU</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- RAM Utilization -->
|
||||
<div class="card bg-base-100 shadow-sm hover:shadow transition-shadow">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-base-content/70">RAM Utilization</h3>
|
||||
<div class="text-xs text-base-content/40 mt-0.5">{{ ram_used }} / {{ ram_used|add:ram_free }} GB</div>
|
||||
</div>
|
||||
<div class="text-lg font-bold text-secondary">{{ ram_used_percentage|floatformat:1 }}%</div>
|
||||
</div>
|
||||
<div class="space-y-2">
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-base-content/60">Used</span>
|
||||
<span class="font-medium">{{ ram_used }} GB</span>
|
||||
</div>
|
||||
<progress class="progress progress-secondary w-full" value="{{ ram_used_percentage }}" max="100"></progress>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-base-content/60">Free</span>
|
||||
<span class="font-medium">{{ ram_free }} GB</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Instance Summary -->
|
||||
<div class="card bg-base-100 shadow-sm hover:shadow transition-shadow">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex items-center justify-between mb-3">
|
||||
<div>
|
||||
<h3 class="text-sm font-medium text-base-content/70">Instances</h3>
|
||||
<div class="text-xs text-base-content/40 mt-0.5">{{ vm_active }} active / {{ vm_stopped }} stopped</div>
|
||||
</div>
|
||||
<div class="text-lg font-bold text-accent">{{ vm_count }}</div>
|
||||
</div>
|
||||
<div class="space-y-3">
|
||||
<div class="flex justify-between items-center text-xs">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="w-2 h-2 rounded-full bg-success"></div>
|
||||
<span>Most Used Flavor</span>
|
||||
</div>
|
||||
<span class="font-medium">{{ common_flavor }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center text-xs">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="w-2 h-2 rounded-full bg-info"></div>
|
||||
<span>Avg. vCPU/VM</span>
|
||||
</div>
|
||||
<span class="font-medium">{{ avg_cpu_per_vm|floatformat:1 }}</span>
|
||||
</div>
|
||||
<div class="flex justify-between items-center text-xs">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="w-2 h-2 rounded-full bg-warning"></div>
|
||||
<span>Density</span>
|
||||
</div>
|
||||
<span class="font-medium">{{ vm_density|floatformat:1 }}/host</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- DETAILED OVERVIEW -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
<!-- Resource Allocation -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<h3 class="text-sm font-semibold mb-4 flex items-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
|
||||
</svg>
|
||||
Resource Allocation
|
||||
</h3>
|
||||
|
||||
<!-- CPU Allocation -->
|
||||
<div class="mb-4">
|
||||
<div class="flex justify-between text-xs mb-1">
|
||||
<span class="text-base-content/70">CPU Allocation</span>
|
||||
<span class="font-medium">{{ cpu_allocated }} / {{ cpu_total }} vCPU</span>
|
||||
</div>
|
||||
{% with pct=cpu_allocated|div:cpu_total|mul:100 %}
|
||||
<div class="flex items-center gap-2">
|
||||
<progress class="progress progress-primary flex-1" value="{{ pct }}" max="100"></progress>
|
||||
<span class="text-xs font-medium w-12 text-right">{{ pct|floatformat:1 }}%</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs mt-1">
|
||||
<span class="text-base-content/50">OC: x{{ cpu_overcommit_ratio }}</span>
|
||||
<span class="text-base-content/50">{{ pct|floatformat:1 }}% allocated</span>
|
||||
</div>
|
||||
{% endwith %}
|
||||
</div>
|
||||
|
||||
<!-- RAM Allocation -->
|
||||
<div>
|
||||
<div class="flex justify-between text-xs mb-1">
|
||||
<span class="text-base-content/70">RAM Allocation</span>
|
||||
<span class="font-medium">{{ ram_allocated }} / {{ ram_total }} GB</span>
|
||||
</div>
|
||||
{% with pct=ram_allocated|div:ram_total|mul:100 %}
|
||||
<div class="flex items-center gap-2">
|
||||
<progress class="progress progress-secondary flex-1" value="{{ pct }}" max="100"></progress>
|
||||
<span class="text-xs font-medium w-12 text-right">{{ pct|floatformat:1 }}%</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs mt-1">
|
||||
<span class="text-base-content/50">OC: x{{ ram_overcommit_ratio }}</span>
|
||||
<span class="text-base-content/50">{{ pct|floatformat:1 }}% allocated</span>
|
||||
</div>
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Flavor Distribution -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<h3 class="text-sm font-semibold mb-4 flex items-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 3.055A9.001 9.001 0 1020.945 13H11V3.055z"/>
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.488 9H15V3.512A9.025 9.025 0 0120.488 9z"/>
|
||||
</svg>
|
||||
Top Flavors
|
||||
</h3>
|
||||
|
||||
<div class="space-y-3">
|
||||
<!-- Most Common -->
|
||||
<div class="bg-base-200/50 rounded-lg p-3">
|
||||
<div class="flex justify-between items-center mb-1">
|
||||
<span class="text-sm font-medium">{{ common_flavor }}</span>
|
||||
<span class="text-xs badge badge-primary">{{ common_flavor_count }} instances</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-xs">
|
||||
<span class="text-base-content/60">Share</span>
|
||||
<span class="font-medium">{{ common_flavor_count|div:vm_count|mul:100|floatformat:0 }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Other Flavors -->
|
||||
<div class="space-y-2">
|
||||
{% if second_common_flavor %}
|
||||
<div class="flex justify-between items-center text-sm">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="w-1.5 h-1.5 rounded-full bg-base-content/30"></div>
|
||||
<span>{{ second_common_flavor.name }}</span>
|
||||
</div>
|
||||
<span class="text-xs badge badge-outline">{{ second_common_flavor.count }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if third_common_flavor %}
|
||||
<div class="flex justify-between items-center text-sm">
|
||||
<div class="flex items-center gap-2">
|
||||
<div class="w-1.5 h-1.5 rounded-full bg-base-content/30"></div>
|
||||
<span>{{ third_common_flavor.name }}</span>
|
||||
</div>
|
||||
<span class="text-xs badge badge-outline">{{ third_common_flavor.count }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- AUDIT CONTROL -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-4">
|
||||
<div>
|
||||
<h3 class="text-sm font-semibold">Audit Analysis</h3>
|
||||
<div class="text-xs text-base-content/50 mt-0.5">Select an audit to analyze resource distribution</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="text-xs text-base-content/50">{{ audits|length }} available</span>
|
||||
<div class="dropdown dropdown-end">
|
||||
<label tabindex="0" class="btn btn-xs btn-ghost">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
|
||||
</svg>
|
||||
Info
|
||||
</label>
|
||||
<div tabindex="0" class="dropdown-content z-[1] card card-compact w-64 p-2 shadow bg-base-100">
|
||||
<div class="card-body">
|
||||
<div class="text-xs space-y-1">
|
||||
<div class="flex justify-between">
|
||||
<span class="text-base-content/60">Strategy:</span>
|
||||
<span id="previewStrategy">Balanced</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-base-content/60">Scope:</span>
|
||||
<span id="previewScope">Full Cluster</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-base-content/60">CPU Weight:</span>
|
||||
<span id="previewCpu">1.0</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span class="text-base-content/60">RAM Weight:</span>
|
||||
<span id="previewRam">1.0</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col md:flex-row gap-3">
|
||||
<select id="auditSelector" class="select select-bordered select-sm flex-1">
|
||||
{% for audit in audits %}
|
||||
<option value="{{ audit.id }}"
|
||||
data-cpu="{{ audit.cpu_weight }}"
|
||||
data-ram="{{ audit.ram_weight }}"
|
||||
data-scope="{{ audit.scope }}"
|
||||
data-strategy="{{ audit.strategy }}"
|
||||
data-goal="{{ audit.goal }}">
|
||||
{{ audit.name }} ({{ audit.created_at|date:"M d" }})
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<button onclick="loadSelectedAudit()" class="btn btn-primary btn-sm">
|
||||
Load Analysis
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- ANALYSIS VISUALIZATION -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-2 gap-4">
|
||||
<!-- Current State -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<h3 class="text-sm font-semibold mb-4">Current CPU Distribution</h3>
|
||||
<div class="h-48">
|
||||
<canvas id="cpuHostChart"></canvas>
|
||||
</div>
|
||||
<div class="flex items-center justify-center gap-3 mt-3">
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<div class="w-3 h-0.5 bg-success"></div>
|
||||
<span class="text-success">Mean: <span id="currentCpuMean">0</span>%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Projected State -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<h3 class="text-sm font-semibold mb-4">Projected CPU Distribution</h3>
|
||||
<div class="h-48">
|
||||
<canvas id="cpuProjectedChart"></canvas>
|
||||
</div>
|
||||
<div class="flex items-center justify-center gap-4 mt-3">
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<div class="w-3 h-0.5 bg-success"></div>
|
||||
<span class="text-success">Mean: <span id="projectedCpuMean">0</span>%</span>
|
||||
</div>
|
||||
<div class="flex items-center gap-1 text-xs">
|
||||
<div class="w-3 h-0.5 bg-error/60"></div>
|
||||
<span class="text-error/60">±1σ: <span id="projectedCpuStd">0</span>%</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- MIGRATION ACTIONS -->
|
||||
<div class="card bg-base-100 shadow-sm">
|
||||
<div class="card-body p-4">
|
||||
<div class="flex items-center justify-between mb-4">
|
||||
<h3 class="text-sm font-semibold">Migration Actions</h3>
|
||||
<div class="badge badge-neutral badge-sm" id="migrationCount">Select audit</div>
|
||||
</div>
|
||||
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-zebra table-sm">
|
||||
<thead>
|
||||
<tr class="bg-base-200">
|
||||
<th class="text-xs font-medium">Instance</th>
|
||||
<th class="text-xs font-medium">Source → Destination</th>
|
||||
<th class="text-xs font-medium">Flavor</th>
|
||||
<th class="text-xs font-medium">Impact</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="migrationTableBody" class="text-sm">
|
||||
<tr>
|
||||
<td colspan="4" class="text-center py-6 text-base-content/40">
|
||||
No audit selected. Load an audit to view migration recommendations.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block script %}
|
||||
<script>
|
||||
// Update audit preview
|
||||
document.getElementById('auditSelector').addEventListener('change', function(e) {
|
||||
const option = this.options[this.selectedIndex];
|
||||
document.getElementById('previewCpu').textContent = option.dataset.cpu || '1.0';
|
||||
document.getElementById('previewRam').textContent = option.dataset.ram || '1.0';
|
||||
document.getElementById('previewScope').textContent = option.dataset.scope || 'Full Cluster';
|
||||
document.getElementById('previewStrategy').textContent = option.dataset.strategy || 'Balanced';
|
||||
});
|
||||
|
||||
// Audit data
|
||||
const auditData = {
|
||||
{% for audit in audits %}
|
||||
"{{ audit.id }}": {
|
||||
name: "{{ audit.name }}",
|
||||
migrations: {{ audit.migrations|safe }},
|
||||
hostData: {
|
||||
labels: {{ audit.host_labels|safe }},
|
||||
current: {{ audit.cpu_current|safe }},
|
||||
projected: {{ audit.cpu_projected|safe }}
|
||||
}
|
||||
}{% if not forloop.last %},{% endif %}
|
||||
{% endfor %}
|
||||
};
|
||||
|
||||
// Chart instances
|
||||
let cpuHostChart = null;
|
||||
let cpuProjectedChart = null;
|
||||
|
||||
// Load selected audit
|
||||
function loadSelectedAudit() {
|
||||
const auditId = document.getElementById('auditSelector').value;
|
||||
updateMigrationTable(auditId);
|
||||
updateCPUCharts(auditId);
|
||||
}
|
||||
|
||||
// Update migration table
|
||||
function updateMigrationTable(auditId) {
|
||||
const tbody = document.getElementById('migrationTableBody');
|
||||
const migrationCount = document.getElementById('migrationCount');
|
||||
const data = auditData[auditId];
|
||||
|
||||
if (!data || !data.migrations || data.migrations.length === 0) {
|
||||
tbody.innerHTML = `
|
||||
<tr>
|
||||
<td colspan="4" class="text-center py-6 text-base-content/40">
|
||||
No migration actions recommended
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
migrationCount.textContent = '0 actions';
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '';
|
||||
data.migrations.forEach(migration => {
|
||||
const impact = migration.impact || 'Low';
|
||||
const impactClass = {
|
||||
'Low': 'badge-success',
|
||||
'Medium': 'badge-warning',
|
||||
'High': 'badge-error'
|
||||
}[impact] || 'badge-neutral';
|
||||
|
||||
html += `
|
||||
<tr>
|
||||
<td class="font-medium">
|
||||
<div>${migration.instanceName}</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="badge badge-outline badge-xs">${migration.source}</span>
|
||||
<svg class="w-3 h-3 text-base-content/30" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 7l5 5m0 0l-5 5m5-5H6"/>
|
||||
</svg>
|
||||
<span class="badge badge-primary badge-outline badge-xs">${migration.destination}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<code class="text-xs bg-base-200 px-2 py-1 rounded">${migration.flavor}</code>
|
||||
</td>
|
||||
<td>
|
||||
<span class="badge ${impactClass} badge-xs">${impact}</span>
|
||||
</td>
|
||||
</tr>
|
||||
`;
|
||||
});
|
||||
|
||||
tbody.innerHTML = html;
|
||||
migrationCount.textContent = `${data.migrations.length} action${data.migrations.length !== 1 ? 's' : ''}`;
|
||||
}
|
||||
|
||||
// Update CPU charts
|
||||
function updateCPUCharts(auditId) {
|
||||
const data = auditData[auditId];
|
||||
if (!data || !data.hostData) return;
|
||||
|
||||
const currentCtx = document.getElementById('cpuHostChart').getContext('2d');
|
||||
const projectedCtx = document.getElementById('cpuProjectedChart').getContext('2d');
|
||||
|
||||
// Calculate statistics
|
||||
const currentStats = calculateStats(data.hostData.current);
|
||||
const projectedStats = calculateStats(data.hostData.projected);
|
||||
|
||||
// Update stats displays
|
||||
document.getElementById('currentCpuMean').textContent = currentStats.mean.toFixed(1);
|
||||
document.getElementById('projectedCpuMean').textContent = projectedStats.mean.toFixed(1);
|
||||
document.getElementById('projectedCpuStd').textContent = projectedStats.std.toFixed(1);
|
||||
|
||||
// Destroy existing charts
|
||||
if (cpuHostChart) cpuHostChart.destroy();
|
||||
if (cpuProjectedChart) cpuProjectedChart.destroy();
|
||||
|
||||
// Chart colors
|
||||
const colors = {
|
||||
primary: getCSSVar('--color-primary'),
|
||||
secondary: getCSSVar('--color-secondary'),
|
||||
accent: getCSSVar('--color-accent'),
|
||||
neutral: getCSSVar('-color-neutral'),
|
||||
info: getCSSVar('--color-info'),
|
||||
success: getCSSVar('--color-success'),
|
||||
warning: getCSSVar('--color-warning'),
|
||||
error: getCSSVar('--color-error')
|
||||
};
|
||||
|
||||
// Create current CPU chart
|
||||
cpuHostChart = new Chart(currentCtx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: data.hostData.labels,
|
||||
datasets: [{
|
||||
label: 'CPU %',
|
||||
data: data.hostData.current,
|
||||
backgroundColor: colors.info + '40',
|
||||
borderColor: colors.info,
|
||||
borderWidth: 1,
|
||||
borderRadius: 3
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: (ctx) => `${ctx.parsed.y}% CPU`
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 100,
|
||||
grid: { drawBorder: false },
|
||||
ticks: {
|
||||
callback: value => value + '%'
|
||||
}
|
||||
},
|
||||
x: {
|
||||
grid: { display: false },
|
||||
ticks: {
|
||||
maxRotation: 45
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create projected CPU chart
|
||||
cpuProjectedChart = new Chart(projectedCtx, {
|
||||
type: 'bar',
|
||||
data: {
|
||||
labels: data.hostData.labels,
|
||||
datasets: [{
|
||||
label: 'Projected CPU %',
|
||||
data: data.hostData.projected,
|
||||
backgroundColor: colors.warning + '40',
|
||||
borderColor: colors.warning,
|
||||
borderWidth: 1,
|
||||
borderRadius: 3
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
responsive: true,
|
||||
maintainAspectRatio: false,
|
||||
plugins: {
|
||||
legend: { display: false },
|
||||
tooltip: {
|
||||
callbacks: {
|
||||
label: (ctx) => `${ctx.parsed.y}% CPU`
|
||||
}
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
max: 100,
|
||||
grid: { drawBorder: false },
|
||||
ticks: {
|
||||
callback: value => value + '%'
|
||||
}
|
||||
},
|
||||
x: {
|
||||
grid: { display: false },
|
||||
ticks: {
|
||||
maxRotation: 45
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Utility functions
|
||||
function calculateStats(data) {
|
||||
const mean = data.reduce((a, b) => a + b, 0) / data.length;
|
||||
const variance = data.reduce((a, b) => a + Math.pow(b - mean, 2), 0) / data.length;
|
||||
const std = Math.sqrt(variance);
|
||||
return { mean, std };
|
||||
}
|
||||
|
||||
// Initialize
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const initialAudit = "{{ audits.0.id|default:'' }}";
|
||||
if (initialAudit && auditData[initialAudit]) {
|
||||
document.getElementById('auditSelector').dispatchEvent(new Event('change'));
|
||||
loadSelectedAudit();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block css %}
|
||||
<style>
|
||||
.progress {
|
||||
@apply h-1.5;
|
||||
}
|
||||
.table td, .table th {
|
||||
@apply px-4 py-2;
|
||||
}
|
||||
.badge-xs {
|
||||
@apply px-1.5 py-0.5 text-xs;
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user