|
18 | 18 | <th></th> |
19 | 19 | @endif |
20 | 20 | <th>{{ trans('base.server_name') }}</th> |
21 | | - <th>{{ trans('strings.location') }}</th> |
22 | 21 | <th>{{ trans('strings.node') }}</th> |
23 | 22 | <th>{{ trans('strings.connection') }}</th> |
24 | | - <th></th> |
| 23 | + <th class="text-center">{{ trans('strings.players') }}</th> |
| 24 | + <th class="text-center">{{ trans('strings.memory') }}</th> |
| 25 | + <th class="text-center">{{ trans('strings.cpu') }}</th> |
| 26 | + <th class="text-center">{{ trans('strings.status') }}</th> |
25 | 27 | </tr> |
26 | 28 | </thead> |
27 | 29 | <tbody> |
28 | 30 | @foreach ($servers as $server) |
29 | | - <tr class="dynUpdate" id="{{ $server->uuidShort }}"> |
| 31 | + <tr class="dynUpdate" data-server="{{ $server->uuidShort }}"> |
30 | 32 | @if (Auth::user()->root_admin == 1) |
31 | 33 | <td style="width:26px;"> |
32 | 34 | @if ($server->owner === Auth::user()->id) |
|
37 | 39 | </td> |
38 | 40 | @endif |
39 | 41 | <td><a href="/server/{{ $server->uuidShort }}">{{ $server->name }}</a></td> |
40 | | - <td>{{ $server->location }}</td> |
41 | | - <td>{{ $server->nodeName }}</td> |
| 42 | + <td>{{ $server->nodeName }} ({{ $server->a_locationShort }})</td> |
42 | 43 | <td><code>{{ $server->ip }}:{{ $server->port }}</code></td> |
43 | | - <td style="width:26px;"><i class="fa fa-circle-o-notch fa-spinner fa-spin applyUpdate"></i></td> |
| 44 | + <td class="text-center" data-action="players">--</td> |
| 45 | + <td class="text-center"><span data-action="memory">--</span> / {{ $server->memory }} MB</td> |
| 46 | + <td class="text-center"><span data-action="cpu" data-cpumax="{{ $server->cpu }}">--</span> %</td> |
| 47 | + <td class="text-center" data-action="status">--</td> |
44 | 48 | </tr> |
45 | 49 | @endforeach |
46 | 50 | </tbody> |
47 | 51 | </table> |
| 52 | + <div class="row"> |
| 53 | + <div class="col-md-12 text-center">{!! $servers->render() !!}</div> |
| 54 | + </div> |
48 | 55 | @else |
49 | 56 | <div class="alert alert-info">{{ trans('base.no_servers') }}</div> |
50 | 57 | @endif |
|
53 | 60 | $(window).load(function () { |
54 | 61 | $('#sidebar_links').find('a[href=\'/\']').addClass('active'); |
55 | 62 | function updateServerStatus () { |
| 63 | + var Status = { |
| 64 | + 0: 'Off', |
| 65 | + 1: 'On', |
| 66 | + 2: 'Starting', |
| 67 | + 3: 'Stopping' |
| 68 | + }; |
56 | 69 | $('.dynUpdate').each(function (index, data) { |
57 | | -
|
58 | 70 | var element = $(this); |
59 | | - var serverShortUUID = $(this).attr('id'); |
60 | | - var updateElement = $(this).find('.applyUpdate'); |
61 | | -
|
62 | | - updateElement.removeClass('fa-check-circle fa-times-circle').css({ color: '#000' }); |
63 | | - updateElement.addClass('fa-circle-o-notch fa-spinner fa-spin'); |
64 | | -
|
| 71 | + var serverShortUUID = $(this).data('server'); |
65 | 72 | $.ajax({ |
66 | 73 | type: 'GET', |
67 | 74 | url: '/server/' + serverShortUUID + '/ajax/status', |
68 | | - timeout: 10000 |
| 75 | + headers: { |
| 76 | + 'X-CSRF-TOKEN': '{{ csrf_token() }}' |
| 77 | + } |
69 | 78 | }).done(function (data) { |
70 | | -
|
71 | | - var selector = (data == 'true') ? 'fa-check-circle' : 'fa-times-circle'; |
72 | | - var selectorColor = (data == 'true') ? 'rgb(83, 179, 12)' : 'rgb(227, 50, 0)'; |
73 | | -
|
74 | | - updateElement.removeClass('fa-circle-o-notch fa-spinner fa-spin'); |
75 | | - updateElement.addClass(selector).css({ color: selectorColor }); |
76 | | -
|
| 79 | + if (typeof data.status === 'undefined') { |
| 80 | + return; |
| 81 | + } |
| 82 | + element.find('[data-action="status"]').html(Status[data.status]); |
| 83 | + if (data.status !== 0) { |
| 84 | + var cpuMax = element.find('[data-action="cpu"]').data('cpumax'); |
| 85 | + var currentCpu = data.proc.cpu.total; |
| 86 | + if (cpuMax !== 0) { |
| 87 | + currentCpu = parseFloat(((data.proc.cpu.total / cpuMax) * 100).toFixed(2).toString()); |
| 88 | + } |
| 89 | + element.find('[data-action="memory"]').html(parseInt(data.proc.memory.total / (1024 * 1024))); |
| 90 | + element.find('[data-action="cpu"]').html(currentCpu); |
| 91 | + element.find('[data-action="players"]').html(data.query.players.length); |
| 92 | + } else { |
| 93 | + element.find('[data-action="memory"]').html('--'); |
| 94 | + element.find('[data-action="cpu"]').html('--'); |
| 95 | + element.find('[data-action="players"]').html('--'); |
| 96 | + } |
77 | 97 | }).fail(function (jqXHR) { |
78 | | -
|
| 98 | + console.error(jqXHR); |
79 | 99 | updateElement.removeClass('fa-circle-o-notch fa-spinner fa-spin'); |
80 | 100 | updateElement.addClass('fa-question-circle').css({ color: 'rgb(227, 50, 0)' }); |
81 | | -
|
82 | 101 | }); |
83 | 102 |
|
84 | 103 | }); |
85 | 104 | } |
86 | 105 | updateServerStatus(); |
87 | | - setInterval(updateServerStatus, 30000); |
| 106 | + setInterval(updateServerStatus, 10000); |
88 | 107 | }); |
89 | 108 | </script> |
90 | 109 | @endsection |
0 commit comments