- Updated .dockerignore and .gitignore for better file management. - Introduced .env.example for environment variable configuration. - Added docker-compose.dev.yml for development with mock data and live reload. - Enhanced Dockerfile to include necessary dependencies and entrypoint script. - Created mock_data.py to provide sample data for testing without OpenStack/Prometheus. - Added unit tests for template filters in dashboard. - Cleaned up various files for consistency and improved readability.
640 lines
30 KiB
HTML
640 lines
30 KiB
HTML
{% 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>
|
||
<script src="{% static 'js/chartjs-plugin-annotation.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">{{ pcpu.usage|floatformat:1 }} / {{ pcpu.total }} CPU</div>
|
||
</div>
|
||
<div class="text-lg font-bold text-primary">{{ pcpu.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">{{ pcpu.usage|floatformat:1 }} CPU</span>
|
||
</div>
|
||
<progress class="progress progress-primary w-full" value="{{ pcpu.used_percentage }}" max="100"></progress>
|
||
<div class="flex justify-between text-xs">
|
||
<span class="text-base-content/60">Free</span>
|
||
<span class="font-medium">{{ pcpu.free }} CPU</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">{{ pram.usage|convert_bytes }} / {{ pram.total|convert_bytes }} GB</div>
|
||
</div>
|
||
<div class="text-lg font-bold text-secondary">{{ pram.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">{{ pram.usage|convert_bytes }} GB</span>
|
||
</div>
|
||
<progress class="progress progress-secondary w-full" value="{{ pram.used_percentage }}" max="100"></progress>
|
||
<div class="flex justify-between text-xs">
|
||
<span class="text-base-content/60">Free</span>
|
||
<span class="font-medium">{{ pram.free|convert_bytes }} 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">{{ flavors.first_common_flavor.name }}</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">{{ vm.avg_cpu|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">{{ vcpu.allocated }} / {{ vcpu.total }} vCPU</span>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<progress class="progress progress-primary flex-1" value="{{ vcpu.allocated_percentage }}" max="100"></progress>
|
||
<span class="text-xs font-medium w-12 text-right">{{ vcpu.allocated_percentage|floatformat:1 }}%</span>
|
||
</div>
|
||
<div class="flex justify-between text-xs mt-1">
|
||
<span class="text-base-content/50">overcommit: {{ vcpu.overcommit_ratio|floatformat:1 }} / {{ vcpu.overcommit_max|floatformat:1 }}</span>
|
||
<span class="text-base-content/50">{{ vcpu.allocated_percentage|floatformat:1 }}% allocated</span>
|
||
</div>
|
||
</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">{{ vram.allocated|convert_bytes }} / {{ vram.total|convert_bytes }} GB</span>
|
||
</div>
|
||
<div class="flex items-center gap-2">
|
||
<progress class="progress progress-secondary flex-1" value="{{ vram.allocated_percentage }}" max="100"></progress>
|
||
<span class="text-xs font-medium w-12 text-right">{{ vram.allocated_percentage|floatformat:1 }}%</span>
|
||
</div>
|
||
<div class="flex justify-between text-xs mt-1">
|
||
<span class="text-base-content/50">overcommit: {{ vram.overcommit_ratio|floatformat:1 }} / {{ vram.overcommit_max|floatformat:1 }}</span>
|
||
<span class="text-base-content/50">{{ vram.allocated_percentage|floatformat:1 }}% allocated</span>
|
||
</div>
|
||
</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">{{ flavors.first_common_flavor.name }}</span>
|
||
<span class="text-xs badge badge-primary">{{ flavors.first_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">{{ flavors.first_common_flavor.count|div:vm.count|mul:100|floatformat:0 }}%</span>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- Other Flavors -->
|
||
<div class="space-y-2">
|
||
{% if flavors.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>{{ flavors.second_common_flavor.name }}</span>
|
||
</div>
|
||
<span class="text-xs badge badge-outline">{{ flavors.second_common_flavor.count }}</span>
|
||
</div>
|
||
{% endif %}
|
||
|
||
{% if flavors.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>{{ flavors.third_common_flavor.name }}</span>
|
||
</div>
|
||
<span class="text-xs badge badge-outline">{{ flavors.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 class="flex items-center gap-1 text-xs">
|
||
<div class="w-3 h-0.5 bg-error/60"></div>
|
||
<span class="text-error/60">±0.5σ: <span id="currentCpuStd">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">±0.5σ: <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 = (currentStats.std * 0.5).toFixed(1);
|
||
document.getElementById('currentCpuStd').textContent = (currentStats.std * 0.5).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) => `${Number(ctx.parsed.y).toFixed(2)}% CPU`
|
||
}
|
||
},
|
||
annotation: {
|
||
annotations: {
|
||
MeanLine: {
|
||
type: 'line',
|
||
yMin: currentStats.mean.toFixed(1),
|
||
yMax: currentStats.mean.toFixed(1),
|
||
borderColor: colors.success,
|
||
borderWidth: 2,
|
||
borderDash: []
|
||
},
|
||
upperStdLine: {
|
||
type: 'line',
|
||
yMin: (currentStats.mean + currentStats.std * 0.5).toFixed(1),
|
||
yMax: (currentStats.mean + currentStats.std * 0.5).toFixed(1),
|
||
borderColor: colors.error,
|
||
borderWidth: 1,
|
||
borderDash: [5, 5]
|
||
},
|
||
lowerStdLine: {
|
||
type: 'line',
|
||
yMin: currentStats.mean > currentStats.std * 0.5 ? (currentStats.mean - currentStats.std * 0.5).toFixed(1) : 0,
|
||
yMax: currentStats.mean > currentStats.std * 0.5 ? (currentStats.mean - currentStats.std * 0.5).toFixed(1) : 0,
|
||
borderColor: colors.error,
|
||
borderWidth: 1,
|
||
borderDash: [5, 5]
|
||
}
|
||
}
|
||
}
|
||
},
|
||
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) => `${Number(ctx.parsed.y).toFixed(2)}% CPU`
|
||
}
|
||
},
|
||
annotation: {
|
||
annotations: {
|
||
MeanLine: {
|
||
type: 'line',
|
||
yMin: projectedStats.mean.toFixed(1),
|
||
yMax: projectedStats.mean.toFixed(1),
|
||
borderColor: colors.success,
|
||
borderWidth: 2,
|
||
borderDash: []
|
||
},
|
||
upperStdLine: {
|
||
type: 'line',
|
||
yMin: (currentStats.mean + currentStats.std * 0.5).toFixed(1),
|
||
yMax: (currentStats.mean + currentStats.std * 0.5).toFixed(1),
|
||
borderColor: colors.error,
|
||
borderWidth: 1,
|
||
borderDash: [5, 5]
|
||
},
|
||
lowerStdLine: {
|
||
type: 'line',
|
||
yMin: currentStats.mean > currentStats.std * 0.5 ? (currentStats.mean - currentStats.std * 0.5).toFixed(1) : 0,
|
||
yMax: currentStats.mean > currentStats.std * 0.5 ? (currentStats.mean - currentStats.std * 0.5).toFixed(1) : 0,
|
||
borderColor: colors.error,
|
||
borderWidth: 1,
|
||
borderDash: [5, 5]
|
||
}
|
||
}
|
||
}
|
||
},
|
||
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 = "{% if audits %}{{ audits.0.id }}{% endif %}";
|
||
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 %} |