mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	Corrected memory usage on StatusService
This commit is contained in:
		@@ -253,7 +253,7 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
                        .AddField(GetText(strs.commands_ran), _stats.CommandsRan.ToString(), true)
 | 
			
		||||
                        .AddField(GetText(strs.messages), $"{_stats.MessageCounter} ({_stats.MessagesPerSecond:F2}/sec)",
 | 
			
		||||
                            true)
 | 
			
		||||
                        .AddField(GetText(strs.memory), $"{_stats.Heap} MB", true)
 | 
			
		||||
                        .AddField(GetText(strs.memory), FormattableString.Invariant($"{_stats.PrivateMemory:F2} MB"), true)
 | 
			
		||||
                        .AddField(GetText(strs.owner_ids), ownerIds, true)
 | 
			
		||||
                        .AddField(GetText(strs.uptime), _stats.GetUptimeString("\n"), true)
 | 
			
		||||
                        .AddField(GetText(strs.presence), 
 | 
			
		||||
 
 | 
			
		||||
@@ -4,16 +4,55 @@ namespace NadekoBot.Services
 | 
			
		||||
{
 | 
			
		||||
    public interface IStatsService
 | 
			
		||||
    {
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The author of the bot.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        string Author { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The total amount of commands ran since startup.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        long CommandsRan { get; }
 | 
			
		||||
        string Heap { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The total amount of private memory used by the bot, in Megabytes.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        double PrivateMemory { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The Discord framework used by the bot.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        string Library { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The amount of messages seen by the bot since startup.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        long MessageCounter { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The rate of messages the bot sees every second.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        double MessagesPerSecond { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The total amount of text channels the bot can see.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        long TextChannels { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// The total amount of voice channels the bot can see.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        long VoiceChannels { get; }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets for how long the bot has been up since startup.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        TimeSpan GetUptime();
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Gets a formatted string of how long the bot has been up since startup.
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        /// <param name="separator">The formatting separator.</param>
 | 
			
		||||
        string GetUptimeString(string separator = ", ");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,21 @@
 | 
			
		||||
using Discord;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
using NadekoBot.Common.ModuleBehaviors;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using Serilog;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using NadekoBot.Common.ModuleBehaviors;
 | 
			
		||||
using Serilog;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Services
 | 
			
		||||
{
 | 
			
		||||
    public class StatsService : IStatsService, IReadyExecutor, INService
 | 
			
		||||
    {
 | 
			
		||||
        private readonly Process _currentProcess = Process.GetCurrentProcess();
 | 
			
		||||
        private readonly DiscordSocketClient _client;
 | 
			
		||||
        private readonly IBotCredentials _creds;
 | 
			
		||||
        private readonly DateTime _started;
 | 
			
		||||
@@ -23,8 +24,7 @@ namespace NadekoBot.Services
 | 
			
		||||
        public string Author => "Kwoth#2452";
 | 
			
		||||
        public string Library => "Discord.Net";
 | 
			
		||||
 | 
			
		||||
        public string Heap => Math.Round((double)GC.GetTotalMemory(false) / 1.MiB(), 2)
 | 
			
		||||
            .ToString(CultureInfo.InvariantCulture);
 | 
			
		||||
        public double PrivateMemory => _currentProcess.PrivateMemorySize64 / (double)1.MiB();
 | 
			
		||||
        public double MessagesPerSecond => MessageCounter / GetUptime().TotalSeconds;
 | 
			
		||||
 | 
			
		||||
        private long _textChannels;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user