Collect webhook response time and shard latency
This commit is contained in:
parent
90c6869b00
commit
a689d61788
@ -312,8 +312,8 @@ namespace PluralKit.Bot
|
||||
|
||||
public async Task HandleMessage(SocketMessage msg)
|
||||
{
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.MessagesReceived);
|
||||
|
||||
RegisterMessageMetrics(msg);
|
||||
|
||||
// _client.CurrentUser will be null if we've connected *some* shards but not shard #0 yet
|
||||
// This will cause an error in WebhookCacheServices so we just workaround and don't process any messages
|
||||
// until we properly connect. TODO: can we do this without chucking away a bunch of messages?
|
||||
@ -347,6 +347,7 @@ namespace PluralKit.Bot
|
||||
system = await conn.QueryFirstOrDefaultAsync<PKSystem>(
|
||||
"select systems.* from systems, accounts where accounts.uid = @Id and systems.id = accounts.system",
|
||||
new {Id = arg.Author.Id});
|
||||
|
||||
await _commands.ExecuteAsync(new PKCommandContext(_client, arg, system, _services), argPos,
|
||||
_services);
|
||||
}
|
||||
@ -357,6 +358,21 @@ namespace PluralKit.Bot
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterMessageMetrics(SocketMessage msg)
|
||||
{
|
||||
var guild = (msg.Channel as IGuildChannel)?.Guild;
|
||||
if (guild != null)
|
||||
{
|
||||
var shard = _client.GetShardFor(guild);
|
||||
var latencyMillis = shard.Latency;
|
||||
|
||||
_metrics.Provider.Timer.Instance(BotMetrics.GatewayLatency, new MetricTags("shard", shard.ShardId.ToString()))
|
||||
.Record(latencyMillis, TimeUnit.Milliseconds);
|
||||
}
|
||||
|
||||
_metrics.Measure.Meter.Mark(BotMetrics.MessagesReceived);
|
||||
}
|
||||
|
||||
public Task HandleReactionAdded(Cacheable<IUserMessage, ulong> message, ISocketMessageChannel channel,
|
||||
SocketReaction reaction) => _proxy.HandleReactionAddedAsync(message, channel, reaction);
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
using App.Metrics;
|
||||
using App.Metrics.Gauge;
|
||||
using App.Metrics.Histogram;
|
||||
using App.Metrics.Meter;
|
||||
using App.Metrics.Timer;
|
||||
|
||||
namespace PluralKit.Bot
|
||||
{
|
||||
@ -15,5 +17,7 @@ namespace PluralKit.Bot
|
||||
public static GaugeOptions Channels => new GaugeOptions {Name = "Channels", MeasurementUnit = Unit.None, Context = "Bot"};
|
||||
public static GaugeOptions ShardsConnected => new GaugeOptions { Name = "Shards Connected", Context = "Bot" };
|
||||
public static GaugeOptions WebhookCacheSize => new GaugeOptions { Name = "Webhook Cache Size", Context = "Bot" };
|
||||
public static TimerOptions WebhookResponseTime => new TimerOptions { Name = "Webhook Response Time", Context = "Bot" };
|
||||
public static TimerOptions GatewayLatency => new TimerOptions { Name = "Gateway Latency", Context = "Bot" };
|
||||
}
|
||||
}
|
@ -117,7 +117,10 @@ namespace PluralKit.Bot
|
||||
var webhook = await _webhookCache.GetWebhook(message.Channel as ITextChannel);
|
||||
var avatarUrl = match.Member.AvatarUrl ?? match.System.AvatarUrl;
|
||||
var proxyName = match.Member.ProxyName(match.System.Tag);
|
||||
var hookMessageId = await ExecuteWebhook(webhook, messageContents, proxyName, avatarUrl, message.Attachments.FirstOrDefault());
|
||||
|
||||
ulong hookMessageId;
|
||||
using (_metrics.Measure.Timer.Time(BotMetrics.WebhookResponseTime))
|
||||
hookMessageId = await ExecuteWebhook(webhook, messageContents, proxyName, avatarUrl, message.Attachments.FirstOrDefault());
|
||||
|
||||
// Store the message in the database, and log it in the log channel (if applicable)
|
||||
await _messageStorage.Store(message.Author.Id, hookMessageId, message.Channel.Id, message.Id, match.Member);
|
||||
|
Loading…
Reference in New Issue
Block a user