From b6fc86d427686fc27de610bc21f9f464e14d9713 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 25 Sep 2021 20:15:24 +0200 Subject: [PATCH] Collect command runtime metrics --- PluralKit.Bot/BotMetrics.cs | 1 + PluralKit.Bot/CommandSystem/Context.cs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/BotMetrics.cs b/PluralKit.Bot/BotMetrics.cs index 20625c37..160ad762 100644 --- a/PluralKit.Bot/BotMetrics.cs +++ b/PluralKit.Bot/BotMetrics.cs @@ -10,6 +10,7 @@ namespace PluralKit.Bot public static MeterOptions MessagesReceived => new MeterOptions { Name = "Messages processed", MeasurementUnit = Unit.Events, RateUnit = TimeUnit.Seconds, Context = "Bot" }; public static MeterOptions MessagesProxied => new MeterOptions { Name = "Messages proxied", MeasurementUnit = Unit.Events, RateUnit = TimeUnit.Seconds, Context = "Bot" }; public static MeterOptions CommandsRun => new MeterOptions { Name = "Commands run", MeasurementUnit = Unit.Commands, RateUnit = TimeUnit.Seconds, Context = "Bot" }; + public static TimerOptions CommandTime => new TimerOptions { Name = "Command run time", MeasurementUnit = Unit.Commands, RateUnit = TimeUnit.Seconds, DurationUnit = TimeUnit.Seconds, Context = "Bot" }; public static GaugeOptions MembersTotal => new GaugeOptions { Name = "Members total", MeasurementUnit = Unit.None, Context = "Bot" }; public static GaugeOptions MembersOnline => new GaugeOptions { Name = "Members online", MeasurementUnit = Unit.None, Context = "Bot" }; public static GaugeOptions Guilds => new GaugeOptions { Name = "Guilds", MeasurementUnit = Unit.None, Context = "Bot" }; diff --git a/PluralKit.Bot/CommandSystem/Context.cs b/PluralKit.Bot/CommandSystem/Context.cs index 954c532b..cc5ff89f 100644 --- a/PluralKit.Bot/CommandSystem/Context.cs +++ b/PluralKit.Bot/CommandSystem/Context.cs @@ -116,7 +116,9 @@ namespace PluralKit.Bot try { - await handler(_provider.Resolve()); + using (_metrics.Measure.Timer.Time(BotMetrics.CommandTime, new MetricTags("Command", commandDef.Key))) + await handler(_provider.Resolve()); + _metrics.Measure.Meter.Mark(BotMetrics.CommandsRun); } catch (PKSyntaxError e)