feat(api): expose Discord statistics on /private/meta

This commit is contained in:
spiral 2022-03-15 00:09:27 -04:00
parent 8909330db2
commit 8a124c67ae
No known key found for this signature in database
GPG Key ID: 244A11E4B0BCF40E
2 changed files with 12 additions and 2 deletions

View File

@ -9,7 +9,7 @@ namespace PluralKit.API;
public static class APIJsonExt public static class APIJsonExt
{ {
public static JObject ToJson(this ModelRepository.Counts counts) public static JObject ToJson(this ModelRepository.Counts counts, int guildCount, int channelCount)
{ {
var o = new JObject(); var o = new JObject();
@ -19,6 +19,10 @@ public static class APIJsonExt
o.Add("switch_count", counts.SwitchCount); o.Add("switch_count", counts.SwitchCount);
o.Add("message_count", counts.MessageCount); o.Add("message_count", counts.MessageCount);
// Discord statistics
o.Add("guild_count", guildCount);
o.Add("channel_count", channelCount);
return o; return o;
} }
} }

View File

@ -30,11 +30,17 @@ public class PrivateController: PKControllerBase
var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus"); var redisInfo = await db.HashGetAllAsync("pluralkit:shardstatus");
var shards = redisInfo.Select(x => Proto.Unmarshal<ShardState>(x.Value)).OrderBy(x => x.ShardId); var shards = redisInfo.Select(x => Proto.Unmarshal<ShardState>(x.Value)).OrderBy(x => x.ShardId);
var redisClusterInfo = await db.HashGetAllAsync("pluralkit:cluster_stats");
var clusterInfo = redisClusterInfo.Select(x => JsonConvert.DeserializeObject<ClusterMetricInfo>(x.Value));
var guildCount = clusterInfo.Sum(x => x.GuildCount);
var channelCount = clusterInfo.Sum(x => x.ChannelCount);
var stats = await _repo.GetStats(); var stats = await _repo.GetStats();
var o = new JObject(); var o = new JObject();
o.Add("shards", shards.ToJson()); o.Add("shards", shards.ToJson());
o.Add("stats", stats.ToJson()); o.Add("stats", stats.ToJson(guildCount, channelCount));
o.Add("version", BuildInfoService.FullVersion); o.Add("version", BuildInfoService.FullVersion);
return Ok(o); return Ok(o);