2013-10-10 18:02:21 +02:00
|
|
|
package mineplex.servermonitor;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
2013-11-05 19:19:04 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
2013-11-02 08:56:31 +01:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2013-10-10 18:02:21 +02:00
|
|
|
|
|
|
|
public class ServerMonitor
|
|
|
|
{
|
|
|
|
private static Repository _repository = new Repository();
|
2013-10-15 23:19:14 +02:00
|
|
|
private static int _count = 0;
|
2013-10-10 18:02:21 +02:00
|
|
|
|
|
|
|
public static void main (String args[])
|
|
|
|
{
|
|
|
|
_repository.initialize();
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2013-11-02 08:56:31 +01:00
|
|
|
/*
|
2013-10-15 23:19:14 +02:00
|
|
|
if (_count % 20 == 0)
|
2013-10-10 18:02:21 +02:00
|
|
|
{
|
2013-10-15 23:19:14 +02:00
|
|
|
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
|
|
|
|
{
|
|
|
|
String key = statusData.Address + " " + statusData.Name;
|
|
|
|
|
|
|
|
String cmd = "/home/mineplex/restartServer.sh";
|
|
|
|
Process process = null;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
process = new ProcessBuilder(new String[] {"/bin/sh", "-x", cmd, statusData.Address, statusData.Name}).start();
|
|
|
|
process.waitFor();
|
|
|
|
BufferedReader reader=new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
|
String line = reader.readLine();
|
|
|
|
|
|
|
|
while(line != null)
|
|
|
|
{
|
|
|
|
System.out.println(line);
|
|
|
|
line=reader.readLine();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
if (process != null)
|
|
|
|
{
|
|
|
|
process.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println("Sent restart command to " + key + "");
|
|
|
|
}
|
|
|
|
}
|
2013-11-02 08:56:31 +01:00
|
|
|
*/
|
2013-10-15 23:19:14 +02:00
|
|
|
if (_count % 10 == 0)
|
|
|
|
{
|
2013-11-05 19:19:04 +01:00
|
|
|
Collection<DynamicServerData> dynamicServers = _repository.retrieveDynamicServers();
|
|
|
|
List<ServerTargetData> targetList = new ArrayList<ServerTargetData>();
|
|
|
|
HashMap<String, GroupStatusData> groupStatusList = _repository.retrieveGroupStatusData();
|
2013-11-02 08:56:31 +01:00
|
|
|
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-10-15 23:19:14 +02:00
|
|
|
Thread.sleep(1000);
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
|
|
|
catch (InterruptedException e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2013-10-15 23:19:14 +02:00
|
|
|
|
|
|
|
_count++;
|
|
|
|
_count %= 20;
|
2013-10-10 18:02:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|