@@ -0,0 +1,2501 @@
+package top.quantic.sentry.job;%0A%0Aimport com.codahale.metrics.MetricRegistry;%0Aimport org.quartz.Job;%0Aimport org.quartz.JobExecutionContext;%0Aimport org.quartz.JobExecutionException;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0Aimport org.springframework.beans.factory.annotation.Autowired;%0Aimport sx.blah.discord.api.IDiscordClient;%0Aimport sx.blah.discord.api.IShard;%0Aimport sx.blah.discord.handle.obj.IGuild;%0Aimport sx.blah.discord.handle.obj.StatusType;%0Aimport top.quantic.sentry.discord.core.ClientRegistry;%0Aimport top.quantic.sentry.domain.Bot;%0A%0Aimport java.util.Map;%0Aimport java.util.concurrent.TimeUnit;%0A%0Apublic class BotCheck implements Job %7B%0A%0A    private static final Logger log = LoggerFactory.getLogger(BotCheck.class);%0A%0A    @Autowired%0A    private ClientRegistry clientRegistry;%0A%0A    @Autowired%0A    private MetricRegistry metricRegistry;%0A%0A    @Override%0A    public void execute(JobExecutionContext context) throws JobExecutionException %7B%0A        for (Map.Entry%3CBot, IDiscordClient%3E entry : clientRegistry.getClients().entrySet()) %7B%0A            IDiscordClient client = entry.getValue();%0A            if (client.isReady()) %7B%0A                String botTag = %22bot:%22 + entry.getKey().getName();%0A                for (IShard shard : client.getShards()) %7B%0A                    String shardTag = %22shard:%22 + shard.getInfo()%5B0%5D;%0A                    long millis = shard.getResponseTime();%0A                    log.debug(%22%5B%7B%7D:%7B%7D%5D Discord WS response time: %7B%7D ms%22, entry.getKey().getName(), shard.getInfo()%5B0%5D, millis);%0A                    metricRegistry.timer(%22discord.ws.response%5B%22 + botTag + %22,%22 + shardTag + %22%5D%22)%0A                        .update(millis, TimeUnit.MILLISECONDS);%0A                %7D%0A                for (IGuild guild : client.getGuilds()) %7B%0A                    String guildTag = %22guild:%22 + guild.getID();%0A                    long online = guild.getUsers().stream()%0A                        .filter(user -%3E user.getPresence().getStatus() == StatusType.ONLINE)%0A                        .count();%0A                    long other = guild.getUsers().size() - online;%0A                    String onlineMetric = %22discord.ws.users%5B%22 + botTag + %22,%22 + guildTag + %22,%22 + %22status:online%5D%22;%0A                    String otherMetric = %22discord.ws.users%5B%22 + botTag + %22,%22 + guildTag + %22,%22 + %22status:other%5D%22;%0A                    metricRegistry.histogram(onlineMetric).update(online);%0A                    metricRegistry.histogram(otherMetric).update(other);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add a job to report bot status