110 lines
4.2 KiB
Java
110 lines
4.2 KiB
Java
package de.serverpulse.bungee.models;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Hält alle empfangenen Monitoring-Daten eines einzelnen Sub-Servers.
|
|
* Wird über den Plugin Messaging Channel vom Spigot-Plugin befüllt.
|
|
*/
|
|
public class ServerData {
|
|
|
|
private final String serverName;
|
|
|
|
// Performance
|
|
private double tps = 20.0;
|
|
private double mspt = 0.0;
|
|
private long ramUsedMb = 0;
|
|
private long ramMaxMb = 0;
|
|
private double ramPercent = 0.0;
|
|
|
|
// Spieler
|
|
private int onlinePlayers = 0;
|
|
private int loadedChunks = 0;
|
|
|
|
// Entities (Welt → Kategorie → Anzahl)
|
|
private Map<String, Map<String, Integer>> entityData = new HashMap<>();
|
|
|
|
// Alerts (letzte X Alerts des Servers)
|
|
private String lastAlert = "";
|
|
private String lastAlertSeverity = "";
|
|
|
|
// Timestamps
|
|
private LocalDateTime lastUpdate = null;
|
|
private LocalDateTime connectedSince = LocalDateTime.now();
|
|
|
|
// Status
|
|
private boolean online = false;
|
|
|
|
public ServerData(String serverName) {
|
|
this.serverName = serverName;
|
|
}
|
|
|
|
// ── Performance ──────────────────────────
|
|
public void updatePerformance(double tps, double mspt,
|
|
long ramUsedMb, long ramMaxMb,
|
|
double ramPercent, int onlinePlayers, int loadedChunks) {
|
|
this.tps = tps;
|
|
this.mspt = mspt;
|
|
this.ramUsedMb = ramUsedMb;
|
|
this.ramMaxMb = ramMaxMb;
|
|
this.ramPercent = ramPercent;
|
|
this.onlinePlayers = onlinePlayers;
|
|
this.loadedChunks = loadedChunks;
|
|
this.lastUpdate = LocalDateTime.now();
|
|
this.online = true;
|
|
}
|
|
|
|
// ── Entity-Daten ─────────────────────────
|
|
public void updateEntityData(String worldName, int monsters, int animals,
|
|
int waterMobs, int villagers, int armorStands,
|
|
int hopperMinecarts, int items, int players,
|
|
int other, int total) {
|
|
Map<String, Integer> worldEntities = new HashMap<>();
|
|
worldEntities.put("monsters", monsters);
|
|
worldEntities.put("animals", animals);
|
|
worldEntities.put("water_mobs", waterMobs);
|
|
worldEntities.put("villagers", villagers);
|
|
worldEntities.put("armor_stands", armorStands);
|
|
worldEntities.put("hopper_minecarts", hopperMinecarts);
|
|
worldEntities.put("items", items);
|
|
worldEntities.put("players", players);
|
|
worldEntities.put("other", other);
|
|
worldEntities.put("total", total);
|
|
this.entityData.put(worldName, worldEntities);
|
|
}
|
|
|
|
// ── Alert ────────────────────────────────
|
|
public void updateAlert(String message, String severity) {
|
|
this.lastAlert = message;
|
|
this.lastAlertSeverity = severity;
|
|
}
|
|
|
|
public void markOffline() {
|
|
this.online = false;
|
|
}
|
|
|
|
// ── Getter ───────────────────────────────
|
|
public String getServerName() { return serverName; }
|
|
public double getTps() { return tps; }
|
|
public double getMspt() { return mspt; }
|
|
public long getRamUsedMb() { return ramUsedMb; }
|
|
public long getRamMaxMb() { return ramMaxMb; }
|
|
public double getRamPercent() { return ramPercent; }
|
|
public int getOnlinePlayers() { return onlinePlayers; }
|
|
public int getLoadedChunks() { return loadedChunks; }
|
|
public Map<String, Map<String, Integer>> getEntityData() { return entityData; }
|
|
public String getLastAlert() { return lastAlert; }
|
|
public String getLastAlertSeverity() { return lastAlertSeverity; }
|
|
public LocalDateTime getLastUpdate() { return lastUpdate; }
|
|
public LocalDateTime getConnectedSince() { return connectedSince; }
|
|
public boolean isOnline() { return online; }
|
|
|
|
public int getTotalEntities() {
|
|
return entityData.values().stream()
|
|
.mapToInt(m -> m.getOrDefault("total", 0))
|
|
.sum();
|
|
}
|
|
}
|