From ef0d23351251a8670852ba617975c5de16332f9d Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Fri, 8 Nov 2013 14:46:05 -0800 Subject: [PATCH] Dynamic server tinkering again. --- .../src/mineplex/servermonitor/DynamicServerData.java | 2 +- .../src/mineplex/servermonitor/Repository.java | 8 +++++--- .../src/mineplex/servermonitor/ServerMonitor.java | 6 ++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/DynamicServerData.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/DynamicServerData.java index 9c8674cd9..483cbfc36 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/DynamicServerData.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/DynamicServerData.java @@ -7,7 +7,7 @@ public class DynamicServerData public String Name; public String Address; public int AvailableCPU = 32; - public int AvailableRAM = 26624; + public int AvailableRAM = 14000; public HashMap ServerGroupCount = new HashMap(); public boolean US; diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/Repository.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/Repository.java index 6076489f3..0266f9382 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/Repository.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/Repository.java @@ -20,7 +20,7 @@ public class Repository private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT ServerStatus.serverName, ServerStatus.address, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;"; private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));"; - private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.US, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;"; + private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false GROUP BY DynamicServers.address, ServerStatus.serverGroup;"; private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, ServerStatus.address, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = false AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) <= 10"; private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;"; private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND serverName = ?;"; @@ -318,13 +318,15 @@ public class Repository dynamicServer.Name = resultSet.getString(1); dynamicServer.Address = resultSet.getString(2); dynamicServer.US = resultSet.getBoolean(3); + dynamicServer.AvailableCPU = resultSet.getInt(4); + dynamicServer.AvailableRAM = resultSet.getInt(5); if (!serverMap.containsKey(dynamicServer.Name)) serverMap.put(dynamicServer.Name, dynamicServer); - String serverGroupName = resultSet.getString(4); + String serverGroupName = resultSet.getString(6); if (serverGroupMap.containsKey(serverGroupName)) - serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(5)); + serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(7)); } } catch (Exception exception) diff --git a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java index 63618d27c..2f5bda607 100644 --- a/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java +++ b/Plugins/Mineplex.ServerMonitor/src/mineplex/servermonitor/ServerMonitor.java @@ -92,6 +92,8 @@ public class ServerMonitor for (DynamicServerData serverData : dynamicServers) { + System.out.println("Checking " + serverData.Name + " Cpu:" + serverData.AvailableCPU + " Ram:" + serverData.AvailableRAM); + if (serverData.AvailableRAM > serverGroup.RequiredRAM && serverData.AvailableCPU > serverGroup.RequiredCPU) { if (bestServer == null) @@ -119,7 +121,7 @@ public class ServerMonitor try { - process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, serverToKill.Address, serverToKill.Name}).start(); + process = new ProcessBuilder(new String[] {"/bin/sh", cmd, serverToKill.Address, serverToKill.Name}).start(); process.waitFor(); BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream())); String line = reader.readLine(); @@ -177,6 +179,6 @@ public class ServerMonitor } serverSpace.setServerGroupCount(serverGroup, serverSpace.ServerGroupCount.containsKey(serverGroup.Name) ? (serverSpace.ServerGroupCount.get(serverGroup.Name) + 1) : 1); - System.out.println("Sent start command to " + serverSpace.Name + " for " + serverGroup.Prefix + "-" + serverNum); + System.out.println("Sent start command (" + serverSpace.Address + "," + serverGroup.ScriptName + "," + serverGroup.Prefix + "-" + serverNum + ", 1," + (serverSpace.US ? "us" : "eu") + ")"); } }