crafty-4/app/frontend/templates/panel/server_metrics.html

240 lines
6.2 KiB
HTML
Raw Normal View History

2022-08-21 21:04:23 +00:00
{% extends ../base.html %}
{% block meta %}
{% end %}
{% block title %}Crafty Controller - {{ translate('serverDetails', 'serverDetails', data['lang']) }}{% end %}
{% block content %}
<div class="content-wrapper">
<!-- Page Title Header Starts-->
<div class="row page-title-header">
<div class="col-12">
<div class="page-header">
<h4 class="page-title">
{{ translate('serverDetails', 'serverDetails', data['lang']) }} - {{
data['server_stats']['server_id']['server_name'] }}
<br />
2023-11-01 17:44:56 +00:00
<small>UUID: {{ data['server_stats']['server_id']['server_id'] }}</small>
2022-08-21 21:04:23 +00:00
</h4>
</div>
</div>
</div>
<!-- Page Title Header Ends-->
{% include "parts/details_stats.html %}
<div class="row">
<div class="col-sm-12 grid-margin">
<div class="card">
<div class="card-body pt-0">
<span class="d-none d-sm-block">
{% include "parts/server_controls_list.html %}
</span>
<span class="d-block d-sm-none">
{% include "parts/m_server_controls_list.html %}
</span>
2022-09-04 20:21:33 +00:00
<div class="col-2">
<div class="form-group">
<label for="days">Metric Period</label>
<select required class="form-control form-control-lg select-css" id="days" name="days">
{% for value in data['options'] %}
<option value="{{value}}">{{value}} Day(s)</option>
{% end %}
</select>
</div>
</div>
2022-08-23 00:04:40 +00:00
<button style="float: right; visibility: hidden;" class="btn btn-outline-success reset-button"
id="reset-button"><i class="fas fa-undo"></i>&nbsp;{{ translate('serverMetrics', 'resetZoom', data['lang'])
}}</button>
{% if data['user_data']['hints'] %}
2022-08-23 02:39:39 +00:00
<span data-html="true" class="hints text-center" title="<i class='fa fa-info-circle'></i> " ,
data-content="{{
translate('serverMetrics', 'zoomHint1' , data['lang'])}} <br> <br> {{ translate('serverMetrics', 'zoomHint2', data['lang'])}}" , data-placement="top"></span>
2022-08-23 00:04:40 +00:00
{% end %}
2022-08-23 02:39:39 +00:00
<div class="chart-wrapper">
<canvas id="lineChart"></canvas>
</div>
2022-08-22 05:15:18 +00:00
2022-08-21 21:04:23 +00:00
</div>
</div>
</div>
</div>
</div>
2022-08-23 00:04:40 +00:00
<style>
2022-08-23 02:39:39 +00:00
.chart-wrapper {
height: 65vh;
}
2022-08-23 00:04:40 +00:00
.popover-body {
color: white !important;
;
}
</style>
2022-08-21 21:04:23 +00:00
<script type="text/javascript">
2022-09-04 20:21:33 +00:00
const serverId = new URLSearchParams(document.location.search).get('id')
2022-08-23 00:04:40 +00:00
var zoomed = false;
2022-08-21 21:04:23 +00:00
//line
var ctxL = document.getElementById("lineChart").getContext('2d');
const players = []
const dates = []
const ram = []
const cpu = []
{% for item in data['history_stats'] %}
2022-08-22 01:47:05 +00:00
{% if 'minecraft-java' in data['server_stats']['server_type'] %}
players.push("{{ item.get('online') }}");
2022-08-22 01:47:05 +00:00
{% end %}
dates.push("{{ item.get('created').strftime('%Y/%m/%d, %H:%M:%S') }}");
ram.push("{{ item.get('mem_percent') }}")
cpu.push("{{ item.get('cpu') }}")
2022-08-21 21:04:23 +00:00
{% end %}
var hist_chart = new Chart(ctxL, {
type: 'line',
data: {
labels: dates,
datasets: [{
label: "Players",
data: players,
borderColor: [
'rgba(136, 98, 224, .5)',
],
2022-08-22 05:15:18 +00:00
borderWidth: 2,
2022-08-23 00:04:40 +00:00
lineTension: 0,
2022-08-21 21:04:23 +00:00
},
{
label: "MEM",
data: ram,
borderColor: [
'rgba(33, 150, 243, .5)',
],
2022-08-22 05:15:18 +00:00
borderWidth: 2,
2022-08-23 00:04:40 +00:00
lineTension: 0,
2022-08-21 21:04:23 +00:00
},
{
label: "CPU",
data: cpu,
borderColor: [
'rgba(255, 175, 0, .5)',
],
2022-08-22 05:15:18 +00:00
borderWidth: 2,
2022-08-23 00:04:40 +00:00
lineTension: 0,
2022-08-21 21:04:23 +00:00
},
]
},
options: {
2022-08-23 02:39:39 +00:00
maintainAspectRatio: false,
2022-08-22 05:15:18 +00:00
plugins: {
zoom: {
zoom: {
2022-08-23 00:04:40 +00:00
onZoom({ hist_chart }) {
console.log("zooming");
document.getElementById("reset-button").style.visibility = "visible";
zoomed = true;
},
2022-08-22 05:15:18 +00:00
wheel: {
enabled: true,
2022-08-23 00:04:40 +00:00
modifierKey: 'shift',
2022-08-22 05:15:18 +00:00
},
drag: {
enabled: true,
modifierKey: "shift"
},
pinch: {
enabled: true
},
mode: 'x',
},
pan: {
enabled: true,
2022-08-23 00:04:40 +00:00
mode: "x",
2022-08-22 05:15:18 +00:00
threshhold: 1,
}
2022-08-23 00:04:40 +00:00
},
2022-08-22 05:15:18 +00:00
},
2022-08-21 21:04:23 +00:00
fill: false,
lineTension: 5,
responsive: true,
scales: {
2022-08-22 05:15:18 +00:00
y: {
min: 0,
},
x: {
position: 'right',
2022-08-23 00:04:40 +00:00
min: dates.length - 200,
2022-08-22 05:15:18 +00:00
}
2022-08-22 01:53:24 +00:00
}
2022-08-21 21:04:23 +00:00
}
});
2022-08-23 00:04:40 +00:00
$(window).ready(function () {
2022-09-04 20:21:33 +00:00
$('#days').on("change", function () {
let days = $('#days').find(":selected").val();
window.location.href = "/panel/server_detail?id=" + serverId + "&days=" + days + "&subpage=metrics"
});
2022-08-23 00:04:40 +00:00
$('body').click(function () {
$('.hints').popover("hide");
});
});
$(document).ready(function () {
if ($(window).width() > 1000) {
$('[data-toggle="popover"]').popover();
$('.hints').popover("show");
}
webSocket.on('update_server_details', function (data) {
dates.push(data.created);
players.push(data.online);
cpu.push(data.cpu)
ram.push(data.mem_percent)
data = {
labels: dates,
datasets: [{
label: "Players",
data: players,
borderColor: [
'rgba(136, 98, 224, .5)',
],
borderWidth: 2,
lineTension: 0,
},
{
label: "MEM",
data: ram,
borderColor: [
'rgba(33, 150, 243, .5)',
],
borderWidth: 2,
lineTension: 0,
},
{
label: "CPU",
data: cpu,
borderColor: [
'rgba(255, 175, 0, .5)',
],
borderWidth: 2,
lineTension: 0,
},
]
}
if (!zoomed) {
hist_chart.options.scales.x.min = dates.length - 200;
}
hist_chart.update(data)
});
$(".reset-button").click(function () {
console.log("resetting zoom");
zoomed = false;
hist_chart.resetZoom();
document.getElementById("reset-button").style.visibility = "hidden";
});
});
2022-08-21 21:04:23 +00:00
</script>
{% end %}