Add InfluxLogger for Kettu, log slot counts

This commit is contained in:
jvyden 2021-11-19 02:21:49 -05:00
commit 8703a39100
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 40 additions and 7 deletions

View file

@ -14,8 +14,10 @@ namespace LBPUnion.ProjectLighthouse.Helpers
public static async void Log()
{
WriteApi writeApi = Client.GetWriteApi();
PointData point = PointData.Measurement("lighthouse").Field("playerCount", await StatisticsHelper.RecentMatches());
using WriteApi writeApi = Client.GetWriteApi();
PointData point = PointData.Measurement("lighthouse")
.Field("playerCount", await StatisticsHelper.RecentMatches())
.Field("slotCount", await StatisticsHelper.SlotCount());
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
@ -26,17 +28,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers
{
await Client.ReadyAsync();
Logger.Log("InfluxDB is now ready.", LoggerLevelInflux.Instance);
Thread t = new Thread
Thread t = new
(
delegate()
{
while (true)
{
Thread.Sleep(5000);
#pragma warning disable CS4014
Log();
#pragma warning restore CS4014
Logger.Log("Logged.", LoggerLevelInflux.Instance);
// Logger.Log("Logged.", LoggerLevelInflux.Instance);
Thread.Sleep(60000);
}
}
);

View file

@ -0,0 +1,27 @@
using InfluxDB.Client;
using InfluxDB.Client.Writes;
using Kettu;
using LBPUnion.ProjectLighthouse.Helpers;
using LBPUnion.ProjectLighthouse.Types.Settings;
namespace LBPUnion.ProjectLighthouse.Logging
{
public class InfluxLogger : LoggerBase
{
public override void Send(LoggerLine line)
{
string channel = string.IsNullOrEmpty(line.LoggerLevel.Channel) ? "" : $"[{line.LoggerLevel.Channel}] ";
string level = $"{$"{line.LoggerLevel.Name} {channel}".TrimEnd()}";
string content = line.LineData;
using WriteApi writeApi = InfluxHelper.Client.GetWriteApi();
PointData point = PointData.Measurement("lighthouseLog").Field("level", level).Field("content", content);
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
}
public override bool AllowMultiple => false;
}
}

View file

@ -47,7 +47,10 @@ namespace LBPUnion.ProjectLighthouse
if (ServerSettings.Instance.InfluxEnabled)
{
Logger.Log("Influx logging is enabled. Starting influx logging...", LoggerLevelStartup.Instance);
#pragma warning disable CS4014
InfluxHelper.StartLogging();
#pragma warning restore CS4014
if (ServerSettings.Instance.InfluxLoggingEnabled) Logger.AddLogger(new InfluxLogger());
}
stopwatch.Stop();

View file

@ -68,7 +68,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
[NotNull]
public static ServerSettings Instance;
public const int CurrentConfigVersion = 3;
public const int CurrentConfigVersion = 4;
[JsonPropertyName("ConfigVersionDoNotModifyOrYouWillBeSlapped")]
public int ConfigVersion { get; set; } = CurrentConfigVersion;
@ -77,7 +77,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
#endregion Meta
public bool InfluxEnabled { get; set; } = false;
public bool InfluxEnabled { get; set; }
public bool InfluxLoggingEnabled { get; set; }
public string InfluxOrg { get; set; } = "lighthouse";
public string InfluxBucket { get; set; } = "lighthouse";
public string InfluxToken { get; set; } = "";