コード例 #1
0
 public async Task UserCountChanged(SocketGuildUser user)
 {
     if (user.Guild.MemberCount < 250)
     {
         //Ignore servers with less than 250 members to reduce disk usage
         return;
     }
     GraphiteService.Report(new ahd.Graphite.Datapoint($"Guilds/{user.Guild.Id}/UserCount", user.Guild.MemberCount, DateTime.UtcNow));
 }
コード例 #2
0
        public void TimerEvent(object _)
        {
            MessageStatistics.LoopCount++;
            Task.Run(() =>
            {
                MessageStatistics.ThisMinute = MessageStatistics.ThisMinute.Where(x => x + TimeSpan.FromMinutes(1) > DateTime.UtcNow).ToList();
                GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/Messages/Minutely", MessageStatistics.ThisMinute.Count, DateTime.UtcNow));
                GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/Messages/Session", MessageStatistics.ThisSession, DateTime.UtcNow));
                if (MessageStatistics.LoopCount % 60 == 0)
                {
                    MessageStatistics.ThisHour = MessageStatistics.ThisHour.Where(x => x + TimeSpan.FromHours(1) > DateTime.UtcNow).ToList();
                    GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/Messages/Hourly", MessageStatistics.ThisHour.Count, DateTime.UtcNow));
                }

                if (MessageStatistics.LoopCount % (60 * 24) == 0)
                {
                    MessageStatistics.ThisDay = MessageStatistics.ThisDay.Where(x => x + TimeSpan.FromDays(1) > DateTime.UtcNow).ToList();
                    GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/Messages/Daily", MessageStatistics.ThisDay.Count, DateTime.UtcNow));
                }
            });
        }
コード例 #3
0
        public GraphManager(IDatabase database, DiscordShardedClient client, LogHandler logger)
        {
            Database = database;
            Client   = client;

            var config = GetConfig();

            if (config.GraphiteUrl == null)
            {
                logger.Log("Graphite URL not set, you can set it using the SetGraphiteUrl command.", Discord.LogSeverity.Warning);
            }

            GraphiteService = new GraphiteService(config.GraphiteUrl);

            Client.UserJoined      += UserCountChanged;
            Client.JoinedGuild     += GuildCountChanged;
            Client.LeftGuild       += GuildCountChanged;
            Client.UserLeft        += UserCountChanged;
            Client.MessageReceived += MessageReceived;

            MessageStatistics = new MessageStats();
            Timer             = new Timer(TimerEvent, null, TimeSpan.Zero, TimeSpan.FromMinutes(1));
        }
コード例 #4
0
 public async Task GuildCountChanged(SocketGuild guild)
 {
     GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/GuildCount", Client.Guilds.Count, DateTime.UtcNow));
     GraphiteService.Report(new ahd.Graphite.Datapoint($"Bot/MemberCount", Client.Guilds.Sum(x => x.MemberCount), DateTime.UtcNow));
 }