Corrected memory usage on StatusService

This commit is contained in:
Kaoticz
2021-10-15 22:04:30 +00:00
committed by Kwoth
parent 6ada15049d
commit 2fd7d97025
3 changed files with 46 additions and 7 deletions

View File

@@ -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),

View File

@@ -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 = ", ");
}
}

View File

@@ -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;