enhancements
This commit is contained in:
parent
9641f9dd96
commit
33abcaccc5
@ -12,18 +12,22 @@ import com.googlecode.lanterna.screen.Screen;
|
||||
import com.googlecode.lanterna.screen.TerminalScreen;
|
||||
import com.googlecode.lanterna.terminal.DefaultTerminalFactory;
|
||||
import com.googlecode.lanterna.terminal.Terminal;
|
||||
import com.googlecode.lanterna.terminal.swing.SwingTerminalFrame;
|
||||
import de.gurkengewuerz.monitoring.object.MassCommand;
|
||||
import de.gurkengewuerz.monitoring.object.Server;
|
||||
import de.gurkengewuerz.monitoring.object.ServerStatus;
|
||||
import org.apache.commons.validator.routines.InetAddressValidator;
|
||||
import org.pmw.tinylog.Logger;
|
||||
import org.sqlite.date.DateFormatUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@ -36,13 +40,34 @@ import java.util.List;
|
||||
* Created by gurkengewuerz.de on 21.10.2017.
|
||||
*/
|
||||
public class GUI {
|
||||
|
||||
private HashMap<String, Server> serverlist;
|
||||
|
||||
public GUI() {
|
||||
HashMap<String, Server> serverlist = Server.getServerList(StartUp.getDb());
|
||||
serverlist = Server.getServerList(StartUp.getDb());
|
||||
Poller poller = new Poller();
|
||||
try {
|
||||
Terminal terminal = new DefaultTerminalFactory()
|
||||
.setTerminalEmulatorTitle("Servermanagment").createTerminal();
|
||||
//TODO: Set GUI Icon
|
||||
if (terminal instanceof SwingTerminalFrame) {
|
||||
SwingTerminalFrame frame = (SwingTerminalFrame) terminal;
|
||||
URL iconURL = getClass().getResource("/icon.png");
|
||||
frame.setIconImage(new ImageIcon(iconURL).getImage());
|
||||
|
||||
frame.setSize(930, 500);
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent e) {
|
||||
poller.stop();
|
||||
StartUp.getDb().closeConnection();
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
|
||||
frame.repaint();
|
||||
}
|
||||
terminal.flush();
|
||||
|
||||
Screen screen = new TerminalScreen(terminal);
|
||||
screen.startScreen();
|
||||
|
||||
@ -125,7 +150,7 @@ public class GUI {
|
||||
}
|
||||
}).addTo(rightPanel).takeFocus();
|
||||
|
||||
new Button("Alle auswählen", () -> checkBoxList.getItems().forEach(s -> checkBoxList.setChecked(s, true))).addTo(rightPanel);
|
||||
new Button("Alle auswählen", () -> checkBoxList.getItems().forEach(s -> checkBoxList.setChecked(s, !checkBoxList.isChecked(s)))).addTo(rightPanel);
|
||||
|
||||
new Button("Aktion ausführen", () -> {
|
||||
List<String> checkedItems = checkBoxList.getCheckedItems();
|
||||
@ -140,7 +165,7 @@ public class GUI {
|
||||
new ActionListDialogBuilder()
|
||||
.setTitle("Aktion ausführen")
|
||||
.setDescription("Was möchtest du unternhmen")
|
||||
.addAction("Server löschen", () -> {
|
||||
.addAction("Löschen", () -> {
|
||||
try {
|
||||
PreparedStatement ps = StartUp.getDb().getPreparedStatement("DELETE FROM server WHERE id = ?");
|
||||
serverarray.forEach(server -> {
|
||||
@ -158,12 +183,13 @@ public class GUI {
|
||||
}
|
||||
updateList(checkBoxList, serverlist);
|
||||
})
|
||||
.addAction("Server Status", () -> {
|
||||
.addAction("Info", () -> serverarray.forEach(server -> MessageDialog.showMessageDialog(gui, server.getName(), server.toString(), MessageDialogButton.OK)))
|
||||
.addAction("Status", () -> {
|
||||
BasicWindow windowStatus = getStatusWindow(checkBoxList, serverlist);
|
||||
gui.addWindow(windowStatus);
|
||||
gui.setActiveWindow(windowStatus);
|
||||
})
|
||||
.addAction("Server updaten", () -> MassCommand.run("apt-get update && apt-get upgrade -y", gui, serverarray, StartUp.getPrivate_key()))
|
||||
.addAction("Updaten", () -> MassCommand.run("apt-get update && apt-get upgrade -y", gui, serverarray, StartUp.getPrivate_key()))
|
||||
.addAction("Herunterfahren", () -> MassCommand.run("shutdown -h now", gui, serverarray, StartUp.getPrivate_key()))
|
||||
.addAction("Neustart", () -> MassCommand.run("reboot", gui, serverarray, StartUp.getPrivate_key()))
|
||||
.build()
|
||||
@ -171,7 +197,7 @@ public class GUI {
|
||||
}).addTo(rightPanel);
|
||||
|
||||
new Button("Aktualisieren", () -> {
|
||||
// TODO: serverlist = Server.getServerList(db);
|
||||
serverlist = Server.getServerList(StartUp.getDb());
|
||||
updateList(checkBoxList, serverlist);
|
||||
}).addTo(rightPanel);
|
||||
|
||||
@ -182,7 +208,7 @@ public class GUI {
|
||||
}).addTo(rightPanel);
|
||||
|
||||
screen.setCursorPosition(null);
|
||||
|
||||
screen.doResizeIfNecessary();
|
||||
gui.addWindowAndWait(window);
|
||||
} catch (IOException e) {
|
||||
Logger.error(e);
|
||||
@ -224,7 +250,7 @@ public class GUI {
|
||||
|
||||
table.getTableModel().addRow(server.getName(),
|
||||
status.getOS(), status.getCPUcount() + "x " + status.getCPUModel(),
|
||||
freeMB + "MB/" + totalMB + "MB", DateFormatUtils.format(status.getUptime() * 1000, "HH:mm:ss"),
|
||||
freeMB + "MB/" + totalMB + "MB", status.getUptimeFormatted(),
|
||||
String.valueOf(status.getLoad()), status.getState().toString());
|
||||
}
|
||||
// "Name", "OS", "CPU", "RAM", "Uptime", "Last", "Status"
|
||||
|
@ -58,6 +58,26 @@ public class Server {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getAddedFormatted() {
|
||||
return ServerStatus.getDate(timeAdded, "HH:mm:ss");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " (#" + id + ")" + "\n" +
|
||||
"------------------" + "\n" +
|
||||
"Server: " + username + "@" + ip + ":" + port + "\n" +
|
||||
"Hinzugefügt am: " + getAddedFormatted() + "\n" +
|
||||
"OS: " + status.getOS() + "\n" +
|
||||
"CPU Model: " + status.getCPUModel() + "\n" +
|
||||
"Kerne: " + status.getCPUcount() + "\n" +
|
||||
"Memory: " + status.getMemFree() + "kb/" + status.getMemTotal() + "kb\n" +
|
||||
"Last: " + status.getLoad() + "\n" +
|
||||
"Uptime: " + status.getUptimeFormatted() + "\n" +
|
||||
"Letzte Aktueallisierung: " + status.getLastPollFormatted() + "\n" +
|
||||
"Status: " + status.getState().toString();
|
||||
}
|
||||
|
||||
public SSHManager getSSHSession(String ssh_private) {
|
||||
SSHManager instance = new SSHManager(getUsername(), ssh_private, ip, "", port);
|
||||
String errorMessage = instance.connect();
|
||||
|
@ -1,5 +1,10 @@
|
||||
package de.gurkengewuerz.monitoring.object;
|
||||
|
||||
import org.sqlite.date.DateFormatUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
/**
|
||||
* Created by gurkengewuerz.de on 21.10.2017.
|
||||
*/
|
||||
@ -56,7 +61,7 @@ public class ServerStatus {
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return state;
|
||||
return state == null ? State.OFFLINE : state;
|
||||
}
|
||||
|
||||
public long getLastpoll() {
|
||||
@ -98,4 +103,23 @@ public class ServerStatus {
|
||||
public void setLastpoll(long lastpoll) {
|
||||
this.lastpoll = lastpoll;
|
||||
}
|
||||
|
||||
public String getUptimeFormatted() {
|
||||
return DateFormatUtils.format(uptime * 1000, "HH:mm:ss");
|
||||
}
|
||||
|
||||
public String getLastPollFormatted() {
|
||||
return getDate(lastpoll, "dd.MM.yyyy HH:MM:ss");
|
||||
}
|
||||
|
||||
|
||||
public static String getDate(long milliSeconds, String dateFormat) {
|
||||
// Create a DateFormatter object for displaying date in specified format.
|
||||
SimpleDateFormat formatter = new SimpleDateFormat(dateFormat);
|
||||
|
||||
// Create a calendar object that will convert the date and time value in milliseconds to date.
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(milliSeconds);
|
||||
return formatter.format(calendar.getTime());
|
||||
}
|
||||
}
|
||||
|
BIN
src/main/resources/icon.png
Normal file
BIN
src/main/resources/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
Loading…
Reference in New Issue
Block a user