use of at.xirado.bean.Bean in project Bean by Xirado.
the class MetricsJob method run.
@Override
public void run() {
byte runs = 0;
Bean instance = Bean.getInstance();
while (true) {
int busyCommandThreads = ((ThreadPoolExecutor) instance.getCommandExecutor()).getActiveCount();
int totalCommandThreads = ((ThreadPoolExecutor) instance.getCommandExecutor()).getCorePoolSize();
int activePlayers = instance.getAudioManager().getAudioPlayers().stream().mapToInt(player -> player.getPlayer().getPlayingTrack() != null ? 1 : 0).sum();
Metrics.BUSY_THREADS.labels("command").set(busyCommandThreads);
Metrics.BUSY_THREADS.labels("command_total").set(totalCommandThreads);
Metrics.PLAYING_MUSIC_PLAYERS.set(activePlayers);
runs++;
if (// per minute
runs == 12) {
int guildCount = (int) instance.getShardManager().getGuildCache().size();
int userCount = instance.getShardManager().getGuildCache().stream().mapToInt(Guild::getMemberCount).sum();
Metrics.USER_COUNT.set(userCount);
Metrics.GUILD_COUNT.set(guildCount);
runs = 0;
}
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
}
}
}
Aggregations