Skip to content

Commit 0741ab6

Browse files
committed
Revamped resource graphing, uses chart.js
1 parent 013c36f commit 0741ab6

File tree

8 files changed

+241
-251
lines changed

8 files changed

+241
-251
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111

1212
### Changed
1313
* Servers are now queued for deletion to allow for cancellation of deletion, as well as run in the background to speed up page loading.
14+
* Switched to new graphing library to make graphs less... broken.
1415

1516
### Removed
1617
* Removed online player listing due to inconsistency in query library and an assortment of query related bugs. This will return in future versions when we get it working correctly.

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Bootstrap - [license](https://github.com/twbs/bootstrap/blob/master/LICENSE) - [
4343

4444
BootStrap Notify - [license](https://github.com/mouse0270/bootstrap-notify/blob/master/LICENSE) - [homepage](http://bootstrap-notify.remabledesigns.com)
4545

46-
D3.js - [license](https://github.com/mbostock/d3/blob/master/LICENSE) - [homepage](https://d3js.org/)
46+
Chart.js - [license](https://github.com/chartjs/Chart.js/blob/master/LICENSE.md) - [homepage](http://www.chartjs.org)
4747

4848
FontAwesome - [license](http://fontawesome.io/license/) - [homepage](http://fontawesome.io)
4949

@@ -57,8 +57,6 @@ jQuery Terminal - [license](https://github.com/jcubic/jquery.terminal/blob/maste
5757

5858
Lodash - [license](https://github.com/lodash/lodash/blob/master/LICENSE) - [homepage](https://lodash.com/)
5959

60-
MetricsGraphics.js - [license](https://github.com/mozilla/metrics-graphics/blob/master/LICENSE) - [homepage](http://metricsgraphicsjs.org/)
61-
6260
Socket.io - [license](https://github.com/socketio/socket.io/blob/master/LICENSE) - [homepage](http://socket.io)
6361

6462
SweetAlert - [license](https://github.com/t4t5/sweetalert/blob/master/LICENSE) - [homepage](http://t4t5.github.io/sweetalert/)

public/js/vendor/chartjs/chart.min.js

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/vendor/d3/d3.min.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

public/js/vendor/jquery/jquery-dateFormat.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/themes/default/js/vendor/metricsgraphics/metricsgraphics.min.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

resources/views/admin/nodes/view.blade.php

Lines changed: 104 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525

2626
@section('scripts')
2727
@parent
28-
{!! Theme::css('css/vendor/metricsgraphics/metricsgraphics.css') !!}
29-
{!! Theme::js('js/vendor/d3/d3.min.js') !!}
30-
{!! Theme::js('js/vendor/metricsgraphics/metricsgraphics.min.js') !!}
3128
{!! Theme::js('js/vendor/socketio/socket.io.min.js') !!}
3229
{!! Theme::js('js/bootstrap-notify.min.js') !!}
30+
{!! Theme::js('js/vendor/chartjs/chart.min.js') !!}
31+
{!! Theme::js('js/vendor/jquery/jquery-dateFormat.min.js') !!}
3332
<script>
3433
$(document).ready(function () {
3534
$.notifyDefaults({
@@ -102,9 +101,8 @@
102101
<div class="panel-heading" style="border-top: 1px solid #ddd;"></div>
103102
<div class="panel-body">
104103
<div class="row">
105-
<div class="col-xs-11 text-center" id="chart_memory" style="height:250px;"></div>
106-
<div class="col-xs-11 text-center" id="chart_cpu" style="height:250px;"></div>
107-
<div class="col-xs-11 text-center" id="chart_players" style="height:250px;"></div>
104+
<canvas id="chart_memory" style="max-height:300px;"></canvas>
105+
<canvas id="chart_cpu" style="max-height:300px;"></canvas>
108106
</div>
109107
</div>
110108
</div>
@@ -545,58 +543,6 @@
545543
3: 'Stopping'
546544
};
547545
548-
// -----------------+
549-
// Charting Methods |
550-
// -----------------+
551-
var memoryGraphSettings = {
552-
title: 'Memory Usage (MB)',
553-
data: [{
554-
'date': new Date(),
555-
'memory': 0
556-
}],
557-
full_width: true,
558-
full_height: true,
559-
target: document.getElementById('chart_memory'),
560-
x_accessor: 'date',
561-
y_accessor: 'memory',
562-
y_rug: true,
563-
area: false,
564-
};
565-
566-
var cpuGraphSettings = {
567-
title: 'CPU Usage (%)',
568-
data: [{
569-
'date': new Date(),
570-
'cpu': 0
571-
}],
572-
full_width: true,
573-
full_height: true,
574-
target: document.getElementById('chart_cpu'),
575-
x_accessor: 'date',
576-
y_accessor: 'cpu',
577-
y_rug: true,
578-
area: false,
579-
};
580-
581-
var playersGraphSettings = {
582-
title: 'Players Online',
583-
data: [{
584-
'date': new Date(),
585-
'players': 0
586-
}],
587-
full_width: true,
588-
full_height: true,
589-
target: document.getElementById('chart_players'),
590-
x_accessor: 'date',
591-
y_accessor: 'players',
592-
y_rug: true,
593-
area: false,
594-
};
595-
596-
MG.data_graphic(memoryGraphSettings);
597-
MG.data_graphic(cpuGraphSettings);
598-
MG.data_graphic(playersGraphSettings);
599-
600546
// Main Socket Object
601547
var socket = io('{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/stats/', {
602548
'query': 'token={{ $node->daemonSecret }}'
@@ -626,36 +572,112 @@
626572
console.error('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.');
627573
});
628574
629-
socket.on('live-stats', function (data) {
630-
631-
if (typeof memoryGraphSettings.data[0][100] !== 'undefined' || memoryGraphSettings.data[0][0].memory === -1) {
632-
memoryGraphSettings.data[0].shift();
633-
}
634-
if (typeof cpuGraphSettings.data[0][100] !== 'undefined' || cpuGraphSettings.data[0][0].cpu === -1) {
635-
cpuGraphSettings.data[0].shift();
575+
var ctc = $('#chart_cpu');
576+
var timeLabels = [];
577+
var cpuData = [];
578+
var CPUChart = new Chart(ctc, {
579+
type: 'line',
580+
data: {
581+
labels: timeLabels,
582+
datasets: [
583+
{
584+
label: "Percent Use",
585+
fill: false,
586+
lineTension: 0.03,
587+
backgroundColor: "#00A1CB",
588+
borderColor: "#00A1CB",
589+
borderCapStyle: 'butt',
590+
borderDash: [],
591+
borderDashOffset: 0.0,
592+
borderJoinStyle: 'miter',
593+
pointBorderColor: "rgba(75,192,192,1)",
594+
pointBackgroundColor: "#fff",
595+
pointBorderWidth: 1,
596+
pointHoverRadius: 5,
597+
pointHoverBackgroundColor: "rgba(75,192,192,1)",
598+
pointHoverBorderColor: "rgba(220,220,220,1)",
599+
pointHoverBorderWidth: 2,
600+
pointRadius: 1,
601+
pointHitRadius: 10,
602+
data: cpuData,
603+
spanGaps: false,
604+
}
605+
]
606+
},
607+
options: {
608+
title: {
609+
display: true,
610+
text: 'CPU Usage (as Percent Total)'
611+
},
612+
legend: {
613+
display: false,
614+
},
615+
animation: {
616+
duration: 1,
617+
}
636618
}
637-
if (typeof playersGraphSettings.data[0][100] !== 'undefined' || playersGraphSettings.data[0][0].players === -1) {
638-
playersGraphSettings.data[0].shift();
619+
});
620+
621+
var ctm = $('#chart_memory');
622+
var memoryData = [];
623+
var MemoryChart = new Chart(ctm, {
624+
type: 'line',
625+
data: {
626+
labels: timeLabels,
627+
datasets: [
628+
{
629+
label: "Memory Use",
630+
fill: false,
631+
lineTension: 0.03,
632+
backgroundColor: "#01A4A4",
633+
borderColor: "#01A4A4",
634+
borderCapStyle: 'butt',
635+
borderDash: [],
636+
borderDashOffset: 0.0,
637+
borderJoinStyle: 'miter',
638+
pointBorderColor: "rgba(75,192,192,1)",
639+
pointBackgroundColor: "#fff",
640+
pointBorderWidth: 1,
641+
pointHoverRadius: 5,
642+
pointHoverBackgroundColor: "rgba(75,192,192,1)",
643+
pointHoverBorderColor: "rgba(220,220,220,1)",
644+
pointHoverBorderWidth: 2,
645+
pointRadius: 1,
646+
pointHitRadius: 10,
647+
data: memoryData,
648+
spanGaps: false,
649+
}
650+
]
651+
},
652+
options: {
653+
title: {
654+
display: true,
655+
text: 'Memory Usage (in Megabytes)'
656+
},
657+
legend: {
658+
display: false,
659+
},
660+
animation: {
661+
duration: 1,
662+
}
639663
}
664+
});
640665
641-
memoryGraphSettings.data[0].push({
642-
'date': new Date(),
643-
'memory': parseInt(data.stats.memory / (1024 * 1024))
644-
});
666+
socket.on('live-stats', function (data) {
667+
if (cpuData.length > 10) {
668+
cpuData.shift();
669+
memoryData.shift();
670+
timeLabels.shift();
671+
}
645672
646-
cpuGraphSettings.data[0].push({
647-
'date': new Date(),
648-
'cpu': data.stats.cpu
649-
});
673+
cpuData.push(data.stats.cpu);
674+
memoryData.push(parseInt(data.stats.memory / (1024 * 1024)));
650675
651-
playersGraphSettings.data[0].push({
652-
'date': new Date(),
653-
'players': data.stats.players
654-
});
676+
var m = new Date();
677+
timeLabels.push($.format.date(new Date(), 'HH:MM:ss'));
655678
656-
MG.data_graphic(memoryGraphSettings);
657-
MG.data_graphic(cpuGraphSettings);
658-
MG.data_graphic(playersGraphSettings);
679+
CPUChart.update();
680+
MemoryChart.update();
659681
660682
$.each(data.servers, function (uuid, info) {
661683
var element = $('tr[data-server="' + uuid + '"]');

0 commit comments

Comments
 (0)