mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-09-26 19:29:07 +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()
|
public static async void Log()
|
||||||
{
|
{
|
||||||
WriteApi writeApi = Client.GetWriteApi();
|
using WriteApi writeApi = Client.GetWriteApi();
|
||||||
PointData point = PointData.Measurement("lighthouse").Field("playerCount", await StatisticsHelper.RecentMatches());
|
PointData point = PointData.Measurement("lighthouse")
|
||||||
|
.Field("playerCount", await StatisticsHelper.RecentMatches())
|
||||||
|
.Field("slotCount", await StatisticsHelper.SlotCount());
|
||||||
|
|
||||||
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
||||||
|
|
||||||
|
@ -26,17 +28,17 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
||||||
{
|
{
|
||||||
await Client.ReadyAsync();
|
await Client.ReadyAsync();
|
||||||
Logger.Log("InfluxDB is now ready.", LoggerLevelInflux.Instance);
|
Logger.Log("InfluxDB is now ready.", LoggerLevelInflux.Instance);
|
||||||
Thread t = new Thread
|
Thread t = new
|
||||||
(
|
(
|
||||||
delegate()
|
delegate()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Thread.Sleep(5000);
|
|
||||||
#pragma warning disable CS4014
|
#pragma warning disable CS4014
|
||||||
Log();
|
Log();
|
||||||
#pragma warning restore CS4014
|
#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)
|
if (ServerSettings.Instance.InfluxEnabled)
|
||||||
{
|
{
|
||||||
Logger.Log("Influx logging is enabled. Starting influx logging...", LoggerLevelStartup.Instance);
|
Logger.Log("Influx logging is enabled. Starting influx logging...", LoggerLevelStartup.Instance);
|
||||||
|
#pragma warning disable CS4014
|
||||||
InfluxHelper.StartLogging();
|
InfluxHelper.StartLogging();
|
||||||
|
#pragma warning restore CS4014
|
||||||
|
if (ServerSettings.Instance.InfluxLoggingEnabled) Logger.AddLogger(new InfluxLogger());
|
||||||
}
|
}
|
||||||
|
|
||||||
stopwatch.Stop();
|
stopwatch.Stop();
|
||||||
|
|
|
@ -68,7 +68,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public static ServerSettings Instance;
|
public static ServerSettings Instance;
|
||||||
|
|
||||||
public const int CurrentConfigVersion = 3;
|
public const int CurrentConfigVersion = 4;
|
||||||
|
|
||||||
[JsonPropertyName("ConfigVersionDoNotModifyOrYouWillBeSlapped")]
|
[JsonPropertyName("ConfigVersionDoNotModifyOrYouWillBeSlapped")]
|
||||||
public int ConfigVersion { get; set; } = CurrentConfigVersion;
|
public int ConfigVersion { get; set; } = CurrentConfigVersion;
|
||||||
|
@ -77,7 +77,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Settings
|
||||||
|
|
||||||
#endregion Meta
|
#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 InfluxOrg { get; set; } = "lighthouse";
|
||||||
public string InfluxBucket { get; set; } = "lighthouse";
|
public string InfluxBucket { get; set; } = "lighthouse";
|
||||||
public string InfluxToken { get; set; } = "";
|
public string InfluxToken { get; set; } = "";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue