mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
Add more performance metrics
This commit is contained in:
parent
b9cbd241de
commit
ca882dba73
7 changed files with 79 additions and 36 deletions
|
|
@ -1,6 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using App.Metrics;
|
||||
|
||||
using DSharpPlus;
|
||||
using DSharpPlus.EventArgs;
|
||||
|
||||
|
|
@ -24,13 +27,15 @@ namespace PluralKit.Bot
|
|||
public bool Connected;
|
||||
}
|
||||
|
||||
private IMetrics _metrics;
|
||||
private ILogger _logger;
|
||||
private DiscordShardedClient _client;
|
||||
private Dictionary<int, ShardInfo> _shardInfo = new Dictionary<int, ShardInfo>();
|
||||
|
||||
public ShardInfoService(ILogger logger, DiscordShardedClient client)
|
||||
public ShardInfoService(ILogger logger, DiscordShardedClient client, IMetrics metrics)
|
||||
{
|
||||
_client = client;
|
||||
_metrics = metrics;
|
||||
_logger = logger.ForContext<ShardInfoService>();
|
||||
}
|
||||
|
||||
|
|
@ -41,6 +46,13 @@ namespace PluralKit.Bot
|
|||
_client.SocketOpened += RefreshShardList;
|
||||
}
|
||||
|
||||
private void ReportShardStatus()
|
||||
{
|
||||
foreach (var (id, shard) in _shardInfo)
|
||||
_metrics.Measure.Gauge.SetValue(BotMetrics.ShardLatency, new MetricTags("shard", id.ToString()), shard.ShardLatency.TotalMilliseconds);
|
||||
_metrics.Measure.Gauge.SetValue(BotMetrics.ShardsConnected, _shardInfo.Count(s => s.Value.Connected));
|
||||
}
|
||||
|
||||
private async Task RefreshShardList()
|
||||
{
|
||||
// This callback doesn't actually receive the shard that was opening, so we just try to check we have 'em all (so far)
|
||||
|
|
@ -95,6 +107,7 @@ namespace PluralKit.Bot
|
|||
var info = TryGetShard(e.Client);
|
||||
// info.LastConnectionTime = SystemClock.Instance.GetCurrentInstant();
|
||||
info.Connected = true;
|
||||
ReportShardStatus();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
@ -105,6 +118,7 @@ namespace PluralKit.Bot
|
|||
var info = TryGetShard(e.Client);
|
||||
info.LastConnectionTime = SystemClock.Instance.GetCurrentInstant();
|
||||
info.Connected = true;
|
||||
ReportShardStatus();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
@ -115,6 +129,7 @@ namespace PluralKit.Bot
|
|||
var info = TryGetShard(e.Client);
|
||||
info.DisconnectionCount++;
|
||||
info.Connected = false;
|
||||
ReportShardStatus();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue