mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-10 12:12:27 +00:00
Remove InfluxDB and add /api/v1/playerCount (#664)
* Add /playerCount api * Modify /playerCount api response * Remove all InfluxDB components
This commit is contained in:
parent
e93aea1977
commit
c8120b3388
9 changed files with 51 additions and 142 deletions
|
@ -1,6 +1,6 @@
|
|||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData;
|
||||
using LBPUnion.ProjectLighthouse.Servers.API.Responses;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.API.Controllers;
|
||||
|
@ -36,4 +36,39 @@ public class StatisticsEndpoints : ApiEndpointController
|
|||
TeamPicks = await StatisticsHelper.TeamPickCount(this.database),
|
||||
}
|
||||
);
|
||||
|
||||
private static readonly List<GameVersion> gameVersions = new()
|
||||
{
|
||||
GameVersion.LittleBigPlanet1,
|
||||
GameVersion.LittleBigPlanet2,
|
||||
GameVersion.LittleBigPlanet3,
|
||||
GameVersion.LittleBigPlanetVita,
|
||||
GameVersion.LittleBigPlanetPSP,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Get player counts for each individual title
|
||||
/// </summary>
|
||||
/// <returns>An instance of PlayerCountResponse</returns>
|
||||
[HttpGet("playerCount")]
|
||||
[ProducesResponseType(typeof(PlayerCountResponse), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetPlayerCounts()
|
||||
{
|
||||
List<PlayerCountObject> gameList = new();
|
||||
foreach (GameVersion version in gameVersions)
|
||||
{
|
||||
gameList.Add(new PlayerCountObject
|
||||
{
|
||||
Game = version.ToString(),
|
||||
PlayerCount = await StatisticsHelper.RecentMatchesForGame(this.database, version),
|
||||
});
|
||||
}
|
||||
PlayerCountResponse response = new()
|
||||
{
|
||||
TotalPlayerCount = await StatisticsHelper.RecentMatches(this.database),
|
||||
Games = gameList,
|
||||
};
|
||||
|
||||
return this.Ok(response);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
namespace LBPUnion.ProjectLighthouse.Servers.API.Responses;
|
||||
|
||||
public class PlayerCountObject
|
||||
{
|
||||
public string Game { get; set; } = "";
|
||||
public int PlayerCount { get; set; }
|
||||
}
|
||||
|
||||
public class PlayerCountResponse
|
||||
{
|
||||
public int TotalPlayerCount { get; set; }
|
||||
public List<PlayerCountObject> Games { get; set; } = new();
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
namespace LBPUnion.ProjectLighthouse.Configuration.ConfigurationCategories;
|
||||
|
||||
public class InfluxDBConfiguration
|
||||
{
|
||||
public bool InfluxEnabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to log to InfluxDB.
|
||||
/// </summary>
|
||||
public bool LoggingEnabled { get; set; }
|
||||
|
||||
public string Organization { get; set; } = "lighthouse";
|
||||
public string Bucket { get; set; } = "lighthouse";
|
||||
public string Token { get; set; } = "";
|
||||
public string Url { get; set; } = "http://localhost:8086";
|
||||
}
|
|
@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
|
|||
// This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly.
|
||||
// If you are modifying anything here, this value MUST be incremented.
|
||||
// Thanks for listening~
|
||||
public override int ConfigVersion { get; set; } = 17;
|
||||
public override int ConfigVersion { get; set; } = 18;
|
||||
|
||||
public override string ConfigName { get; set; } = "lighthouse.yml";
|
||||
public string WebsiteListenUrl { get; set; } = "http://localhost:10060";
|
||||
|
@ -36,7 +36,6 @@ public class ServerConfiguration : ConfigurationBase<ServerConfiguration>
|
|||
public DigestKeyConfiguration DigestKey { get; set; } = new();
|
||||
public DiscordIntegrationConfiguration DiscordIntegration { get; set; } = new();
|
||||
public GoogleAnalyticsConfiguration GoogleAnalytics { get; set; } = new();
|
||||
public InfluxDBConfiguration InfluxDB { get; set; } = new();
|
||||
public MailConfiguration Mail { get; set; } = new();
|
||||
public UserGeneratedContentLimitConfiguration UserGeneratedContentLimits { get; set; } = new();
|
||||
public WebsiteConfiguration WebsiteConfiguration { get; set; } = new();
|
||||
|
|
|
@ -1,90 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using InfluxDB.Client;
|
||||
using InfluxDB.Client.Writes;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Extensions;
|
||||
using LBPUnion.ProjectLighthouse.Logging;
|
||||
using LBPUnion.ProjectLighthouse.PlayerData;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
||||
public static class InfluxHelper
|
||||
{
|
||||
public static readonly InfluxDBClient Client = new(url: ServerConfiguration.Instance.InfluxDB.Url,
|
||||
token: ServerConfiguration.Instance.InfluxDB.Token);
|
||||
|
||||
private static readonly List<GameVersion> gameVersions = new()
|
||||
{
|
||||
GameVersion.LittleBigPlanet1,
|
||||
GameVersion.LittleBigPlanet2,
|
||||
GameVersion.LittleBigPlanet3,
|
||||
GameVersion.LittleBigPlanetVita,
|
||||
GameVersion.LittleBigPlanetPSP,
|
||||
};
|
||||
|
||||
private static async void Log()
|
||||
{
|
||||
try
|
||||
{
|
||||
await using Database database = new();
|
||||
using WriteApi writeApi = Client.GetWriteApi();
|
||||
PointData point = PointData.Measurement("lighthouse")
|
||||
.Field("playerCount", await StatisticsHelper.RecentMatches(database))
|
||||
.Field("slotCount", await StatisticsHelper.SlotCount(database))
|
||||
.Field("userCount", await StatisticsHelper.UserCount(database))
|
||||
.Field("photoCount", await StatisticsHelper.PhotoCount(database));
|
||||
|
||||
foreach (GameVersion gameVersion in gameVersions)
|
||||
{
|
||||
PointData gamePoint = PointData.Measurement("lighthouse")
|
||||
.Tag("game", gameVersion.ToString())
|
||||
.Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(database, gameVersion));
|
||||
|
||||
writeApi.WritePoint(gamePoint, ServerConfiguration.Instance.InfluxDB.Bucket, ServerConfiguration.Instance.InfluxDB.Organization);
|
||||
}
|
||||
|
||||
writeApi.WritePoint(point, ServerConfiguration.Instance.InfluxDB.Bucket, ServerConfiguration.Instance.InfluxDB.Organization);
|
||||
|
||||
writeApi.Flush();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.Error("Exception while logging: ", LogArea.InfluxDB);
|
||||
Logger.Error(e.ToDetailedException(), LogArea.InfluxDB);
|
||||
}
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "FunctionNeverReturns")]
|
||||
public static async Task StartLogging()
|
||||
{
|
||||
await Client.ReadyAsync();
|
||||
Logger.Success("InfluxDB is now ready.", LogArea.InfluxDB);
|
||||
Thread t = new
|
||||
(
|
||||
delegate()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
Log();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.Error("Exception while running log thread: ", LogArea.InfluxDB);
|
||||
Logger.Error(e.ToDetailedException(), LogArea.InfluxDB);
|
||||
}
|
||||
|
||||
Thread.Sleep(60000);
|
||||
}
|
||||
}
|
||||
);
|
||||
t.IsBackground = true;
|
||||
t.Name = "InfluxDB Logger";
|
||||
t.Start();
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@ public enum LogArea
|
|||
Database,
|
||||
Filter,
|
||||
HTTP,
|
||||
InfluxDB,
|
||||
Match,
|
||||
Photos,
|
||||
Resources,
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
using InfluxDB.Client;
|
||||
using InfluxDB.Client.Writes;
|
||||
using LBPUnion.ProjectLighthouse.Configuration;
|
||||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Logging.Loggers;
|
||||
|
||||
public class InfluxLogger : ILogger
|
||||
{
|
||||
public void Log(LogLine line)
|
||||
{
|
||||
string channel = string.IsNullOrEmpty(line.Area) ? "" : $"[{line.Area}] ";
|
||||
|
||||
string level = $"{$"{channel} {line}".TrimEnd()}";
|
||||
string content = line.Message;
|
||||
|
||||
using WriteApi writeApi = InfluxHelper.Client.GetWriteApi();
|
||||
|
||||
PointData point = PointData.Measurement("lighthouseLog").Field("level", level).Field("content", content);
|
||||
|
||||
writeApi.WritePoint(point, ServerConfiguration.Instance.InfluxDB.Bucket, ServerConfiguration.Instance.InfluxDB.Organization);
|
||||
}
|
||||
}
|
|
@ -13,7 +13,6 @@
|
|||
<PackageReference Include="Pfim" Version="0.11.2" />
|
||||
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.9.0" />
|
||||
<PackageReference Include="InfluxDB.Client" Version="4.10.0" />
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="7.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
|
||||
|
@ -27,7 +26,7 @@
|
|||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
<PackageReference Include="YamlDotNet" Version="13.0.0" />
|
||||
<PackageReference Include="BouncyCastle.Cryptography" Version="2.0.0" />
|
||||
<PackageReference Include="DistributedLock.MySql" Version="1.0.1"/>
|
||||
<PackageReference Include="DistributedLock.MySql" Version="1.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -63,13 +63,6 @@ public static class StartupTasks
|
|||
|
||||
migrateDatabase(database).Wait();
|
||||
|
||||
if (ServerConfiguration.Instance.InfluxDB.InfluxEnabled)
|
||||
{
|
||||
Logger.Info("Influx logging is enabled. Starting influx logging...", LogArea.Startup);
|
||||
InfluxHelper.StartLogging().Wait();
|
||||
if (ServerConfiguration.Instance.InfluxDB.LoggingEnabled) Logger.Instance.AddLogger(new InfluxLogger());
|
||||
}
|
||||
|
||||
Logger.Debug
|
||||
(
|
||||
"This is a debug build, so performance may suffer! " +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue