diff --git a/app/classes/minecraft/controller.py b/app/classes/minecraft/controller.py index 604239e1..e89f9e38 100644 --- a/app/classes/minecraft/controller.py +++ b/app/classes/minecraft/controller.py @@ -29,7 +29,24 @@ class Controller: servers = db_helper.get_all_defined_servers() for s in servers: + + # if this server path no longer exists - let's warn and bomb out + if not helper.check_path_exits(s['path']): + logger.warning("Unable to find server {} at path {}. Skipping this server".format(s['server_name'], + s['path'])) + + console.warning("Unable to find server {} at path {}. Skipping this server".format(s['server_name'], + s['path'])) + continue + settings_file = os.path.join(s['path'], 'server.properties') + + # if the properties file isn't there, let's warn + if not helper.check_file_exists(settings_file): + logger.error("Unable to find {}. Skipping this server.".format(settings_file)) + console.error("Unable to find {}. Skipping this server.".format(settings_file)) + continue + settings = ServerProps(settings_file) temp_server_dict = { diff --git a/app/classes/minecraft/stats.py b/app/classes/minecraft/stats.py index f2416385..a3ca363b 100644 --- a/app/classes/minecraft/stats.py +++ b/app/classes/minecraft/stats.py @@ -10,7 +10,7 @@ import datetime from app.classes.shared.helpers import helper from app.classes.minecraft.mc_ping import ping from app.classes.minecraft.controller import controller -from app.classes.shared.models import Host_Stats +from app.classes.shared.models import Host_Stats, Server_Stats logger = logging.getLogger(__name__) @@ -204,10 +204,10 @@ class Stats: return server_stats_list - # todo: add stats to db def record_stats(self): stats_to_send = self.get_node_stats() node_stats = stats_to_send.get('node_stats') + Host_Stats.insert({ Host_Stats.boot_time: node_stats.get('boot_time', "Unknown"), Host_Stats.cpu_usage: round(node_stats.get('cpu_usage', 0), 2), @@ -220,10 +220,27 @@ class Stats: Host_Stats.disk_json: node_stats.get('disk_data', '{}') }).execute() + server_stats = stats_to_send.get('servers') + + for server in server_stats: + Server_Stats.insert({ + Server_Stats.server_id: server.get('id', 0), + Server_Stats.started: server.get('started', ""), + Server_Stats.running: server.get('running', ""), + Server_Stats.cpu: server.get('cpu', ""), + Server_Stats.mem: server.get('mem', ""), + Server_Stats.world_name: server.get('world_name', ""), + Server_Stats.world_size: server.get('world_size', ""), + Server_Stats.server_port: server.get('server_port', ""), + Server_Stats.int_ping_results: server.get('int_ping_results', ""), + }).execute() + # delete 1 week old data max_age = int(helper.get_setting("CRAFTY", "history_max_age")) now = datetime.datetime.now() last_week = now.day - max_age + Host_Stats.delete().where(Host_Stats.time < last_week).execute() + Server_Stats.delete().where(Server_Stats.created < last_week).execute() stats = Stats() diff --git a/app/classes/shared/models.py b/app/classes/shared/models.py index c38d1f27..65729bb3 100644 --- a/app/classes/shared/models.py +++ b/app/classes/shared/models.py @@ -75,11 +75,27 @@ class Servers(BaseModel): stop_command = CharField(default="stop") server_port = IntegerField(default=25565) - class Meta: table_name = "servers" +class Server_Stats(BaseModel): + stats_id = AutoField() + created = DateTimeField(default=datetime.datetime.now) + server_id = ForeignKeyField(Servers, backref='server') + started = CharField(default="") + running = BooleanField(default=False) + cpu = FloatField(default=0) + mem = FloatField(default=0) + world_name = CharField(default="") + world_size = CharField(default="") + server_port = IntegerField(default=25565) + int_ping_results = CharField(default="") + + class Meta: + table_name = "server_stats" + + class Webhooks(BaseModel): id = AutoField() name = CharField(max_length=64, unique=True) @@ -113,6 +129,7 @@ class db_builder: Host_Stats, Webhooks, Servers, + Server_Stats ]) @staticmethod @@ -156,6 +173,10 @@ class db_shortcuts: query = Servers.select() return self.return_rows(query) + def get_all_servers_stats(self): + query = Server_Stats.select().order_by(Server_Stats.stats_id.desc()).limit(1) + return self.return_rows(query) + def get_latest_hosts_stats(self): query = Host_Stats.select().order_by(Host_Stats.id.desc()).get() return model_to_dict(query) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 5757dfbc..d0c31aa0 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -10,7 +10,6 @@ from app.classes.web.base_handler import BaseHandler from app.classes.minecraft.controller import controller from app.classes.shared.models import db_helper - logger = logging.getLogger(__name__) @@ -23,15 +22,17 @@ class PanelHandler(BaseHandler): template = "panel/denied.html" + defined_servers = controller.list_defined_servers() page_data = { 'version_data': "version_data_here", 'user_data': user_data, 'server_stats': { - 'total': len(controller.list_defined_servers()), + 'total': len(defined_servers), 'running': len(controller.list_running_servers()), 'stopped': (len(controller.list_defined_servers()) - len(controller.list_running_servers())) }, + 'menu_servers': defined_servers, 'hosts_data': db_helper.get_latest_hosts_stats() } @@ -46,9 +47,11 @@ class PanelHandler(BaseHandler): template = "panel/denied.html" elif page == 'dashboard': + page_data['servers'] = db_helper.get_all_servers_stats() + template = "panel/dashboard.html" self.render( template, data=page_data - ) \ No newline at end of file + ) diff --git a/app/classes/web/server_handler.py b/app/classes/web/server_handler.py index a161785f..2373d9ec 100644 --- a/app/classes/web/server_handler.py +++ b/app/classes/web/server_handler.py @@ -31,7 +31,6 @@ class ServerHandler(BaseHandler): template = "public/404.html" - page_data = { 'version_data': "version_data_here", 'user_data': user_data, diff --git a/app/frontend/templates/main_menu.html b/app/frontend/templates/main_menu.html index 39e52440..166fc217 100644 --- a/app/frontend/templates/main_menu.html +++ b/app/frontend/templates/main_menu.html @@ -21,21 +21,12 @@
diff --git a/app/frontend/templates/panel/dashboard.html b/app/frontend/templates/panel/dashboard.html index 34338c66..5fdd1eb9 100644 --- a/app/frontend/templates/panel/dashboard.html +++ b/app/frontend/templates/panel/dashboard.html @@ -44,8 +44,8 @@
-

