ServerMonitor tweaks.
This commit is contained in:
parent
e27f01e916
commit
7cc880afd1
@ -92,6 +92,7 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
plugin.getConfig().getString("serverstatus.connectionurl"),
|
plugin.getConfig().getString("serverstatus.connectionurl"),
|
||||||
plugin.getConfig().getString("serverstatus.username"),
|
plugin.getConfig().getString("serverstatus.username"),
|
||||||
plugin.getConfig().getString("serverstatus.password"),
|
plugin.getConfig().getString("serverstatus.password"),
|
||||||
|
plugin.getConfig().getBoolean("serverstatus.us"),
|
||||||
_name,
|
_name,
|
||||||
plugin.getConfig().getString("serverstatus.group"),
|
plugin.getConfig().getString("serverstatus.group"),
|
||||||
address + ":" + _plugin.getServer().getPort(), event.getMaxPlayers()
|
address + ":" + _plugin.getServer().getPort(), event.getMaxPlayers()
|
||||||
@ -119,6 +120,9 @@ public class ServerStatusManager extends MiniPlugin
|
|||||||
GetPlugin().getConfig().addDefault("serverstatus.password", "tAbechAk3wR7tuTh");
|
GetPlugin().getConfig().addDefault("serverstatus.password", "tAbechAk3wR7tuTh");
|
||||||
GetPlugin().getConfig().set("serverstatus.password", GetPlugin().getConfig().getString("serverstatus.password"));
|
GetPlugin().getConfig().set("serverstatus.password", GetPlugin().getConfig().getString("serverstatus.password"));
|
||||||
|
|
||||||
|
GetPlugin().getConfig().addDefault("serverstatus.us", true);
|
||||||
|
GetPlugin().getConfig().set("serverstatus.us", GetPlugin().getConfig().getBoolean("serverstatus.us"));
|
||||||
|
|
||||||
GetPlugin().getConfig().addDefault("serverstatus.name", "TEST-1");
|
GetPlugin().getConfig().addDefault("serverstatus.name", "TEST-1");
|
||||||
GetPlugin().getConfig().set("serverstatus.name", GetPlugin().getConfig().getString("serverstatus.name"));
|
GetPlugin().getConfig().set("serverstatus.name", GetPlugin().getConfig().getString("serverstatus.name"));
|
||||||
|
|
||||||
|
@ -20,19 +20,21 @@ public class ServerStatusRepository
|
|||||||
private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;";
|
private static String UPDATE_PLAYER_COUNT_WITH_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ?, lastTimeWithPlayers = now() WHERE id = ?;";
|
||||||
private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
|
private static String UPDATE_PLAYER_COUNT_WITHOUT_PLAYERS = "UPDATE ServerStatus SET updated = now(), serverName = ?, serverGroup = ?, motd = ?, players = ?, maxPlayers = ?, tps = ?, ram = ?, maxRam = ? WHERE id = ?;";
|
||||||
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;";
|
private static String RETRIEVE_ID = "SELECT id FROM ServerStatus WHERE address = ?;";
|
||||||
private static String RETRIEVE_SERVER_STATUSES = "SELECT serverName, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = 'true' AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
private static String RETRIEVE_SERVER_STATUSES = "SELECT ServerStatus.serverName, motd, players, maxPlayers FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address LIKE CONCAT(DynamicServers.address, '%') WHERE DynamicServers.US = ? AND TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) < 10;";
|
||||||
|
|
||||||
private int _id = -1;
|
private int _id = -1;
|
||||||
|
private boolean _us;
|
||||||
private String _serverName;
|
private String _serverName;
|
||||||
private String _serverGroup;
|
private String _serverGroup;
|
||||||
private String _address;
|
private String _address;
|
||||||
private int _maxPlayers = 0;
|
private int _maxPlayers = 0;
|
||||||
|
|
||||||
public ServerStatusRepository(String connectionUrl, String username, String password, String serverName, String serverGroup, String address, int maxPlayers)
|
public ServerStatusRepository(String connectionUrl, String username, String password, boolean us, String serverName, String serverGroup, String address, int maxPlayers)
|
||||||
{
|
{
|
||||||
_connectionString = connectionUrl;
|
_connectionString = connectionUrl;
|
||||||
_userName = username;
|
_userName = username;
|
||||||
_password = password;
|
_password = password;
|
||||||
|
_us = us;
|
||||||
_serverName = serverName;
|
_serverName = serverName;
|
||||||
_serverGroup = serverGroup;
|
_serverGroup = serverGroup;
|
||||||
_address = address;
|
_address = address;
|
||||||
@ -240,6 +242,8 @@ public class ServerStatusRepository
|
|||||||
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
connection = DriverManager.getConnection(_connectionString, _userName, _password);
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
|
preparedStatement = connection.prepareStatement(RETRIEVE_SERVER_STATUSES);
|
||||||
|
preparedStatement.setBoolean(1, _us);
|
||||||
|
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
while (resultSet.next())
|
while (resultSet.next())
|
||||||
|
@ -10,6 +10,7 @@ public class DynamicServerData
|
|||||||
public int AvailableRAM = 26624;
|
public int AvailableRAM = 26624;
|
||||||
|
|
||||||
public HashMap<String, Integer> ServerGroupCount = new HashMap<String, Integer>();
|
public HashMap<String, Integer> ServerGroupCount = new HashMap<String, Integer>();
|
||||||
|
public boolean US;
|
||||||
|
|
||||||
public void setServerGroupCount(ServerGroupData groupData, int count)
|
public void setServerGroupCount(ServerGroupData groupData, int count)
|
||||||
{
|
{
|
||||||
|
@ -19,7 +19,7 @@ public class GroupStatusData
|
|||||||
Players += serverStatusData.Players;
|
Players += serverStatusData.Players;
|
||||||
MaxPlayers += serverStatusData.MaxPlayers;
|
MaxPlayers += serverStatusData.MaxPlayers;
|
||||||
|
|
||||||
if (serverStatusData.Motd.contains("Starting") || serverStatusData.Motd.contains("Recruiting") || serverStatusData.Motd.contains("Waiting") || serverStatusData.Motd.contains("Cup") || serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
|
if (serverStatusData.Motd != null && (serverStatusData.Motd.contains("Starting") || serverStatusData.Motd.contains("Recruiting") || serverStatusData.Motd.contains("Waiting") || serverStatusData.Motd.contains("Cup") || serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals("")))
|
||||||
{
|
{
|
||||||
if (serverStatusData.Players < serverStatusData.MaxPlayers)
|
if (serverStatusData.Players < serverStatusData.MaxPlayers)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,6 @@ import java.sql.DriverManager;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -21,8 +20,8 @@ public class Repository
|
|||||||
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT serverName, address, motd, players, maxPlayers FROM ServerStatus WHERE TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.updated)) > 10;";
|
private static String RETRIEVE_OLD_SERVER_STATUSES = "SELECT serverName, address, motd, players, maxPlayers FROM ServerStatus WHERE 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 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, 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, 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, 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_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 RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
|
||||||
|
|
||||||
|
|
||||||
@ -213,11 +212,12 @@ public class Repository
|
|||||||
|
|
||||||
serverStatusData.Name = resultSet.getString(1);
|
serverStatusData.Name = resultSet.getString(1);
|
||||||
String serverGroup = resultSet.getString(2);
|
String serverGroup = resultSet.getString(2);
|
||||||
String addressPortString = resultSet.getString(3);
|
serverStatusData.Motd = resultSet.getString(3);
|
||||||
|
String addressPortString = resultSet.getString(4);
|
||||||
serverStatusData.Address = addressPortString.split(":")[0];
|
serverStatusData.Address = addressPortString.split(":")[0];
|
||||||
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]);
|
serverStatusData.Port = Integer.parseInt(addressPortString.split(":")[1]);
|
||||||
serverStatusData.Players = resultSet.getInt(4);
|
serverStatusData.Players = resultSet.getInt(5);
|
||||||
serverStatusData.MaxPlayers = resultSet.getInt(5);
|
serverStatusData.MaxPlayers = resultSet.getInt(6);
|
||||||
serverStatusData.Empty = resultSet.getBoolean(7);
|
serverStatusData.Empty = resultSet.getBoolean(7);
|
||||||
|
|
||||||
if (!groupData.containsKey(serverGroup))
|
if (!groupData.containsKey(serverGroup))
|
||||||
@ -305,6 +305,9 @@ public class Repository
|
|||||||
serverGroupMap.put(serverGroupData.Name, serverGroupData);
|
serverGroupMap.put(serverGroupData.Name, serverGroupData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preparedStatement.close();
|
||||||
|
resultSet.close();
|
||||||
|
|
||||||
preparedStatement = connection.prepareStatement(RETRIEVE_AVAILABLE_SERVERS);
|
preparedStatement = connection.prepareStatement(RETRIEVE_AVAILABLE_SERVERS);
|
||||||
resultSet = preparedStatement.executeQuery();
|
resultSet = preparedStatement.executeQuery();
|
||||||
|
|
||||||
@ -314,13 +317,14 @@ public class Repository
|
|||||||
|
|
||||||
dynamicServer.Name = resultSet.getString(1);
|
dynamicServer.Name = resultSet.getString(1);
|
||||||
dynamicServer.Address = resultSet.getString(2);
|
dynamicServer.Address = resultSet.getString(2);
|
||||||
|
dynamicServer.US = resultSet.getBoolean(3);
|
||||||
|
|
||||||
if (!serverMap.containsKey(dynamicServer.Name))
|
if (!serverMap.containsKey(dynamicServer.Name))
|
||||||
serverMap.put(dynamicServer.Name, dynamicServer);
|
serverMap.put(dynamicServer.Name, dynamicServer);
|
||||||
|
|
||||||
String serverGroupName = resultSet.getString(3);
|
String serverGroupName = resultSet.getString(4);
|
||||||
if (serverGroupMap.containsKey(serverGroupName))
|
if (serverGroupMap.containsKey(serverGroupName))
|
||||||
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(4));
|
serverMap.get(dynamicServer.Name).setServerGroupCount(serverGroupMap.get(serverGroupName), resultSet.getInt(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -99,7 +99,7 @@ public class ServerMonitor
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, bestServer.Address, serverGroup.ScriptName, serverGroup.Prefix + "-" + serverNum, "1"}).start();
|
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, bestServer.Address, serverGroup.ScriptName, serverGroup.Prefix + "-" + serverNum, "1", bestServer.US + ""}).start();
|
||||||
process.waitFor();
|
process.waitFor();
|
||||||
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
String line = reader.readLine();
|
String line = reader.readLine();
|
||||||
|
Loading…
Reference in New Issue
Block a user