mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-09 23:37:54 +00:00
Add basic WIP metrics system
This commit is contained in:
parent
a2040f959d
commit
2d58705e85
6 changed files with 90 additions and 9 deletions
|
|
@ -1,10 +1,14 @@
|
|||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using App.Metrics;
|
||||
using App.Metrics.Meter;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
namespace PluralKit.Bot.Commands {
|
||||
public class MiscCommands: ModuleBase<PKCommandContext> {
|
||||
public BotConfig BotConfig { get; set; }
|
||||
public IMetrics Metrics { get; set; }
|
||||
|
||||
[Command("invite")]
|
||||
[Alias("inv")]
|
||||
|
|
@ -32,5 +36,21 @@ namespace PluralKit.Bot.Commands {
|
|||
[Command("freeze")] public Task Freeze() => Context.Channel.SendMessageAsync("*A giant crystal ball of ice is charged and hurled toward your opponent, bursting open and freezing them solid on contact.*");
|
||||
[Command("starstorm")] public Task Starstorm() => Context.Channel.SendMessageAsync("*Vibrant colours burst forth from the sky as meteors rain down upon your opponent.*");
|
||||
|
||||
[Command("stats")]
|
||||
public async Task Stats()
|
||||
{
|
||||
var messagesReceived = Metrics.Snapshot.GetForContext("Bot").Meters.First(m => m.MultidimensionalName == BotMetrics.MessagesReceived.Name).Value;
|
||||
var messagesProxied = Metrics.Snapshot.GetForContext("Bot").Meters.First(m => m.MultidimensionalName == BotMetrics.MessagesProxied.Name).Value;
|
||||
var proxySuccessRate = messagesProxied.Items.First(i => i.Item == "success");
|
||||
|
||||
var commandsRun = Metrics.Snapshot.GetForContext("Bot").Meters.First(m => m.MultidimensionalName == BotMetrics.CommandsRun.Name).Value;
|
||||
|
||||
await Context.Channel.SendMessageAsync(embed: new EmbedBuilder()
|
||||
.AddField("Messages processed", $"{messagesReceived.OneMinuteRate:F1}/s ({messagesReceived.FifteenMinuteRate:F1}/s over 15m)")
|
||||
.AddField("Messages proxied", $"{messagesProxied.OneMinuteRate:F1}/s ({messagesProxied.FifteenMinuteRate:F1}/s over 15m)")
|
||||
.AddField("Commands executed", $"{commandsRun.OneMinuteRate:F1}/s ({commandsRun.FifteenMinuteRate:F1}/s over 15m)")
|
||||
.AddField("Proxy success rate", $"{proxySuccessRate.Percent/100:P1}")
|
||||
.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue