mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-02 16:59:42 +01:00
Fixed Sponge CPU usage gathering
This commit is contained in:
parent
e09f821071
commit
86f99cbe1b
@ -7,6 +7,8 @@ import com.djrapitops.plan.system.processing.processors.TPSInsertProcessor;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.task.AbsRunnable;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -52,4 +54,27 @@ public abstract class TPSCountTimer<T extends PlanPlugin> extends AbsRunnable {
|
||||
public int getLatestPlayersOnline() {
|
||||
return latestPlayersOnline;
|
||||
}
|
||||
|
||||
protected long getUsedMemory() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
long totalMemory = runtime.totalMemory();
|
||||
return (totalMemory - runtime.freeMemory()) / 1000000;
|
||||
}
|
||||
|
||||
protected double getCPUUsage() {
|
||||
double averageCPUUsage;
|
||||
|
||||
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
|
||||
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
|
||||
averageCPUUsage = nativeOsBean.getSystemCpuLoad();
|
||||
} else {
|
||||
int availableProcessors = osBean.getAvailableProcessors();
|
||||
averageCPUUsage = osBean.getSystemLoadAverage() / availableProcessors;
|
||||
}
|
||||
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
|
||||
averageCPUUsage = -1;
|
||||
}
|
||||
return averageCPUUsage * 100.0;
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,10 @@ public class BungeeTPSCountTimer extends TPSCountTimer<PlanBungee> {
|
||||
.date(now)
|
||||
.skipTPS()
|
||||
.playersOnline(onlineCount)
|
||||
.usedCPU(getCPUUsage())
|
||||
.usedMemory(getUsedMemory())
|
||||
.entities(-1)
|
||||
.chunksLoaded(-1)
|
||||
.toTPS();
|
||||
|
||||
history.add(tps);
|
||||
|
@ -7,9 +7,6 @@ import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
|
||||
public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
|
||||
|
||||
private long lastCheckNano;
|
||||
@ -43,10 +40,7 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
|
||||
private TPS calculateTPS(long diff, long now) {
|
||||
double averageCPUUsage = getCPUUsage();
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
long totalMemory = runtime.totalMemory();
|
||||
long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000;
|
||||
long usedMemory = getUsedMemory();
|
||||
|
||||
int playersOnline = plugin.getServer().getOnlinePlayers().size();
|
||||
latestPlayersOnline = playersOnline;
|
||||
@ -58,22 +52,6 @@ public class BukkitTPSCountTimer extends TPSCountTimer<Plan> {
|
||||
return getTPS(diff, now, averageCPUUsage, usedMemory, entityCount, loadedChunks, playersOnline);
|
||||
}
|
||||
|
||||
private double getCPUUsage() {
|
||||
double averageCPUUsage;
|
||||
|
||||
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
|
||||
com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
|
||||
averageCPUUsage = nativeOsBean.getSystemCpuLoad();
|
||||
} else {
|
||||
int availableProcessors = osBean.getAvailableProcessors();
|
||||
averageCPUUsage = osBean.getSystemLoadAverage() / availableProcessors;
|
||||
}
|
||||
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
|
||||
averageCPUUsage = -1;
|
||||
}
|
||||
return averageCPUUsage * 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TPS for Spigot / Bukkit
|
||||
|
@ -9,9 +9,6 @@ import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import org.spongepowered.api.Sponge;
|
||||
import org.spongepowered.api.world.World;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.OperatingSystemMXBean;
|
||||
|
||||
public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
|
||||
private long lastCheckNano;
|
||||
@ -42,18 +39,9 @@ public class SpongeTPSCountTimer extends TPSCountTimer<PlanSponge> {
|
||||
* @return the TPS
|
||||
*/
|
||||
private TPS calculateTPS(long now) {
|
||||
OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
|
||||
int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
|
||||
double averageCPUUsage = operatingSystemMXBean.getSystemLoadAverage() / availableProcessors * 100.0;
|
||||
double averageCPUUsage = getCPUUsage();
|
||||
|
||||
if (averageCPUUsage < 0) { // If unavailable, getSystemLoadAverage() returns -1
|
||||
averageCPUUsage = -1;
|
||||
}
|
||||
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
|
||||
long totalMemory = runtime.totalMemory();
|
||||
long usedMemory = (totalMemory - runtime.freeMemory()) / 1000000;
|
||||
long usedMemory = getUsedMemory();
|
||||
|
||||
double tps = Sponge.getGame().getServer().getTicksPerSecond();
|
||||
int playersOnline = ServerInfo.getServerProperties().getOnlinePlayers();
|
||||
|
Loading…
Reference in New Issue
Block a user