{{ data['server_stats']['total'] }} {{_('Online')}}

-

{{ data['server_stats']['running'] }} {{_('Shutdown')}}

+

{{ data['server_stats']['running'] }} {{_('Online')}}

+

{{ data['server_stats']['stopped'] }} {{_('Shutdown')}}

@@ -94,144 +94,62 @@ Server + Actions CPU Memory - Disk + World Players Status - + {% for server in data['servers'] %} - Bedwarz + + + {{ server['server_id']['server_name'] }} + + + + + {% if server['started'] == True %} +   +   +   + {% else %} +   +   +   + {% end %} + +
-
+
+
+ + + +
+
-
-
-
+ {{ server['world_name'] }} : {{ server['world_size'] }} -
-
-
- - - 7 + {{ server['int_ping_results'] }} + {% if server['started'] == True %} Online + {% else %} + Offline + {% end %} - - - - Lobby - -
-
-
- - -
-
-
- - -
-
-
- - - 3 - - - Online - - - - - - Bedwarz - -
-
-
- - -
-
-
- - -
-
-
- - - 0 - - - Online - - - - - - Creative - -
-
-
- - -
-
-
- - -
-
-
- - - 5 - - - Online - - - - - - Survival - -
-
-
- - -
-
-
- - -
-
-
- - - 3 - - - Online - - + {% end %} @@ -241,6 +159,8 @@ + +