Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ bin/
.vscode/

### Mac OS ###
.DS_Store
.DS_Store
teste2e/src/test/resources/config/ServerPulse/config.yml
.python-version
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ public class AsyncMetricsSnapshot {
private final double minMSPT;
private final double maxMSPT;

private final double systemCpuLoadRatio;
private final double processCpuLoadRatio;
private final int availableProcessors;


public AsyncMetricsSnapshot(long usedHeap, long commitedHeap,
long totalDisk, long usableDisk,
long minPing, long maxPing, long avgPing,
double mspt1m, double mspt5m, double mspt15m,
double lastMSPT, double minMSPT, double maxMSPT) {
double lastMSPT, double minMSPT, double maxMSPT,
double systemCpuLoadRatio, double processCpuLoadRatio, int availableProcessors) {
this.usedHeap = usedHeap;
this.commitedHeap = commitedHeap;

Expand All @@ -44,6 +49,10 @@ public AsyncMetricsSnapshot(long usedHeap, long commitedHeap,
this.lastMSPT = lastMSPT;
this.minMSPT = minMSPT;
this.maxMSPT = maxMSPT;

this.systemCpuLoadRatio = systemCpuLoadRatio;
this.processCpuLoadRatio = processCpuLoadRatio;
this.availableProcessors = availableProcessors;
}

/**
Expand Down Expand Up @@ -162,4 +171,28 @@ public double getMinMSPT() {
public double getMaxMSPT() {
return maxMSPT;
}

/**
* Gets the system-wide CPU load ratio (0.0 to 1.0)
* @return the system CPU load ratio
*/
public double getSystemCpuLoadRatio() {
return systemCpuLoadRatio;
}

/**
* Gets the JVM process CPU load ratio (0.0 to 1.0)
* @return the process CPU load ratio
*/
public double getProcessCpuLoadRatio() {
return processCpuLoadRatio;
}

/**
* Gets the number of available processors
* @return the number of available processors
*/
public int getAvailableProcessors() {
return availableProcessors;
}
}
35 changes: 35 additions & 0 deletions api/src/main/java/it/renvins/serverpulse/api/utils/CPUUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package it.renvins.serverpulse.api.utils;

import java.lang.management.ManagementFactory;

import com.sun.management.OperatingSystemMXBean;


public class CPUUtils {

private final static OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);

/**
* Get the system-wide CPU load ratio (0.0 to 1.0)
* @return the system CPU load ratio
*/
public static double getSystemCPULoadRatio() {
return osBean.getCpuLoad();
}

/**
* Get the JVM process CPU load ratio (0.0 to 1.0)
* @return the process CPU load ratio
*/
public static double getProcessCPULoadRatio() {
return osBean.getProcessCpuLoad();
}

/**
* Get the number of available processors
* @return the number of available processors
*/
public static int getAvailableProcessors() {
return Runtime.getRuntime().availableProcessors();
}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group = "it.renvins"
version = "0.5.0-SNAPSHOT"
version = "0.5.1-SNAPSHOT"

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public List<String> format(SyncMetricsSnapshot syncData, AsyncMetricsSnapshot as
.addField("min_ping", asyncData.getMinPing())
.addField("max_ping", asyncData.getMaxPing())
.addField("avg_ping", asyncData.getAvgPing())
.addField("system_cpu_load_ratio", asyncData.getSystemCpuLoadRatio())
.addField("process_cpu_load_ratio", asyncData.getProcessCpuLoadRatio())
.addField("available_processors", asyncData.getAvailableProcessors())
.setTimestamp(timestamp);

if (syncData.getTps()[0] != 0.0 && syncData.getTps()[1] != 0.0 && syncData.getTps()[2] != 0.0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import it.renvins.serverpulse.api.metrics.IMSPTRetriever;
import it.renvins.serverpulse.api.metrics.IPingRetriever;
import it.renvins.serverpulse.api.metrics.ITPSRetriever;
import it.renvins.serverpulse.api.utils.CPUUtils;
import it.renvins.serverpulse.api.utils.MemoryUtils;
import it.renvins.serverpulse.common.logger.PulseLogger;
import it.renvins.serverpulse.common.platform.Platform;
Expand Down Expand Up @@ -93,10 +94,15 @@ public AsyncMetricsSnapshot collectAsyncSnapshot() {
double maxMSPT = msptRetriever.getMaxMSPT(5 * 60 * 20);
double minMSPT = msptRetriever.getMinMSPT(5 * 60 * 20);

double systemCpuLoadRatio = CPUUtils.getSystemCPULoadRatio();
double processCpuLoadRatio = CPUUtils.getProcessCPULoadRatio();
int availableProcessors = CPUUtils.getAvailableProcessors();

return new AsyncMetricsSnapshot(usedHeap, committedHeap,
totalDisk, usableDisk,
minPing, maxPing, avgPing,
mspt1m, mspt5m, mspt15m,
lastMSPT, minMSPT, maxMSPT);
lastMSPT, minMSPT, maxMSPT,
systemCpuLoadRatio, processCpuLoadRatio, availableProcessors);
}
}
Loading