init commit

This commit is contained in:
2025-10-26 17:24:37 +02:00
commit 9e94e93f12
9 changed files with 605 additions and 0 deletions

90
templates/graphs.html Normal file
View File

@@ -0,0 +1,90 @@
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Графіки температур - Raspberry Pi</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
.chart-container {
height: 400px;
margin-bottom: 30px;
}
</style>
</head>
<body class="bg-light">
<div class="container py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Графіки температур за останні 30 хвилин</h2>
<a href="/" class="btn btn-outline-primary">← Повернутися до моніторингу</a>
</div>
<div class="row">
{% for device in devices %}
<div class="col-12 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{{ device.hostname }} ({{ device.host }})</h5>
<div class="chart-container">
<canvas id="chart-{{ loop.index }}"></canvas>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function createChart(elementId, data, hostname) {
const ctx = document.getElementById(elementId).getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: data.timestamps,
datasets: [{
label: 'GPU Temperature',
data: data.gpu,
borderColor: '#FF6B6B',
tension: 0.1
}, {
label: 'CPU Temperature',
data: data.cpu,
borderColor: '#4ECDC4',
tension: 0.1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: 'Temperature (°C)'
}
}
},
plugins: {
title: {
display: true,
text: hostname
}
}
}
});
}
{% for device in devices %}
createChart(
'chart-{{ loop.index }}',
{{ device.history | tojson }},
'{{ device.hostname }}'
);
{% endfor %}
</script>
</body>
</html>

127
templates/index.html Normal file
View File

@@ -0,0 +1,127 @@
<!DOCTYPE html>
<html lang="uk">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Монітор температури Raspberry Pi</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<meta http-equiv="refresh" content="10">
<style>
.sparkline {
width: 100px;
height: 30px;
display: inline-block;
}
.status-ok {
color: #198754;
}
.status-error {
color: #dc3545;
}
</style>
</head>
<body class="bg-light">
<div class="container py-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Температура системи</h2>
<a href="/graphs" class="btn btn-primary">Переглянути детальні графіки →</a>
</div>
<div class="card mb-4">
<div class="card-body">
<div class="text-muted small mb-3 text-end">
Оновлено: {{ current_time }}
(автоматичне оновлення кожні 10 секунд)
</div>
<div class="table-responsive">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>IP-адреса</th>
<th>Hostname</th>
<th>Температура GPU</th>
<th>Температура CPU</th>
<th>Графік GPU</th>
<th>Графік CPU</th>
<th>Статус</th>
</tr>
</thead>
<tbody>
{% for temp in temperatures %}
<tr>
<td>{{ temp.name }}</td>
<td>{{ temp.hostname }}</td>
<td>{% if temp.value is string %}{{ temp.value }}{% else %}{{ temp.value }}°C{% endif %}</td>
<td>{% if temp.cpu is string %}{{ temp.cpu }}{% else %}{{ temp.cpu }}°C{% endif %}</td>
<td><canvas class="sparkline" id="gpu-{{ loop.index }}"></canvas></td>
<td><canvas class="sparkline" id="cpu-{{ loop.index }}"></canvas></td>
<td class="{% if temp.status == 'OK' %}status-ok{% else %}status-error{% endif %}">
{{ temp.status }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function createSparkline(elementId, data, labels, color) {
const ctx = document.getElementById(elementId).getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
data: data,
borderColor: color,
borderWidth: 1,
fill: false,
pointRadius: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: false
}
},
scales: {
x: {
display: false
},
y: {
display: false
}
},
animation: false
}
});
}
{% for temp in temperatures %}
{% if temp.history is defined %}
createSparkline(
'gpu-{{ loop.index }}',
{{ temp.history.gpu | tojson }},
{{ temp.history.timestamps | tojson }},
'#FF6B6B'
);
createSparkline(
'cpu-{{ loop.index }}',
{{ temp.history.cpu | tojson }},
{{ temp.history.timestamps | tojson }},
'#4ECDC4'
);
{% endif %}
{% endfor %}
</script>
</body>
</html>