diff options
-rw-r--r-- | ogcp/templates/dashboard.html | 12 | ||||
-rw-r--r-- | ogcp/views.py | 40 |
2 files changed, 39 insertions, 13 deletions
diff --git a/ogcp/templates/dashboard.html b/ogcp/templates/dashboard.html index 257cfe3..bc89128 100644 --- a/ogcp/templates/dashboard.html +++ b/ogcp/templates/dashboard.html @@ -30,14 +30,22 @@ <td>{{ server.images | length }}</td> <td> {% set disk = server.disk %} + {% if disk['total'] != 0 %} {% set used = (((disk['total'] - disk['free']) / disk['total']) * 100)|int %} + {% else %} + {% set used = 0 %} + {% endif %} <div class="progress progress-lg"> <div class="progress-bar bg-primary" style="width: {{used}}%"></div> </div> </td> <td> {% set memory = server.stats.memory %} + {% if memory['size'] != 0 %} {% set used = (((memory['size'] - memory['free']) / memory['size']) * 100)|int %} + {% else %} + {% set used = 0 %} + {% endif %} <div class="progress progress-lg"> <div class="progress-bar bg-primary" style="width: {{used}}%"></div> </div> @@ -64,7 +72,7 @@ <hr /> <ul class="nav nav-tabs" id="serversTab" role="tablist"> -{% for id, server in servers.items() %} +{% for id, server in servers.items() if server.online %} <li class="nav-item" role="presentation"> <button class="nav-link {% if loop.first %}active{% endif %}" id="{{ id }}-tab" data-toggle="tab" data-target="#{{ id }}" type="button" role="tab" aria-controls="{{ id }}" aria-selected="true"> {{ server.name }} @@ -74,7 +82,7 @@ </ul> <div class="tab-content" id="serversTabContent"> -{% for id, server in servers.items() %} +{% for id, server in servers.items() if server.online %} {% set stats = server.stats %} {% set time_dict = server.time_dict %} {% set images = server.images %} diff --git a/ogcp/views.py b/ogcp/views.py index f0049fc..24df2e3 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -391,17 +391,35 @@ def index(): dashboard_servers[server_id]['oglive_list'] = i['json'] all_stats = multi_request('get', '/stats') - for i in all_stats: - server_id = i['server'].id - stats = i['json'] - dashboard_servers[server_id]['stats'] = stats - - timestamp = datetime.datetime.fromtimestamp(stats.get('time').get('now')) - now = timestamp.strftime('%Y-%m-%d %H:%M:%S') - boot = display_time(stats.get('time').get('boot')) - start = display_time(stats.get('time').get('start')) - time_dict = {'now': now, 'boot': boot, 'start': start} - dashboard_servers[server_id]['time_dict'] = time_dict + for server in servers: + active = False + stat = None + for i in all_stats: + if i['server'].id == server.id: + active = True + stat = i + break + if active: + server_id = stat['server'].id + dashboard_servers[server_id]['online'] = True + stats = stat['json'] + dashboard_servers[server_id]['stats'] = stats + timestamp = datetime.datetime.fromtimestamp(stats.get('time').get('now')) + now = timestamp.strftime('%Y-%m-%d %H:%M:%S') + boot = display_time(stats.get('time').get('boot')) + start = display_time(stats.get('time').get('start')) + time_dict = {'now': now, 'boot': boot, 'start': start} + dashboard_servers[server_id]['time_dict'] = time_dict + else: + dashboard_servers[server.id] = {} + dashboard_servers[server.id]['online'] = False + dashboard_servers[server.id]['name'] = server.name + dashboard_servers[server.id]['time_dict'] = {'now': None, 'boot': 'Offline', 'start': None} + dashboard_servers[server.id]['clients'] = [] + dashboard_servers[server.id]['images'] = [] + dashboard_servers[server.id]['disk'] = {'total': 0, 'free':0} + dashboard_servers[server.id]['stats'] = {'memory': {'free': 0, 'size':0}, 'swap': ''} + dashboard_servers[server.id]['oglive_list'] = [] clients_response = multi_request('get', '/clients') for i in clients_response: |