-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
53 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,102 +1,49 @@ | ||
const hoursElement = document.getElementById('hours'); | ||
const datemenuElement = document.getElementById('datemenu'); | ||
const cpuChartElement = document.getElementById('cpuLoadChart').getContext('2d'); | ||
const memoryChartElement = document.getElementById('memoryUsageChart').getContext('2d'); | ||
|
||
const cpuChart = new Chart(cpuChartElement, { | ||
const chartConfig = (label, unit) => ({ | ||
type: 'line', | ||
data: { | ||
labels: [], | ||
datasets: [ | ||
{ | ||
label: '% CPU', | ||
data: [], | ||
fill: false, | ||
borderColor: ['rgba(33,37,41, 1)'], | ||
tension: 0.1 | ||
} | ||
] | ||
}, | ||
data: { labels: [], datasets: [{ label, data: [], fill: false, borderColor: 'rgba(33,37,41, 1)', tension: 0.1 }] }, | ||
options: { | ||
maintainAspectRatio: false, | ||
scales: { | ||
y: { | ||
beginAtZero: true | ||
} | ||
}, | ||
elements: { | ||
point: { | ||
radius: 0 | ||
} | ||
}, | ||
animation: { | ||
duration: 0 | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false | ||
} | ||
} | ||
scales: { x: { type: 'time', time: { unit } }, y: { beginAtZero: true } }, | ||
elements: { point: { radius: 0 } }, | ||
animation: { duration: 0 }, | ||
plugins: { legend: { display: false } } | ||
} | ||
}); | ||
|
||
const memoryChart = new Chart(memoryChartElement, { | ||
type: 'line', | ||
data: { | ||
labels: [], | ||
datasets: [ | ||
{ | ||
label: 'RAM in MB', | ||
data: [], | ||
fill: false, | ||
borderColor: ['rgba(33,37,41, 1)'], | ||
tension: 0.1 | ||
} | ||
] | ||
}, | ||
options: { | ||
maintainAspectRatio: false, | ||
scales: { | ||
y: { | ||
beginAtZero: true | ||
} | ||
}, | ||
elements: { | ||
point: { | ||
radius: 0 | ||
} | ||
}, | ||
animation: { | ||
duration: 0 | ||
}, | ||
plugins: { | ||
legend: { | ||
display: false | ||
} | ||
} | ||
} | ||
}); | ||
const cpuChart = new Chart(cpuChartElement, chartConfig('% CPU', 'hour')); | ||
const memoryChart = new Chart(memoryChartElement, chartConfig('RAM in MB', 'hour')); | ||
|
||
document.addEventListener('DOMContentLoaded', async () => { | ||
await setChartData(); | ||
|
||
setInterval(async () => { | ||
datemenuElement.addEventListener('change', async () => { | ||
await setChartData(); | ||
}, 10000); | ||
}); | ||
}); | ||
|
||
async function getMetrics() { | ||
return await axios.get('/api/metrics?hours=' + hoursElement.value) | ||
.then(response => response.data); | ||
return (await axios.get('/api/metrics?hours=' + datemenuElement.value)).data; | ||
} | ||
|
||
async function setChartData() { | ||
const data = await getMetrics(); | ||
|
||
cpuChart.data.labels = data.map(metric => metric.date); | ||
cpuChart.data.datasets[0].data = data.map(metric => metric.cpuLoad); | ||
cpuChart.update(); | ||
const updateChart = (chart, dataKey) => { | ||
if (datemenuElement.value > 24) { | ||
chart.options.scales.x.time.unit = 'day'; | ||
} else { | ||
chart.options.scales.x.time.unit = 'hour'; | ||
} | ||
|
||
chart.data.labels = data.map(metric => metric.date); | ||
chart.data.datasets[0].data = data.map(metric => metric[dataKey]); | ||
chart.update(); | ||
}; | ||
|
||
memoryChart.data.labels = data.map(metric => metric.date); | ||
memoryChart.data.datasets[0].data = data.map(metric => metric.memoryUsage); | ||
memoryChart.update(); | ||
updateChart(cpuChart, 'cpuLoad'); | ||
updateChart(memoryChart, 'memoryUsage'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,16 +5,10 @@ | |
<div class="container-fluid d-flex"> | ||
<div class="row g-3 align-items-center mb-3"> | ||
<div class="col-auto"> | ||
<label class="col-form-label" for="hours">Hours</label> | ||
</div> | ||
<div class="col-auto"> | ||
<select class="form-select" id="hours"> | ||
<option value="1" selected>1</option> | ||
<option value="3">3</option> | ||
<option value="6">6</option> | ||
<option value="12">12</option> | ||
<option value="24">24</option> | ||
<option value="48">48</option> | ||
<select class="form-select" id="datemenu"> | ||
<option value="1" selected>Last hour</option> | ||
<option value="24">Last 24 hours</option> | ||
<option value="168">Last 7 days</option> | ||
</select> | ||
</div> | ||
</div> | ||
|
@@ -44,10 +38,13 @@ | |
|
||
<div class="col-md-6"> | ||
<div class="card p-3"> | ||
<div class="d-flex mb-4"> | ||
<div class="d-flex flex-column flex-md-row mb-3 mb-md-4 justify-content-center"> | ||
<h4 class="card-title">Simulcasts</h4> | ||
<a id="simulcasts-invalidate" href="/admin/simulcasts-invalidate" | ||
class="btn btn-danger ms-auto me-0">Invalidate</a> | ||
|
||
<div class="ms-md-auto me-md-0"> | ||
<a id="simulcasts-invalidate" href="/admin/simulcasts-invalidate" | ||
class="btn btn-danger">Invalidate</a> | ||
</div> | ||
</div> | ||
|
||
<ul class="list-group list-group-numbered"> | ||
|
@@ -76,10 +73,13 @@ | |
|
||
<div class="col-md-6"> | ||
<div class="card p-3"> | ||
<div class="d-flex mb-4"> | ||
<div class="d-flex flex-column flex-md-row mb-3 mb-md-4 justify-content-center"> | ||
<h4 class="card-title">Images</h4> | ||
<a id="images-invalidate" href="/admin/images-invalidate" class="btn btn-danger ms-auto me-0">Invalidate</a> | ||
<a href="/admin/images-save" class="btn btn-success ms-2 me-0">Save</a> | ||
|
||
<div class="ms-md-auto me-md-0"> | ||
<a id="images-invalidate" href="/admin/images-invalidate" class="btn btn-danger">Invalidate</a> | ||
<a href="/admin/images-save" class="btn btn-success">Save</a> | ||
</div> | ||
</div> | ||
|
||
<div class="row g-3"> | ||
|
@@ -106,6 +106,9 @@ | |
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/chart.js" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/moment@^2"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script> | ||
|
||
<script src="/assets/js/home_chart.js" crossorigin="anonymous"></script> | ||
</@navigation.display> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters