Search in sources :

Example 1 with Bean

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) {
        }
    }
}
Also used : Guild(net.dv8tion.jda.api.entities.Guild) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Metrics(at.xirado.bean.misc.Metrics) Bean(at.xirado.bean.Bean) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Bean(at.xirado.bean.Bean)

Aggregations

Bean (at.xirado.bean.Bean)1 Metrics (at.xirado.bean.misc.Metrics)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 Guild (net.dv8tion.jda.api.entities.Guild)1