mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-02 10:08:39 +00:00
Log recent matches for individual games to influx (#230)
This commit is contained in:
parent
dee575f711
commit
d03179997a
2 changed files with 37 additions and 4 deletions
|
@ -1,9 +1,12 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using InfluxDB.Client;
|
using InfluxDB.Client;
|
||||||
using InfluxDB.Client.Writes;
|
using InfluxDB.Client.Writes;
|
||||||
using Kettu;
|
using Kettu;
|
||||||
using LBPUnion.ProjectLighthouse.Logging;
|
using LBPUnion.ProjectLighthouse.Logging;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
@ -12,6 +15,15 @@ public static class InfluxHelper
|
||||||
{
|
{
|
||||||
public static readonly InfluxDBClient Client = InfluxDBClientFactory.Create(ServerSettings.Instance.InfluxUrl, ServerSettings.Instance.InfluxToken);
|
public static readonly InfluxDBClient Client = InfluxDBClientFactory.Create(ServerSettings.Instance.InfluxUrl, ServerSettings.Instance.InfluxToken);
|
||||||
|
|
||||||
|
private static readonly List<GameVersion> gameVersions = new()
|
||||||
|
{
|
||||||
|
GameVersion.LittleBigPlanet1,
|
||||||
|
GameVersion.LittleBigPlanet2,
|
||||||
|
GameVersion.LittleBigPlanet3,
|
||||||
|
GameVersion.LittleBigPlanetVita,
|
||||||
|
GameVersion.LittleBigPlanetPSP,
|
||||||
|
};
|
||||||
|
|
||||||
public static async void Log()
|
public static async void Log()
|
||||||
{
|
{
|
||||||
using WriteApi writeApi = Client.GetWriteApi();
|
using WriteApi writeApi = Client.GetWriteApi();
|
||||||
|
@ -19,6 +31,15 @@ public static class InfluxHelper
|
||||||
.Field("playerCount", await StatisticsHelper.RecentMatches())
|
.Field("playerCount", await StatisticsHelper.RecentMatches())
|
||||||
.Field("slotCount", await StatisticsHelper.SlotCount());
|
.Field("slotCount", await StatisticsHelper.SlotCount());
|
||||||
|
|
||||||
|
foreach (GameVersion gameVersion in gameVersions)
|
||||||
|
{
|
||||||
|
PointData gamePoint = PointData.Measurement("lighthouse")
|
||||||
|
.Tag("game", gameVersion.ToString())
|
||||||
|
.Field("playerCountGame", await StatisticsHelper.RecentMatchesForGame(gameVersion));
|
||||||
|
|
||||||
|
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, gamePoint);
|
||||||
|
}
|
||||||
|
|
||||||
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
writeApi.WritePoint(ServerSettings.Instance.InfluxBucket, ServerSettings.Instance.InfluxOrg, point);
|
||||||
|
|
||||||
writeApi.Flush();
|
writeApi.Flush();
|
||||||
|
@ -34,10 +55,17 @@ public static class InfluxHelper
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
#pragma warning disable CS4014
|
try
|
||||||
Log();
|
{
|
||||||
#pragma warning restore CS4014
|
Log();
|
||||||
// Logger.Log("Logged.", LoggerLevelInflux.Instance);
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Logger.Log("Exception while logging: ", LoggerLevelInflux.Instance);
|
||||||
|
|
||||||
|
foreach (string line in e.ToString().Split("\n")) Logger.Log(line, LoggerLevelInflux.Instance);
|
||||||
|
}
|
||||||
|
|
||||||
Thread.Sleep(60000);
|
Thread.Sleep(60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using LBPUnion.ProjectLighthouse.Types;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Helpers;
|
namespace LBPUnion.ProjectLighthouse.Helpers;
|
||||||
|
@ -10,6 +11,10 @@ public static class StatisticsHelper
|
||||||
|
|
||||||
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync();
|
public static async Task<int> RecentMatches() => await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300).CountAsync();
|
||||||
|
|
||||||
|
public static async Task<int> RecentMatchesForGame
|
||||||
|
(GameVersion gameVersion)
|
||||||
|
=> await database.LastContacts.Where(l => TimestampHelper.Timestamp - l.Timestamp < 300 && l.GameVersion == gameVersion).CountAsync();
|
||||||
|
|
||||||
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
public static async Task<int> SlotCount() => await database.Slots.CountAsync();
|
||||||
|
|
||||||
public static async Task<int> UserCount() => await database.Users.CountAsync(u => !u.Banned);
|
public static async Task<int> UserCount() => await database.Users.CountAsync(u => !u.Banned);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue