mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-25 10:49:01 +00:00
Add InfluxLogger for Kettu, log slot counts
This commit is contained in:
parent
3c42c0cf55
commit
8703a39100
4 changed files with 40 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
|
27
ProjectLighthouse/Logging/InfluxLogger.cs
Normal file
27
ProjectLighthouse/Logging/InfluxLogger.cs
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
|
@ -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; } = "";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue