|
25 | 25 |
|
26 | 26 | @section('scripts') |
27 | 27 | @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') !!} |
31 | 28 | {!! Theme::js('js/vendor/socketio/socket.io.min.js') !!} |
32 | 29 | {!! 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') !!} |
33 | 32 | <script> |
34 | 33 | $(document).ready(function () { |
35 | 34 | $.notifyDefaults({ |
|
102 | 101 | <div class="panel-heading" style="border-top: 1px solid #ddd;"></div> |
103 | 102 | <div class="panel-body"> |
104 | 103 | <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> |
108 | 106 | </div> |
109 | 107 | </div> |
110 | 108 | </div> |
|
545 | 543 | 3: 'Stopping' |
546 | 544 | }; |
547 | 545 |
|
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 | | -
|
600 | 546 | // Main Socket Object |
601 | 547 | var socket = io('{{ $node->scheme }}://{{ $node->fqdn }}:{{ $node->daemonListen }}/stats/', { |
602 | 548 | 'query': 'token={{ $node->daemonSecret }}' |
|
626 | 572 | console.error('There was an error while attemping to connect to the websocket: ' + err + '\n\nPlease try loading this page again.'); |
627 | 573 | }); |
628 | 574 |
|
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 | + } |
636 | 618 | } |
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 | + } |
639 | 663 | } |
| 664 | + }); |
640 | 665 |
|
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 | + } |
645 | 672 |
|
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))); |
650 | 675 |
|
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')); |
655 | 678 |
|
656 | | - MG.data_graphic(memoryGraphSettings); |
657 | | - MG.data_graphic(cpuGraphSettings); |
658 | | - MG.data_graphic(playersGraphSettings); |
| 679 | + CPUChart.update(); |
| 680 | + MemoryChart.update(); |
659 | 681 |
|
660 | 682 | $.each(data.servers, function (uuid, info) { |
661 | 683 | var element = $('tr[data-server="' + uuid + '"]'); |
|
0 commit comments