forked from lavalink-devs/Lavalink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3a1736
commit d34ccfc
Showing
6 changed files
with
158 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/.idea/ | ||
*.iml | ||
/logs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
LavalinkClient/src/main/java/lavalink/client/io/RemoteStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package lavalink.client.io; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class RemoteStats { | ||
|
||
private int players; | ||
private int playingPlayers; | ||
private long uptime; | ||
|
||
// In bytes | ||
private int memFree; | ||
private int memUsed; | ||
private int memAllocated; | ||
private int memReservable; | ||
|
||
private int cpuCores; | ||
private double systemLoad; | ||
private double lavalinkLoad; | ||
|
||
private int avgFramesSentPerMinute = -1; | ||
private int avgFramesNulledPerMinute = -1; | ||
private int avgFramesDeficitPerMinute = -1; | ||
|
||
RemoteStats(JSONObject json) { | ||
players = json.getInt("players"); | ||
playingPlayers = json.getInt("playingPlayers"); | ||
uptime = json.getLong("uptime"); | ||
|
||
memFree = json.getJSONObject("memory").getInt("free"); | ||
memUsed = json.getJSONObject("memory").getInt("used"); | ||
memAllocated = json.getJSONObject("memory").getInt("allocated"); | ||
memReservable = json.getJSONObject("memory").getInt("reservable"); | ||
|
||
cpuCores = json.getJSONObject("cpu").getInt("cores"); | ||
systemLoad = json.getJSONObject("cpu").getDouble("systemLoad"); | ||
lavalinkLoad = json.getJSONObject("cpu").getDouble("lavalinkLoad"); | ||
|
||
JSONObject frames = json.optJSONObject("frameStats"); | ||
|
||
if (frames != null) { | ||
avgFramesSentPerMinute = frames.getInt("sent"); | ||
avgFramesNulledPerMinute = frames.getInt("nulled"); | ||
avgFramesDeficitPerMinute = frames.getInt("deficit"); | ||
} | ||
} | ||
|
||
public int getPlayers() { | ||
return players; | ||
} | ||
|
||
public int getPlayingPlayers() { | ||
return playingPlayers; | ||
} | ||
|
||
public long getUptime() { | ||
return uptime; | ||
} | ||
|
||
public int getMemFree() { | ||
return memFree; | ||
} | ||
|
||
public int getMemUsed() { | ||
return memUsed; | ||
} | ||
|
||
public int getMemAllocated() { | ||
return memAllocated; | ||
} | ||
|
||
public int getMemReservable() { | ||
return memReservable; | ||
} | ||
|
||
public int getCpuCores() { | ||
return cpuCores; | ||
} | ||
|
||
public double getSystemLoad() { | ||
return systemLoad; | ||
} | ||
|
||
public double getLavalinkLoad() { | ||
return lavalinkLoad; | ||
} | ||
|
||
public int getAvgFramesSentPerMinute() { | ||
return avgFramesSentPerMinute; | ||
} | ||
|
||
public int getAvgFramesNulledPerMinute() { | ||
return avgFramesNulledPerMinute; | ||
} | ||
|
||
public int getAvgFramesDeficitPerMinute() { | ||
return avgFramesDeficitPerMinute; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RemoteStats{" + | ||
"players=" + players + | ||
", playingPlayers=" + playingPlayers + | ||
", uptime=" + uptime + | ||
", memFree=" + memFree + | ||
", memUsed=" + memUsed + | ||
", memAllocated=" + memAllocated + | ||
", memReservable=" + memReservable + | ||
", cpuCores=" + cpuCores + | ||
", systemLoad=" + systemLoad + | ||
", lavalinkLoad=" + lavalinkLoad + | ||
", avgFramesSentPerMinute=" + avgFramesSentPerMinute + | ||
", avgFramesNulledPerMinute=" + avgFramesNulledPerMinute + | ||
", avgFramesDeficitPerMinute=" + avgFramesDeficitPerMinute + | ||
'}'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
LavalinkClient/src/test/java/lavalink/client/io/RemoteStatsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package lavalink.client.io; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
class RemoteStatsTest { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(RemoteStatsTest.class); | ||
|
||
@Test | ||
void remoteStatsTest() { | ||
JSONObject json = new JSONObject("{\"playingPlayers\":0,\"op\":\"stats\",\"memory\":{\"reservable\":1892155392,\"used\":67111552,\"free\":137885056,\"allocated\":204996608},\"players\":0,\"cpu\":{\"cores\":4,\"systemLoad\":0,\"lavalinkLoad\":0},\"uptime\":15754}"); | ||
RemoteStats stats = new RemoteStats(json); | ||
|
||
Assertions.assertEquals(-1, stats.getAvgFramesSentPerMinute()); | ||
Assertions.assertEquals(-1, stats.getAvgFramesNulledPerMinute()); | ||
Assertions.assertEquals(-1, stats.getAvgFramesDeficitPerMinute()); | ||
log.info(stats + ""); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters